Sha256: 9c6dac668aff8629edaefc1d1c462a316cbcea9a246ef43b4dd614bb894554f2

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 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
        subject.salt.should == 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
        subject.encrypted_password.should == 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
        subject.salt.should_not be_nil
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
clearance-1.4.3 spec/models/blowfish_spec.rb
clearance-1.4.2 spec/models/blowfish_spec.rb
clearance-1.4.1 spec/models/blowfish_spec.rb
clearance-1.4.0 spec/models/blowfish_spec.rb
clearance-1.3.0 spec/models/blowfish_spec.rb
clearance-1.2.1 spec/models/blowfish_spec.rb
clearance-1.2.0 spec/models/blowfish_spec.rb
clearance-1.1.0 spec/models/blowfish_spec.rb
clearance-1.0.1 spec/models/blowfish_spec.rb
clearance-1.0.0 spec/models/blowfish_spec.rb
clearance-1.0.0.rc8 spec/models/blowfish_spec.rb
clearance-1.0.0.rc7 spec/models/blowfish_spec.rb
clearance-1.0.0.rc6 spec/models/blowfish_spec.rb