2012-07-13 12:18:12 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe KeyPair do
|
2012-07-17 10:31:32 +01:00
|
|
|
before(:all) do
|
2013-01-18 12:57:45 +00:00
|
|
|
init_test_root
|
2012-12-24 10:53:20 +00:00
|
|
|
stub_redis
|
2012-07-17 10:31:32 +01:00
|
|
|
FactoryGirl.create(:key_pair)
|
|
|
|
end
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
2012-07-17 10:31:32 +01:00
|
|
|
|
|
|
|
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) }
|
|
|
|
|
|
|
|
it { subject.valid?.should be_true }
|
|
|
|
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?
|
2012-12-24 13:58:46 +00:00
|
|
|
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?
|
2012-12-24 13:58:46 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2012-07-17 10:31:32 +01:00
|
|
|
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
|