diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2017-09-04 10:28:46 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2017-09-04 10:28:46 +0300 |
commit | a315e6025c702985b2f6390b29508de39383f52d (patch) | |
tree | f0d07d955092e4a218346c41f2942131dfcef91a /spec/models/application_setting_spec.rb | |
parent | 78dad4cf321eb84aa5decdea34704145adca0c3e (diff) | |
parent | fd54a4678f23c9e18ce46b3803e5e57ffa1199a3 (diff) |
Merge branch 'master' into zj-auto-devops-table
Diffstat (limited to 'spec/models/application_setting_spec.rb')
-rw-r--r-- | spec/models/application_setting_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 95ebd016064..c7a9eabdf06 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -73,6 +73,33 @@ describe ApplicationSetting do .is_greater_than(0) end + context 'key restrictions' do + it 'supports all key types' do + expect(described_class::SUPPORTED_KEY_TYPES).to contain_exactly(:rsa, :dsa, :ecdsa, :ed25519) + end + + it 'does not allow all key types to be disabled' do + described_class::SUPPORTED_KEY_TYPES.each do |type| + setting["#{type}_key_restriction"] = described_class::FORBIDDEN_KEY_VALUE + end + + expect(setting).not_to be_valid + expect(setting.errors.messages).to have_key(:allowed_key_types) + end + + where(:type) do + described_class::SUPPORTED_KEY_TYPES + end + + with_them do + let(:field) { :"#{type}_key_restriction" } + + it { is_expected.to validate_presence_of(field) } + it { is_expected.to allow_value(*KeyRestrictionValidator.supported_key_restrictions(type)).for(field) } + it { is_expected.not_to allow_value(128).for(field) } + end + end + it_behaves_like 'an object with email-formated attributes', :admin_notification_email do subject { setting } end @@ -442,4 +469,36 @@ describe ApplicationSetting do end end end + + describe '#allowed_key_types' do + it 'includes all key types by default' do + expect(setting.allowed_key_types).to contain_exactly(*described_class::SUPPORTED_KEY_TYPES) + end + + it 'excludes disabled key types' do + expect(setting.allowed_key_types).to include(:ed25519) + + setting.ed25519_key_restriction = described_class::FORBIDDEN_KEY_VALUE + + expect(setting.allowed_key_types).not_to include(:ed25519) + end + end + + describe '#key_restriction_for' do + it 'returns the restriction value for recognised types' do + setting.rsa_key_restriction = 1024 + + expect(setting.key_restriction_for(:rsa)).to eq(1024) + end + + it 'allows types to be passed as a string' do + setting.rsa_key_restriction = 1024 + + expect(setting.key_restriction_for('rsa')).to eq(1024) + end + + it 'returns forbidden for unrecognised type' do + expect(setting.key_restriction_for(:foo)).to eq(described_class::FORBIDDEN_KEY_VALUE) + end + end end |