<commit_before>require 'spec_helper'

module AccountManager
  describe Crypto do
    describe '.new_salt' do
      it 'returns a 20 character hex string' do
        Crypto.new_salt.should match /[a-f0-9]{20}/
      end
    end

    describe '.hash_password' do
      it 'creates a SSHA password hash' do
        Crypto.hash_password('<PASSWORD>', type: :ssha).should match /^{SSHA}/
      end

      it 'creates a SHA password hash' do
        Crypto.hash_password('<PASSWORD>', type: :sha).should match /^{SHA}/
      end

      it 'should complain if you pass it an unsupported hash type' do
        expect {
          Crypto.hash_password('<PASSWORD>', type: :md5)
        }.should raise_error "Unsupported password hash type md5"
      end
    end

    describe '.check_ssha_password' do

      before :all do
        @hash = Crypto.hash_password '<PASSWORD>', type: :ssha
      end

      it 'validates a correct password against an SSHA hash' do
        Crypto.check_ssha_password('<PASSWORD>', @hash).should be true
      end

      it 'does not validate an incorrect password against an SSHA hash' do
        Crypto.check_ssha_password('<PASSWORD>', @hash).should be false
      end
    end

    describe '.check_sha_password' do


      before :all do
        @hash = Crypto.hash_password '<PASSWORD>', type: :sha
      end

      it 'validates a correct password against an SHA hash' do
        Crypto.check_sha_password('<PASSWORD>', @hash).should be true
      end

      it 'does not validate an incorrect password against an SHA hash' do
        Crypto.check_sha_password('<PASSWORD>', @hash).should be false
      end
    end

    describe '.check_password' do
      it 'identifies and validates SSHA passwords' do
        hash = Crypto.hash_password '<PASSWORD>', type: :ssha
        Crypto.check_password '<PASSWORD>', hash
      end

      it 'identifies and validates SHA passwords' do
        hash = Crypto.hash_password '<PASSWORD>', type: :sha
        Crypto.check_password '<PASSWORD>', hash
      end

      it 'complains if you try to use an unsupported password hash type' do
        expect {
          Crypto.check_password '<PASSWORD>', '{MD5}<PASSWORD>'
        }.should raise_error 'Unsupported password hash type md5'
      end

      it "complains if you don't have a hash prefix string such as {SHA} in your hash" do
        expect {
          Crypto.check_password '<PASSWORD>', '<PASSWORD>'
        }.should raise_error 'No hash prefix. Expected something like {SHA} at the beginning of the hash.'
      end
    end

  end
end<commit_msg>add test for compatibility with larger salts<commit_after>require 'spec_helper'

module AccountManager
  describe Crypto do
    describe '.new_salt' do
      it 'returns a 20 character hex string' do
        Crypto.new_salt.should match /[a-f0-9]{20}/
      end
    end

    describe '.hash_password' do
      it 'creates a SSHA password hash' do
        Crypto.hash_password('<PASSWORD>', type: :ssha).should match /^{SSHA}/
      end

      it 'creates a SHA password hash' do
        Crypto.hash_password('<PASSWORD>', type: :sha).should match /^{SHA}/
      end

      it 'should complain if you pass it an unsupported hash type' do
        expect {
          Crypto.hash_password('<PASSWORD>', type: :md5)
        }.should raise_error "Unsupported password hash type md5"
      end
    end

    describe '.check_ssha_password' do

      before :all do
        @hazh = Crypto.hash_password '<PASSWORD>', type: :ssha
      end

      it 'validates a correct password against an SSHA hash' do
        Crypto.check_ssha_password('<PASSWORD>', @hazh).should be true
      end

      it 'does not validate an incorrect password against an SSHA hash' do
        Crypto.check_ssha_password('<PASSWORD>', @hazh).should be false
      end

      it 'works with a really long salt' do
        salt = 10.times.inject('') {|out| out << Crypto.new_salt}
        hazh = Crypto.hash_password '<PASSWORD>', salt: salt
        Crypto.check_password('<PASSWORD>', hazh).should be true
      end
    end

    describe '.check_sha_password' do


      before :all do
        @hazh = Crypto.hash_password '<PASSWORD>', type: :sha
      end

      it 'validates a correct password against an SHA hash' do
        Crypto.check_sha_password('<PASSWORD>', @hazh).should be true
      end

      it 'does not validate an incorrect password against an SHA hash' do
        Crypto.check_sha_password('<PASSWORD>', @hazh).should be false
      end
    end

    describe '.check_password' do
      it 'identifies and validates SSHA passwords' do
        hazh = Crypto.hash_password '<PASSWORD>', type: :ssha
        Crypto.check_password '<PASSWORD>', hazh
      end

      it 'identifies and validates SHA passwords' do
        hazh = Crypto.hash_password '<PASSWORD>', type: :sha
        Crypto.check_password '<PASSWORD>', hazh
      end

      it 'complains if you try to use an unsupported password hash type' do
        expect {
          Crypto.check_password '<PASSWORD>', '{MD5}somehash'
        }.should raise_error 'Unsupported password hash type md5'
      end

      it "complains if you don't have a hash prefix string such as {SHA} in your hash" do
        expect {
          Crypto.check_password '<PASSWORD>', 'bad<PASSWORD>'
        }.should raise_error 'No hash prefix. Expected something like {SHA} at the beginning of the hash.'
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.0912442396313364, 'fraction_numerical': 0.004055299539170507, 'mean_word_length': 2.5510471204188483, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '110765', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1564, 'n_words': 562}