spec/passrock/password_db_spec.rb in passrock-0.0.4 vs spec/passrock/password_db_spec.rb in passrock-0.0.5
- old
+ new
@@ -1,10 +1,12 @@
require 'spec_helper'
describe Passrock::PasswordDb do
+
let(:password_db) { passrock_password_db }
let(:private_key) { passrock_private_key }
+ let(:valid_init_opts) { {:password_db => password_db, :private_key => private_key} }
let(:insecure_password) { 'password' }
let(:secure_password) { 'BoatActKnowsDog' }
describe '.bcrypt_hash' do
@@ -16,57 +18,72 @@
end
end
+ describe '#initialize' do
+
+ context 'when password_db file does not exist' do
+ it 'raises PasswordDbNotFoundError' do
+ expect {
+ described_class.new(:password_db => '/invalid/path/to/password_db', :private_key => private_key)
+ }.to raise_error(Passrock::PasswordDbNotFoundError)
+ end
+ end
+
+ end
+
describe '#password_in_searchable_form' do
it 'returns the given password in a searchable format' do
- passrock = described_class.new(password_db, private_key)
- expect(passrock.password_in_searchable_form(insecure_password)).to eq('+lR0p4OzjXJnta/4GGtqdaBQEFPQdjI=')
+ subject = described_class.new(valid_init_opts)
+ expect(subject.password_in_searchable_form(insecure_password)).to eq('+lR0p4OzjXJnta/4GGtqdaBQEFPQdjI=')
end
end
describe '#secure?' do
- let(:passrock) { described_class.new(password_db, private_key) }
+ let(:subject) { described_class.new(valid_init_opts) }
+
context 'when given password is present in the password database' do
it 'returns false' do
- expect(passrock.secure?(insecure_password)).to be_false
+ expect(subject.secure?(insecure_password)).to be_false
end
end
context 'when given password does not appear in the password database' do
it 'returns true' do
- expect(passrock.secure?(secure_password)).to be_true
+ expect(subject.secure?(secure_password)).to be_true
end
end
context 'multiple sequential calls' do
it 'does not error out' do
expect {
- passrock.secure?(secure_password)
- passrock.secure?(insecure_password)
+ subject.secure?(secure_password)
+ subject.secure?(insecure_password)
}.to_not raise_error
end
end
end
describe '#insecure?' do
- let(:passrock) { described_class.new(password_db, private_key) }
+ let(:subject) { described_class.new(valid_init_opts) }
+
context 'when given password is present in the password database' do
it 'returns true' do
- expect(passrock.insecure?(insecure_password)).to be_true
+ expect(subject.insecure?(insecure_password)).to be_true
end
end
context 'when given password does not appear in the password database' do
it 'returns false' do
- expect(passrock.insecure?(secure_password)).to be_false
+ expect(subject.insecure?(secure_password)).to be_false
end
end
+
end
end