summaryrefslogtreecommitdiff
path: root/spec/helpers/ssh_keys_helper_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/ssh_keys_helper_spec.rb')
-rw-r--r--spec/helpers/ssh_keys_helper_spec.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/helpers/ssh_keys_helper_spec.rb b/spec/helpers/ssh_keys_helper_spec.rb
new file mode 100644
index 00000000000..1aa604f19be
--- /dev/null
+++ b/spec/helpers/ssh_keys_helper_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe SshKeysHelper do
+ describe '#ssh_key_allowed_algorithms' do
+ it 'returns string with the names of allowed algorithms that are quoted and joined by commas' do
+ allowed_algorithms = Gitlab::CurrentSettings.allowed_key_types.flat_map do |ssh_key_type_name|
+ Gitlab::SSHPublicKey.supported_algorithms_for_name(ssh_key_type_name)
+ end
+
+ quoted_allowed_algorithms = allowed_algorithms.map { |name| "'#{name}'" }
+
+ expected_string = Gitlab::Utils.to_exclusive_sentence(quoted_allowed_algorithms)
+
+ expect(ssh_key_allowed_algorithms).to eq(expected_string)
+ end
+
+ it 'returns only allowed algorithms' do
+ expect(ssh_key_allowed_algorithms).to match('ed25519')
+ stub_application_setting(ed25519_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE)
+ expect(ssh_key_allowed_algorithms).not_to match('ed25519')
+ end
+ end
+end