summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-28 00:06:20 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-28 00:06:20 +0000
commite08eba1838cb749b8815c7da98a504ff97bcfb98 (patch)
tree0172bc4d205f59dd6f3722b27d53e6aa8abb5825 /spec/support
parentd4633b0e70ec39583ce0b13f277f990b216ac0d9 (diff)
downloadgitlab-ce-e08eba1838cb749b8815c7da98a504ff97bcfb98.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/helpers/lfs_http_helpers.rb62
-rw-r--r--spec/support/shared_examples/lfs_http_shared_examples.rb43
2 files changed, 105 insertions, 0 deletions
diff --git a/spec/support/helpers/lfs_http_helpers.rb b/spec/support/helpers/lfs_http_helpers.rb
new file mode 100644
index 00000000000..0537b122040
--- /dev/null
+++ b/spec/support/helpers/lfs_http_helpers.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+require_relative 'workhorse_helpers'
+
+module LfsHttpHelpers
+ include WorkhorseHelpers
+
+ def authorize_ci_project
+ ActionController::HttpAuthentication::Basic.encode_credentials('gitlab-ci-token', build.token)
+ end
+
+ def authorize_user
+ ActionController::HttpAuthentication::Basic.encode_credentials(user.username, user.password)
+ end
+
+ def authorize_deploy_key
+ Gitlab::LfsToken.new(key).basic_encoding
+ end
+
+ def authorize_user_key
+ Gitlab::LfsToken.new(user).basic_encoding
+ end
+
+ def authorize_deploy_token
+ ActionController::HttpAuthentication::Basic.encode_credentials(deploy_token.username, deploy_token.token)
+ end
+
+ def post_lfs_json(url, body = nil, headers = nil)
+ params = body.try(:to_json)
+ headers = (headers || {}).merge('Content-Type' => LfsRequest::CONTENT_TYPE)
+
+ post(url, params: params, headers: headers)
+ end
+
+ def batch_url(project)
+ "#{project.http_url_to_repo}/info/lfs/objects/batch"
+ end
+
+ def objects_url(project, oid = nil, size = nil)
+ File.join(["#{project.http_url_to_repo}/gitlab-lfs/objects", oid, size].compact.map(&:to_s))
+ end
+
+ def authorize_url(project, oid, size)
+ File.join(objects_url(project, oid, size), 'authorize')
+ end
+
+ def download_body(objects)
+ request_body('download', objects)
+ end
+
+ def upload_body(objects)
+ request_body('upload', objects)
+ end
+
+ def request_body(operation, objects)
+ objects = [objects] unless objects.is_a?(Array)
+
+ {
+ 'operation' => operation,
+ 'objects' => objects
+ }
+ end
+end
diff --git a/spec/support/shared_examples/lfs_http_shared_examples.rb b/spec/support/shared_examples/lfs_http_shared_examples.rb
new file mode 100644
index 00000000000..bcd30fe9654
--- /dev/null
+++ b/spec/support/shared_examples/lfs_http_shared_examples.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+shared_examples 'LFS http 200 response' do
+ it_behaves_like 'LFS http expected response code and message' do
+ let(:response_code) { 200 }
+ end
+end
+
+shared_examples 'LFS http 401 response' do
+ it_behaves_like 'LFS http expected response code and message' do
+ let(:response_code) { 401 }
+ end
+end
+
+shared_examples 'LFS http 403 response' do
+ it_behaves_like 'LFS http expected response code and message' do
+ let(:response_code) { 403 }
+ let(:message) { 'Access forbidden. Check your access level.' }
+ end
+end
+
+shared_examples 'LFS http 501 response' do
+ it_behaves_like 'LFS http expected response code and message' do
+ let(:response_code) { 501 }
+ let(:message) { 'Git LFS is not enabled on this GitLab server, contact your admin.' }
+ end
+end
+
+shared_examples 'LFS http 404 response' do
+ it_behaves_like 'LFS http expected response code and message' do
+ let(:response_code) { 404 }
+ end
+end
+
+shared_examples 'LFS http expected response code and message' do
+ let(:response_code) { }
+ let(:message) { }
+
+ it 'responds with the expected response code and message' do
+ expect(response).to have_gitlab_http_status(response_code)
+ expect(json_response['message']).to eq(message) if message
+ end
+end