summaryrefslogtreecommitdiff
path: root/lib/api/helpers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 12:08:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-02 12:08:18 +0000
commit684d65316ac77c62f47d68b9926eea8af30db227 (patch)
treed1f4c4eec399d7772ab4ad6294f98e7505c1cee5 /lib/api/helpers
parentade18c9d68d5a2e6c6e28ef7e9d3add3b3491ace (diff)
downloadgitlab-ce-684d65316ac77c62f47d68b9926eea8af30db227.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/helpers')
-rw-r--r--lib/api/helpers/custom_validators.rb97
-rw-r--r--lib/api/helpers/merge_requests_helpers.rb1
2 files changed, 0 insertions, 98 deletions
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb
deleted file mode 100644
index 76f5fe555b4..00000000000
--- a/lib/api/helpers/custom_validators.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-# frozen_string_literal: true
-
-module API
- module Helpers
- module CustomValidators
- class FilePath < Grape::Validations::Base
- def validate_param!(attr_name, params)
- path = params[attr_name]
-
- Gitlab::Utils.check_path_traversal!(path)
- rescue StandardError
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
- message: "should be a valid file path"
- end
- end
-
- class GitSha < Grape::Validations::Base
- def validate_param!(attr_name, params)
- sha = params[attr_name]
-
- return if Commit::EXACT_COMMIT_SHA_PATTERN.match?(sha)
-
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
- message: "should be a valid sha"
- end
- end
-
- class Absence < Grape::Validations::Base
- def validate_param!(attr_name, params)
- return if params.respond_to?(:key?) && !params.key?(attr_name)
-
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:absence)
- end
- end
-
- class IntegerNoneAny < Grape::Validations::Base
- def validate_param!(attr_name, params)
- value = params[attr_name]
-
- return if value.is_a?(Integer) ||
- [IssuableFinder::Params::FILTER_NONE, IssuableFinder::Params::FILTER_ANY].include?(value.to_s.downcase)
-
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
- message: "should be an integer, 'None' or 'Any'"
- end
- end
-
- class ArrayNoneAny < Grape::Validations::Base
- def validate_param!(attr_name, params)
- value = params[attr_name]
-
- return if value.is_a?(Array) ||
- [IssuableFinder::Params::FILTER_NONE, IssuableFinder::Params::FILTER_ANY].include?(value.to_s.downcase)
-
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
- message: "should be an array, 'None' or 'Any'"
- end
- end
-
- class GitRef < Grape::Validations::Base
- # There are few checks that a Git reference should pass through to be valid reference.
- # The link contains some rules that have been added to this validator.
- # https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
- # We have skipped some checks that are optional and can be skipped for exception.
- # We also check for control characters, More info on ctrl chars - https://ruby-doc.org/core-2.7.0/Regexp.html#class-Regexp-label-Character+Classes
- INVALID_CHARS = Regexp.union('..', '\\', '@', '@{', ' ', '~', '^', ':', '*', '?', '[', /[[:cntrl:]]/).freeze
- GIT_REF_LENGTH = (1..1024).freeze
-
- def validate_param!(attr_name, params)
- revision = params[attr_name]
-
- return unless invalid_character?(revision)
-
- raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
- message: 'should be a valid reference path'
- end
-
- private
-
- def invalid_character?(revision)
- revision.nil? ||
- revision.start_with?('-') ||
- revision.end_with?('.') ||
- GIT_REF_LENGTH.exclude?(revision.length) ||
- INVALID_CHARS.match?(revision)
- end
- end
- end
- end
-end
-
-Grape::Validations.register_validator(:file_path, ::API::Helpers::CustomValidators::FilePath)
-Grape::Validations.register_validator(:git_sha, ::API::Helpers::CustomValidators::GitSha)
-Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence)
-Grape::Validations.register_validator(:integer_none_any, ::API::Helpers::CustomValidators::IntegerNoneAny)
-Grape::Validations.register_validator(:array_none_any, ::API::Helpers::CustomValidators::ArrayNoneAny)
-Grape::Validations.register_validator(:git_ref, ::API::Helpers::CustomValidators::GitRef)
diff --git a/lib/api/helpers/merge_requests_helpers.rb b/lib/api/helpers/merge_requests_helpers.rb
index e0753254002..73711a7e0ba 100644
--- a/lib/api/helpers/merge_requests_helpers.rb
+++ b/lib/api/helpers/merge_requests_helpers.rb
@@ -4,7 +4,6 @@ module API
module Helpers
module MergeRequestsHelpers
extend Grape::API::Helpers
- include ::API::Helpers::CustomValidators
params :merge_requests_base_params do
optional :state,