diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-28 18:07:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-28 18:07:51 +0300 |
commit | b213b675ec1d6fa633497c5f71c195f00b56be6d (patch) | |
tree | 40b871f2124307dfe2326f1d116d3fd7b4e2f86d /app/validators | |
parent | e4dad5d33053f0facde637888363a8954d0d5e46 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/key_restriction_validator.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/app/validators/key_restriction_validator.rb b/app/validators/key_restriction_validator.rb index 9809047ae83..0094d6156a3 100644 --- a/app/validators/key_restriction_validator.rb +++ b/app/validators/key_restriction_validator.rb @@ -2,25 +2,34 @@ class KeyRestrictionValidator < ActiveModel::EachValidator FORBIDDEN = -1 + ALLOWED = 0 def self.supported_sizes(type) Gitlab::SSHPublicKey.supported_sizes(type) end def self.supported_key_restrictions(type) - [0, *supported_sizes(type), FORBIDDEN] + if Gitlab::FIPS.enabled? + [*supported_sizes(type), FORBIDDEN] + else + [ALLOWED, *supported_sizes(type), FORBIDDEN] + end end def validate_each(record, attribute, value) unless valid_restriction?(value) - record.errors.add(attribute, "must be forbidden, allowed, or one of these sizes: #{supported_sizes_message}") + record.errors.add(attribute, "must be #{supported_sizes_message}") end end private def supported_sizes_message - sizes = self.class.supported_sizes(options[:type]) + sizes = [] + + sizes << "forbidden" if valid_restriction?(FORBIDDEN) + sizes << "allowed" if valid_restriction?(ALLOWED) + sizes += self.class.supported_sizes(options[:type]) Gitlab::Utils.to_exclusive_sentence(sizes) end |