2019-10-29 00:06:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-23 09:23:47 +00:00
|
|
|
require 'spec_helper'
|
2013-12-20 19:12:44 +00:00
|
|
|
require 'mime/types'
|
2013-05-23 09:23:47 +00:00
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe API::Repositories do
|
2014-08-01 12:41:02 +00:00
|
|
|
include RepoHelpers
|
2016-02-11 17:10:14 +00:00
|
|
|
include WorkhorseHelpers
|
2014-08-01 12:41:02 +00:00
|
|
|
|
2013-05-23 09:23:47 +00:00
|
|
|
let(:user) { create(:user) }
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:guest) { create(:user).tap { |u| create(:project_member, :guest, user: u, project: project) } }
|
2017-01-26 23:51:57 +00:00
|
|
|
let!(:project) { create(:project, :repository, creator: user) }
|
2018-07-11 14:36:08 +00:00
|
|
|
let!(:maintainer) { create(:project_member, :maintainer, user: user, project: project) }
|
2016-12-19 15:26:59 +00:00
|
|
|
|
2013-06-06 15:01:03 +00:00
|
|
|
describe "GET /projects/:id/repository/tree" do
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:route) { "/projects/#{project.id}/repository/tree" }
|
2013-06-06 15:01:03 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
shared_examples_for 'repository tree' do
|
|
|
|
it 'returns the repository tree' do
|
|
|
|
get api(route, current_user)
|
2016-08-29 15:23:40 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 20:49:10 +00:00
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
2013-06-06 15:01:03 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
first_commit = json_response.first
|
|
|
|
expect(first_commit['name']).to eq('bar')
|
|
|
|
expect(first_commit['type']).to eq('tree')
|
|
|
|
expect(first_commit['mode']).to eq('040000')
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when ref does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2017-03-08 00:14:33 +00:00
|
|
|
let(:request) { get api("#{route}?ref=foo", current_user) }
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:message) { '404 Tree Not Found' }
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
2013-06-06 15:01:03 +00:00
|
|
|
end
|
2015-01-18 21:17:10 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'with recursive=1' do
|
|
|
|
it 'returns recursive project paths tree' do
|
|
|
|
get api("#{route}?recursive=1", current_user)
|
2015-01-18 21:17:10 +00:00
|
|
|
|
2020-03-31 21:08:05 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-19 15:26:59 +00:00
|
|
|
expect(json_response).to be_an Array
|
2017-01-24 20:49:10 +00:00
|
|
|
expect(response).to include_pagination_headers
|
2016-12-19 15:26:59 +00:00
|
|
|
expect(json_response[4]['name']).to eq('html')
|
|
|
|
expect(json_response[4]['path']).to eq('files/html')
|
|
|
|
expect(json_response[4]['type']).to eq('tree')
|
|
|
|
expect(json_response[4]['mode']).to eq('040000')
|
|
|
|
end
|
2013-06-06 15:01:03 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ref does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2017-03-08 00:14:33 +00:00
|
|
|
let(:request) { get api("#{route}?recursive=1&ref=foo", current_user) }
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:message) { '404 Tree Not Found' }
|
|
|
|
end
|
|
|
|
end
|
2013-06-06 15:01:03 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 15:23:40 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository tree' do
|
2017-01-26 23:51:57 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:current_user) { nil }
|
2016-08-29 15:23:40 +00:00
|
|
|
end
|
2016-12-19 15:26:59 +00:00
|
|
|
end
|
2016-08-29 15:23:40 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
2016-11-23 20:14:08 +00:00
|
|
|
end
|
2016-08-29 15:23:40 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository tree' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
2016-08-29 15:23:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-01 20:22:29 +00:00
|
|
|
describe "GET /projects/:id/repository/blobs/:sha" do
|
|
|
|
let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}" }
|
|
|
|
|
|
|
|
shared_examples_for 'repository blob' do
|
|
|
|
it 'returns blob attributes as json' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-03-01 20:22:29 +00:00
|
|
|
expect(json_response['size']).to eq(111)
|
|
|
|
expect(json_response['encoding']).to eq("base64")
|
|
|
|
expect(Base64.decode64(json_response['content']).lines.first).to eq("class Commit\n")
|
|
|
|
expect(json_response['sha']).to eq(sample_blob.oid)
|
2016-12-19 15:26:59 +00:00
|
|
|
end
|
2013-05-23 09:23:47 +00:00
|
|
|
|
2017-03-01 20:22:29 +00:00
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2020-04-01 15:07:45 +00:00
|
|
|
let(:request) { get api(route.sub(sample_blob.oid, 'abcd9876'), current_user) }
|
2017-03-01 20:22:29 +00:00
|
|
|
let(:message) { '404 Blob Not Found' }
|
2016-12-19 15:26:59 +00:00
|
|
|
end
|
|
|
|
end
|
2013-05-23 09:23:47 +00:00
|
|
|
|
2017-03-01 20:22:29 +00:00
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
it_behaves_like '403 response' do
|
2017-03-01 20:22:29 +00:00
|
|
|
let(:request) { get api(route, current_user) }
|
2016-12-19 15:26:59 +00:00
|
|
|
end
|
|
|
|
end
|
2013-05-23 09:23:47 +00:00
|
|
|
end
|
2017-03-01 20:22:29 +00:00
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'repository blob' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'repository blob' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
|
|
|
end
|
2013-05-23 09:23:47 +00:00
|
|
|
end
|
2013-08-28 01:22:42 +00:00
|
|
|
|
2017-03-01 20:22:29 +00:00
|
|
|
describe "GET /projects/:id/repository/blobs/:sha/raw" do
|
|
|
|
let(:route) { "/projects/#{project.id}/repository/blobs/#{sample_blob.oid}/raw" }
|
2016-12-19 15:26:59 +00:00
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
shared_examples_for 'repository raw blob' do
|
|
|
|
it 'returns the repository raw blob' do
|
2017-03-01 20:22:29 +00:00
|
|
|
expect(Gitlab::Workhorse).to receive(:send_git_blob)
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
get api(route, current_user)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-01-10 12:30:19 +00:00
|
|
|
expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
2016-12-19 15:26:59 +00:00
|
|
|
|
2019-01-10 12:30:19 +00:00
|
|
|
it 'sets inline content disposition by default' do
|
2018-11-23 16:44:09 +00:00
|
|
|
get api(route, current_user)
|
|
|
|
|
2019-01-10 12:30:19 +00:00
|
|
|
expect(headers['Content-Disposition']).to eq 'inline'
|
2018-11-23 16:44:09 +00:00
|
|
|
end
|
|
|
|
|
2020-05-27 21:08:05 +00:00
|
|
|
it_behaves_like 'uncached response' do
|
|
|
|
before do
|
|
|
|
get api(route, current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
2020-04-01 15:07:45 +00:00
|
|
|
let(:request) { get api(route.sub(sample_blob.oid, 'abcd9876'), current_user) }
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:message) { '404 Blob Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository is disabled' do
|
|
|
|
include_context 'disabled repository'
|
|
|
|
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, current_user) }
|
|
|
|
end
|
|
|
|
end
|
2013-08-28 01:22:42 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is public' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository raw blob' do
|
2017-01-26 23:51:57 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-16 17:21:58 +00:00
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository raw blob' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2013-12-23 09:37:38 +00:00
|
|
|
end
|
2015-01-18 21:17:10 +00:00
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2015-01-18 21:17:10 +00:00
|
|
|
end
|
2013-12-23 09:37:38 +00:00
|
|
|
end
|
|
|
|
|
2013-12-20 19:12:44 +00:00
|
|
|
describe "GET /projects/:id/repository/archive(.:format)?:sha" do
|
2020-07-06 12:09:00 +00:00
|
|
|
let(:project_id) { CGI.escape(project.full_path) }
|
|
|
|
let(:route) { "/projects/#{project_id}/repository/archive" }
|
2016-12-19 15:26:59 +00:00
|
|
|
|
2020-02-22 12:08:58 +00:00
|
|
|
before do
|
|
|
|
allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
shared_examples_for 'repository archive' do
|
|
|
|
it 'returns the repository archive' do
|
2016-12-19 15:26:59 +00:00
|
|
|
get api(route, current_user)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-06-05 18:22:55 +00:00
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.gz/)
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the repository archive archive.zip' do
|
2020-07-06 12:09:00 +00:00
|
|
|
get api("/projects/#{project_id}/repository/archive.zip", user)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-06-05 18:22:55 +00:00
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.zip/)
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the repository archive archive.tar.bz2' do
|
2020-07-06 12:09:00 +00:00
|
|
|
get api("/projects/#{project_id}/repository/archive.tar.bz2", user)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
|
|
|
type, params = workhorse_send_data
|
|
|
|
|
|
|
|
expect(type).to eq('git-archive')
|
2018-06-05 18:22:55 +00:00
|
|
|
expect(params['ArchivePath']).to match(/#{project.path}\-[^\.]+\.tar.bz2/)
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
2016-12-19 15:26:59 +00:00
|
|
|
|
|
|
|
context 'when sha does not exist' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api("#{route}?sha=xxx", current_user) }
|
|
|
|
let(:message) { '404 File Not Found' }
|
|
|
|
end
|
|
|
|
end
|
2020-02-22 12:08:58 +00:00
|
|
|
|
|
|
|
it 'rate limits user when thresholds hit' do
|
|
|
|
allow(::Gitlab::ApplicationRateLimiter).to receive(:throttled?).and_return(true)
|
|
|
|
|
2020-07-06 12:09:00 +00:00
|
|
|
get api("/projects/#{project_id}/repository/archive.tar.bz2", user)
|
2020-02-22 12:08:58 +00:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:too_many_requests)
|
|
|
|
end
|
2020-03-26 18:08:03 +00:00
|
|
|
|
|
|
|
context "when hotlinking detection is enabled" do
|
|
|
|
before do
|
2020-05-29 18:08:26 +00:00
|
|
|
stub_feature_flags(repository_archive_hotlinking_interception: true)
|
2020-03-26 18:08:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "hotlink interceptor" do
|
|
|
|
let(:http_request) do
|
|
|
|
get api(route, current_user), headers: headers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-12-20 19:12:44 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is public' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository archive' do
|
2017-01-26 23:51:57 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-16 17:21:58 +00:00
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
2013-12-20 19:12:44 +00:00
|
|
|
end
|
|
|
|
|
2020-07-06 12:09:00 +00:00
|
|
|
context 'when unauthenticated and project path has dots' do
|
|
|
|
it_behaves_like 'repository archive' do
|
|
|
|
let(:project) { create(:project, :public, :repository, path: 'path.with.dot') }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository archive' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2013-09-26 20:42:49 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
2013-09-26 20:42:49 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-26 15:05:55 +00:00
|
|
|
|
2014-07-02 09:40:20 +00:00
|
|
|
describe 'GET /projects/:id/repository/compare' do
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:route) { "/projects/#{project.id}/repository/compare" }
|
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
shared_examples_for 'repository compare' do
|
|
|
|
it "compares branches" do
|
2018-06-23 19:39:11 +00:00
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: false
|
|
|
|
}).and_call_original
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
2014-05-26 15:05:55 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
2018-06-23 19:39:11 +00:00
|
|
|
it "compares branches with explicit merge-base mode" do
|
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: false
|
|
|
|
}).and_call_original
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature', straight: false }
|
2018-06-23 19:39:11 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-06-23 19:39:11 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "compares branches with explicit straight mode" do
|
|
|
|
expect(::Gitlab::Git::Compare).to receive(:new).with(anything, anything, anything, {
|
|
|
|
straight: true
|
|
|
|
}).and_call_original
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature', straight: true }
|
2018-06-23 19:39:11 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-06-23 19:39:11 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
it "compares tags" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: 'v1.0.0', to: 'v1.1.0' }
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "compares commits" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: sample_commit.id, to: sample_commit.parent_id }
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_falsey
|
|
|
|
end
|
2014-05-27 08:27:42 +00:00
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
it "compares commits in reverse order" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: sample_commit.parent_id, to: sample_commit.id }
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "compares same refs" do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { from: 'master', to: 'master' }
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response['commits']).to be_empty
|
|
|
|
expect(json_response['diffs']).to be_empty
|
|
|
|
expect(json_response['compare_same_ref']).to be_truthy
|
|
|
|
end
|
2020-01-22 18:08:47 +00:00
|
|
|
|
|
|
|
it "returns an empty string when the diff overflows" do
|
2020-09-21 15:09:44 +00:00
|
|
|
allow(Gitlab::Git::DiffCollection)
|
|
|
|
.to receive(:default_limits)
|
|
|
|
.and_return({ max_files: 2, max_lines: 2 })
|
2020-01-22 18:08:47 +00:00
|
|
|
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'feature' }
|
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-01-22 18:08:47 +00:00
|
|
|
expect(json_response['commits']).to be_present
|
|
|
|
expect(json_response['diffs']).to be_present
|
|
|
|
expect(json_response['diffs'].first['diff']).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 when from ref is unknown" do
|
|
|
|
get api(route, current_user), params: { from: 'unknown_ref', to: 'master' }
|
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-01-22 18:08:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404 when to ref is unknown" do
|
|
|
|
get api(route, current_user), params: { from: 'master', to: 'unknown_ref' }
|
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2020-01-22 18:08:47 +00:00
|
|
|
end
|
2014-05-26 15:05:55 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is public' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository compare' do
|
2017-01-26 23:51:57 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-16 17:21:58 +00:00
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
2014-05-27 08:27:42 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository compare' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2014-05-26 15:05:55 +00:00
|
|
|
end
|
2016-12-19 15:26:59 +00:00
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
|
|
|
end
|
2014-05-26 15:05:55 +00:00
|
|
|
end
|
2014-07-02 09:40:20 +00:00
|
|
|
|
|
|
|
describe 'GET /projects/:id/repository/contributors' do
|
2016-12-19 15:26:59 +00:00
|
|
|
let(:route) { "/projects/#{project.id}/repository/contributors" }
|
|
|
|
|
2016-12-16 17:21:58 +00:00
|
|
|
shared_examples_for 'repository contributors' do
|
|
|
|
it 'returns valid data' do
|
2016-12-19 15:26:59 +00:00
|
|
|
get api(route, current_user)
|
2016-12-16 17:21:58 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 20:49:10 +00:00
|
|
|
expect(response).to include_pagination_headers
|
2016-12-16 17:21:58 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
|
|
|
|
first_contributor = json_response.first
|
|
|
|
expect(first_contributor['email']).to eq('tiagonbotelho@hotmail.com')
|
|
|
|
expect(first_contributor['name']).to eq('tiagonbotelho')
|
|
|
|
expect(first_contributor['commits']).to eq(1)
|
|
|
|
expect(first_contributor['additions']).to eq(0)
|
|
|
|
expect(first_contributor['deletions']).to eq(0)
|
|
|
|
end
|
2017-11-18 14:06:55 +00:00
|
|
|
|
|
|
|
context 'using sorting' do
|
|
|
|
context 'by commits desc' do
|
|
|
|
it 'returns the repository contribuors sorted by commits desc' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { order_by: 'commits', sort: 'desc' }
|
2017-11-18 14:06:55 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-11-18 14:06:55 +00:00
|
|
|
expect(response).to match_response_schema('contributors')
|
|
|
|
expect(json_response.first['commits']).to be > json_response.last['commits']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by name desc' do
|
|
|
|
it 'returns the repository contribuors sorted by name asc case insensitive' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get api(route, current_user), params: { order_by: 'name', sort: 'asc' }
|
2017-11-18 14:06:55 +00:00
|
|
|
|
2020-03-02 18:07:42 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-11-18 14:06:55 +00:00
|
|
|
expect(response).to match_response_schema('contributors')
|
|
|
|
expect(json_response.first['name'].downcase).to be < json_response.last['name'].downcase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 17:21:58 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is public' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository contributors' do
|
2017-01-26 23:51:57 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-12-16 17:21:58 +00:00
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 15:26:59 +00:00
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:request) { get api(route) }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
2016-12-16 17:21:58 +00:00
|
|
|
it_behaves_like 'repository contributors' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
2014-07-02 09:40:20 +00:00
|
|
|
end
|
2016-12-19 15:26:59 +00:00
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:request) { get api(route, guest) }
|
|
|
|
end
|
|
|
|
end
|
2018-04-16 10:30:40 +00:00
|
|
|
|
2019-09-18 14:02:45 +00:00
|
|
|
# Regression: https://gitlab.com/gitlab-org/gitlab-foss/issues/45363
|
2018-04-16 10:30:40 +00:00
|
|
|
describe 'Links header contains working URLs when no `order_by` nor `sort` is given' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it 'returns `Link` header that includes URLs with default value for `order_by` & `sort`' do
|
|
|
|
get api(route, current_user)
|
|
|
|
|
|
|
|
first_link_url = response.headers['Link'].split(';').first
|
|
|
|
|
|
|
|
expect(first_link_url).to include('order_by=commits')
|
|
|
|
expect(first_link_url).to include('sort=asc')
|
|
|
|
end
|
|
|
|
end
|
2014-07-02 09:40:20 +00:00
|
|
|
end
|
2018-07-31 14:38:03 +00:00
|
|
|
|
|
|
|
describe 'GET :id/repository/merge_base' do
|
|
|
|
let(:refs) do
|
2018-10-11 14:27:04 +00:00
|
|
|
%w(304d257dcb821665ab5110318fc58a007bd104ed 0031876facac3f2b2702a0e53a26e89939a42209 570e7b2abdd848b95f2f578043fc23bd6f6fd24d)
|
2018-07-31 14:38:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
subject(:request) do
|
2018-12-17 22:52:17 +00:00
|
|
|
get(api("/projects/#{project.id}/repository/merge_base", current_user), params: { refs: refs })
|
2018-07-31 14:38:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'merge base' do
|
|
|
|
it 'returns the common ancestor' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
expect(json_response['id']).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is public' do
|
|
|
|
it_behaves_like 'merge base' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:current_user) { nil }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unauthenticated', 'and project is private' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
let(:message) { '404 Project Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a developer' do
|
|
|
|
it_behaves_like 'merge base' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when authenticated', 'as a guest' do
|
|
|
|
it_behaves_like '403 response' do
|
|
|
|
let(:current_user) { guest }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing refs that do not exist' do
|
|
|
|
it_behaves_like '400 response' do
|
|
|
|
let(:refs) { %w(304d257dcb821665ab5110318fc58a007bd104ed missing) }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:message) { 'Could not find ref: missing' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing refs that do not have a merge base' do
|
|
|
|
it_behaves_like '404 response' do
|
|
|
|
let(:refs) { ['304d257dcb821665ab5110318fc58a007bd104ed', TestEnv::BRANCH_SHA['orphaned-branch']] }
|
|
|
|
let(:current_user) { user }
|
|
|
|
let(:message) { '404 Merge Base Not Found' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not enough refs are passed' do
|
|
|
|
let(:refs) { %w(only-one) }
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it 'renders a bad request error' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2018-10-11 14:27:04 +00:00
|
|
|
expect(json_response['message']).to eq('Provide at least 2 refs')
|
2018-07-31 14:38:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-23 09:23:47 +00:00
|
|
|
end
|