debian-mirror-gitlab/spec/support/helpers/git_http_helpers.rb

70 lines
2.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-09-30 21:07:59 +05:30
require_relative 'workhorse_helpers'
2016-11-03 12:29:30 +05:30
module GitHttpHelpers
2019-09-30 21:07:59 +05:30
include WorkhorseHelpers
2021-01-03 14:25:43 +05:30
def clone_get(project, **options)
2019-02-15 15:39:39 +05:30
get "/#{project}/info/refs", params: { service: 'git-upload-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
2016-11-03 12:29:30 +05:30
end
2021-01-03 14:25:43 +05:30
def clone_post(project, **options)
2019-02-15 15:39:39 +05:30
post "/#{project}/git-upload-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
2016-11-03 12:29:30 +05:30
end
2021-01-03 14:25:43 +05:30
def push_get(project, **options)
2019-02-15 15:39:39 +05:30
get "/#{project}/info/refs", params: { service: 'git-receive-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
2016-11-03 12:29:30 +05:30
end
2021-01-03 14:25:43 +05:30
def push_post(project, **options)
2019-02-15 15:39:39 +05:30
post "/#{project}/git-receive-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
2016-11-03 12:29:30 +05:30
end
def download(project, user: nil, password: nil, spnego_request_token: nil)
2021-01-03 14:25:43 +05:30
args = { user: user, password: password, spnego_request_token: spnego_request_token }
2016-11-03 12:29:30 +05:30
2021-01-03 14:25:43 +05:30
clone_get(project, **args)
2016-11-03 12:29:30 +05:30
yield response
2021-01-03 14:25:43 +05:30
clone_post(project, **args)
2016-11-03 12:29:30 +05:30
yield response
end
def upload(project, user: nil, password: nil, spnego_request_token: nil)
2021-01-03 14:25:43 +05:30
args = { user: user, password: password, spnego_request_token: spnego_request_token }
2016-11-03 12:29:30 +05:30
2021-01-03 14:25:43 +05:30
push_get(project, **args)
2016-11-03 12:29:30 +05:30
yield response
2021-01-03 14:25:43 +05:30
push_post(project, **args)
2016-11-03 12:29:30 +05:30
yield response
end
2021-01-03 14:25:43 +05:30
def download_or_upload(project, **args, &block)
download(project, **args, &block)
upload(project, **args, &block)
2017-09-10 17:25:29 +05:30
end
2016-11-03 12:29:30 +05:30
def auth_env(user, password, spnego_request_token)
env = workhorse_internal_api_request_header
2017-09-10 17:25:29 +05:30
if user
2016-11-03 12:29:30 +05:30
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user, password)
elsif spnego_request_token
env['HTTP_AUTHORIZATION'] = "Negotiate #{::Base64.strict_encode64('opaque_request_token')}"
end
env
end
2017-09-10 17:25:29 +05:30
def git_access_error(error_key)
message = Gitlab::GitAccess::ERROR_MESSAGES[error_key]
message || raise("GitAccess error message key '#{error_key}' not found")
end
def git_access_wiki_error(error_key)
message = Gitlab::GitAccessWiki::ERROR_MESSAGES[error_key]
message || raise("GitAccessWiki error message key '#{error_key}' not found")
end
2016-11-03 12:29:30 +05:30
end