diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/validators | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/gitlab/emoji_name_validator.rb | 19 | ||||
-rw-r--r-- | app/validators/key_restriction_validator.rb | 15 |
2 files changed, 28 insertions, 6 deletions
diff --git a/app/validators/gitlab/emoji_name_validator.rb b/app/validators/gitlab/emoji_name_validator.rb index a9092d0194f..c034a79214b 100644 --- a/app/validators/gitlab/emoji_name_validator.rb +++ b/app/validators/gitlab/emoji_name_validator.rb @@ -11,9 +11,22 @@ module Gitlab class EmojiNameValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless TanukiEmoji.find_by_alpha_code(value.to_s) - record.errors.add(attribute, (options[:message] || 'is not a valid emoji name')) - end + return if valid_tanuki_emoji?(value) + return if valid_custom_emoji?(record, value) + + record.errors.add(attribute, (options[:message] || 'is not a valid emoji name')) + end + + private + + def valid_tanuki_emoji?(value) + TanukiEmoji.find_by_alpha_code(value.to_s) + end + + def valid_custom_emoji?(record, value) + resource = record.try(:resource_parent) + + CustomEmoji.for_resource(resource).by_name(value.to_s).any? end end end 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 |