rosa-build/spec/models/key_pair_spec.rb

73 lines
2.3 KiB
Ruby
Raw Normal View History

2012-07-13 12:18:12 +01:00
require 'spec_helper'
describe KeyPair do
2014-03-18 13:54:16 +00:00
before(:all) { FactoryGirl.create(:key_pair) }
it { should belong_to(:repository) }
it { should belong_to(:user)}
2012-12-20 17:36:32 +00:00
it { should ensure_length_of(:public).is_at_most(10000) }
it { should ensure_length_of(:secret).is_at_most(10000) }
it { should_not allow_mass_assignment_of(:user) }
it { should_not allow_mass_assignment_of(:key_id) }
2012-12-20 16:21:43 +00:00
describe 'check_keys validation' do
subject { FactoryGirl.build(:key_pair) }
2015-02-19 01:12:08 +00:00
it { subject.valid?.should be_truthy }
2012-12-20 16:21:43 +00:00
it 'checks error when wrong public key' do
subject.public = 'test'
subject.valid?
subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')]
end
it 'checks error when wrong secret key' do
subject.secret = 'test'
subject.valid?
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_key')]
end
it 'checks error when public key contains secret key' do
subject.public = subject.secret
subject.valid?
subject.errors[:public].should =~ [I18n.t('activerecord.errors.key_pair.wrong_public_key')]
2012-12-20 16:21:43 +00:00
end
it 'checks error when secret key contains public key' do
subject.secret = subject.public
subject.valid?
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_secret_key')]
2012-12-20 16:21:43 +00:00
end
it 'checks error when different fingerprint of keys' do
file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'pubring.pass.gpg'), "rb")
subject.public = file.read
file.close
subject.valid?
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.wrong_keys')]
end
it 'checks error when secret key contains passphrase' do
file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'pubring.pass.gpg'), "rb")
subject.public = file.read
file.close
file = File.open(Rails.root.join('spec', 'support', 'fixtures', 'secring.pass.gpg'), "rb")
subject.secret = file.read
file.close
subject.valid?
subject.errors[:secret].should =~ [I18n.t('activerecord.errors.key_pair.key_has_passphrase')]
end
end
after(:all) do
Platform.delete_all
User.delete_all
Product.delete_all
FileUtils.rm_rf(APP_CONFIG['root_path'])
end
2012-07-13 12:18:12 +01:00
end