Class: Constraints::RepositoryRedirectUrlConstrainer

Inherits:
Object
  • Object
show all
Defined in:
lib/constraints/repository_redirect_url_constrainer.rb

Instance Method Summary collapse

Instance Method Details

#container_path?(path) ⇒ Boolean

Check if the path matches any known repository containers. These also cover wikis, since a `.wiki` suffix is valid in project/group paths too.

Returns:

  • (Boolean)

22
23
24
25
26
# File 'lib/constraints/repository_redirect_url_constrainer.rb', line 22

def container_path?(path)
  NamespacePathValidator.valid_path?(path) ||
    ProjectPathValidator.valid_path?(path) ||
    path =~ Gitlab::PathRegex.full_snippets_repository_path_regex
end

#git_request?(query) ⇒ Boolean

Allow /info/refs, /info/refs?service=git-upload-pack, and /info/refs?service=git-receive-pack, but nothing else.

Returns:

  • (Boolean)

14
15
16
17
18
# File 'lib/constraints/repository_redirect_url_constrainer.rb', line 14

def git_request?(query)
  query.blank? ||
    query == 'service=git-upload-pack' ||
    query == 'service=git-receive-pack'
end

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)

5
6
7
8
9
10
# File 'lib/constraints/repository_redirect_url_constrainer.rb', line 5

def matches?(request)
  path = request.params[:repository_path].delete_suffix('.git')
  query = request.query_string

  git_request?(query) && container_path?(path)
end