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
# 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