Commit d7e34ceb authored by Bogdan Denkovych's avatar Bogdan Denkovych

DRY supported ssh key types

Add `Gitlab::SSHPublicKey.supported_types` method.
This method returns the names of ssh keys GitLab supports.
`Gitlab::SSHPublicKey` should be the source of truth about such
information.
`SUPPORTED_KEY_TYPES` has the same information so I reused the method
to prevent duplication that would allow easier to extend the list of
supported keys.
See https://gitlab.com/gitlab-org/gitlab/-/issues/213259.
parent ccf33f48
......@@ -14,7 +14,7 @@ module ApplicationSettingImplementation
# Setting a key restriction to `-1` means that all keys of this type are
# 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
DEFAULT_PROTECTED_PATHS = [
......
......@@ -19,6 +19,10 @@ module Gitlab
TECHNOLOGIES.find { |tech| key.is_a?(tech.key_class) }
end
def self.supported_types
TECHNOLOGIES.map(&:name)
end
def self.supported_sizes(name)
technology(name)&.supported_sizes
end
......
......@@ -21,6 +21,14 @@ RSpec.describe Gitlab::SSHPublicKey, lib: true do
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
where(:name, :sizes) do
[
......
......@@ -491,7 +491,7 @@ RSpec.describe ApplicationSetting do
context 'key restrictions' 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
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