Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/gitlab/emoji_name_validator.rb19
-rw-r--r--app/validators/key_restriction_validator.rb15
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