Commit 1897c391 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'refactor-ssh-public-key-implementation' into 'master'

DRY supported ssh key types

See merge request gitlab-org/gitlab!77374
parents 946e0078 d7e34ceb
...@@ -14,7 +14,7 @@ module ApplicationSettingImplementation ...@@ -14,7 +14,7 @@ module ApplicationSettingImplementation
# Setting a key restriction to `-1` means that all keys of this type are # Setting a key restriction to `-1` means that all keys of this type are
# forbidden. # forbidden.
FORBIDDEN_KEY_VALUE = KeyRestrictionValidator::FORBIDDEN FORBIDDEN_KEY_VALUE = KeyRestrictionValidator::FORBIDDEN
SUPPORTED_KEY_TYPES = %i[rsa dsa ecdsa ed25519].freeze SUPPORTED_KEY_TYPES = Gitlab::SSHPublicKey.supported_types
VALID_RUNNER_REGISTRAR_TYPES = %w(project group).freeze VALID_RUNNER_REGISTRAR_TYPES = %w(project group).freeze
DEFAULT_PROTECTED_PATHS = [ DEFAULT_PROTECTED_PATHS = [
......
...@@ -19,6 +19,10 @@ module Gitlab ...@@ -19,6 +19,10 @@ module Gitlab
TECHNOLOGIES.find { |tech| key.is_a?(tech.key_class) } TECHNOLOGIES.find { |tech| key.is_a?(tech.key_class) }
end end
def self.supported_types
TECHNOLOGIES.map(&:name)
end
def self.supported_sizes(name) def self.supported_sizes(name)
technology(name)&.supported_sizes technology(name)&.supported_sizes
end end
......
...@@ -21,6 +21,14 @@ RSpec.describe Gitlab::SSHPublicKey, lib: true do ...@@ -21,6 +21,14 @@ RSpec.describe Gitlab::SSHPublicKey, lib: true do
end end
end end
describe '.supported_types' do
it 'returns array with the names of supported technologies' do
expect(described_class.supported_types).to eq(
[:rsa, :dsa, :ecdsa, :ed25519]
)
end
end
describe '.supported_sizes(name)' do describe '.supported_sizes(name)' do
where(:name, :sizes) do where(:name, :sizes) do
[ [
......
...@@ -491,7 +491,7 @@ RSpec.describe ApplicationSetting do ...@@ -491,7 +491,7 @@ RSpec.describe ApplicationSetting do
context 'key restrictions' do context 'key restrictions' do
it 'supports all key types' do it 'supports all key types' do
expect(described_class::SUPPORTED_KEY_TYPES).to contain_exactly(:rsa, :dsa, :ecdsa, :ed25519) expect(described_class::SUPPORTED_KEY_TYPES).to eq(Gitlab::SSHPublicKey.supported_types)
end end
it 'does not allow all key types to be disabled' do it 'does not allow all key types to be disabled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment