rosa-build/spec/models/key_pair_spec.rb

65 lines
2.2 KiB
Ruby
Raw Permalink Normal View History

2012-07-13 12:18:12 +01:00
require 'spec_helper'
describe KeyPair do
it { should belong_to(:repository) }
it { should belong_to(:user)}
2015-05-26 00:03:38 +01:00
it { should validate_length_of(:public).is_at_most(10000) }
it { should validate_length_of(:secret).is_at_most(10000) }
2012-12-20 16:21:43 +00:00
describe 'check_keys validation' do
subject { FactoryGirl.build(:key_pair) }
2015-05-26 00:03:38 +01:00
it { expect(subject).to be_valid }
2012-12-20 16:21:43 +00:00
it 'checks error when wrong public key' do
subject.public = 'test'
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:public]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key')
2012-12-20 16:21:43 +00:00
end
it 'checks error when wrong secret key' do
subject.secret = 'test'
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_key')
2012-12-20 16:21:43 +00:00
end
it 'checks error when public key contains secret key' do
subject.public = subject.secret
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:public]).to contain_exactly 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
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:secret]).to contain_exactly 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
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.wrong_keys')
2012-12-20 16:21:43 +00:00
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
2015-05-26 00:03:38 +01:00
expect(subject).to_not be_valid
expect(subject.errors[:secret]).to contain_exactly I18n.t('activerecord.errors.key_pair.key_has_passphrase')
2012-12-20 16:21:43 +00:00
end
end
after(:all) do
FileUtils.rm_rf(APP_CONFIG['root_path'])
end
2012-07-13 12:18:12 +01:00
end