Sha256: 1d5bf89abff5f3ddbafa09fce69cb8cc73f156ff38394ce43530d59e50fe3dab

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe Clearance::PasswordStrategies::Blowfish do
  subject do
    fake_model_with_password_strategy(Clearance::PasswordStrategies::Blowfish)
  end

  describe '#password=' do
    context 'when the password is set' do
      let(:salt) { 'salt' }
      let(:password) { 'password' }

      before do
        subject.salt = salt
        subject.password = password
      end

      it 'does not initialize the salt' do
        expect(subject.salt).to eq salt
      end

      it 'encrypts the password using Blowfish and the existing salt' do
        cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt
        cipher.key = Digest::SHA256.digest(salt)
        expected = cipher.update("--#{salt}--#{password}--") << cipher.final
        encrypted_password = Base64.decode64(subject.encrypted_password)
        expect(encrypted_password).to eq expected
      end
    end

    context 'when the salt is not set' do
      before do
        subject.salt = nil
        subject.password = 'whatever'
      end

      it 'should initialize the salt' do
        expect(subject.salt).not_to be_nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clearance-1.7.0 spec/models/blowfish_spec.rb
clearance-1.6.1 spec/models/blowfish_spec.rb
clearance-1.6.0 spec/models/blowfish_spec.rb
clearance-1.5.1 spec/models/blowfish_spec.rb