/
blowfish_spec.rb
41 lines (34 loc) · 1.04 KB
/
blowfish_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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