2013-02-26 15:53:59 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Internal do
|
2018-05-17 09:19:32 -04:00
|
|
|
set(:user) { create(:user) }
|
2013-02-26 15:53:59 -05:00
|
|
|
let(:key) { create(:key, user: user) }
|
2018-05-17 09:19:32 -04:00
|
|
|
set(:project) { create(:project, :repository, :wiki_repo) }
|
2016-11-18 06:02:45 -05:00
|
|
|
let(:secret_token) { Gitlab::Shell.secret_token }
|
2017-08-31 17:01:07 -04:00
|
|
|
let(:gl_repository) { "project-#{project.id}" }
|
|
|
|
let(:reference_counter) { double('ReferenceCounter') }
|
2013-02-26 15:53:59 -05:00
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe "GET /internal/check" do
|
2013-02-26 15:53:59 -05:00
|
|
|
it do
|
2017-08-31 17:00:40 -04:00
|
|
|
expect_any_instance_of(Redis).to receive(:ping).and_return('PONG')
|
|
|
|
|
2014-10-15 11:26:15 -04:00
|
|
|
get api("/internal/check"), secret_token: secret_token
|
2013-02-26 15:53:59 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['api_version']).to eq(API::API.version)
|
2017-08-31 17:00:40 -04:00
|
|
|
expect(json_response['redis']).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for field `redis` when redis is unavailable' do
|
|
|
|
expect_any_instance_of(Redis).to receive(:ping).and_raise(Errno::ENOENT)
|
|
|
|
|
|
|
|
get api("/internal/check"), secret_token: secret_token
|
|
|
|
|
|
|
|
expect(json_response['redis']).to be(false)
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-15 09:47:33 -04:00
|
|
|
describe 'GET /internal/broadcast_message' do
|
|
|
|
context 'broadcast message exists' do
|
|
|
|
let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) }
|
2015-02-07 10:41:30 -05:00
|
|
|
|
2017-06-15 09:47:33 -04:00
|
|
|
it 'returns one broadcast message' do
|
|
|
|
get api('/internal/broadcast_message'), secret_token: secret_token
|
2015-02-07 10:41:30 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-15 09:47:33 -04:00
|
|
|
expect(json_response['message']).to eq(broadcast_message.message)
|
2015-02-07 10:41:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-15 09:47:33 -04:00
|
|
|
context 'broadcast message does not exist' do
|
|
|
|
it 'returns nothing' do
|
|
|
|
get api('/internal/broadcast_message'), secret_token: secret_token
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-15 09:47:33 -04:00
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2017-07-14 00:38:26 -04:00
|
|
|
|
|
|
|
context 'nil broadcast message' do
|
|
|
|
it 'returns nothing' do
|
|
|
|
allow(BroadcastMessage).to receive(:current).and_return(nil)
|
|
|
|
|
|
|
|
get api('/internal/broadcast_message'), secret_token: secret_token
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-07-14 00:38:26 -04:00
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2017-06-15 09:47:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /internal/broadcast_messages' do
|
|
|
|
context 'broadcast message(s) exist' do
|
|
|
|
let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) }
|
|
|
|
|
|
|
|
it 'returns active broadcast message(s)' do
|
|
|
|
get api('/internal/broadcast_messages'), secret_token: secret_token
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-15 09:47:33 -04:00
|
|
|
expect(json_response[0]['message']).to eq(broadcast_message.message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'broadcast message does not exist' do
|
|
|
|
it 'returns nothing' do
|
|
|
|
get api('/internal/broadcast_messages'), secret_token: secret_token
|
2015-02-07 10:41:30 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-18 17:58:20 -05:00
|
|
|
expect(json_response).to be_empty
|
2015-02-07 10:41:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-26 17:48:51 -04:00
|
|
|
describe 'GET /internal/two_factor_recovery_codes' do
|
|
|
|
it 'returns an error message when the key does not exist' do
|
|
|
|
post api('/internal/two_factor_recovery_codes'),
|
|
|
|
secret_token: secret_token,
|
|
|
|
key_id: 12345
|
|
|
|
|
2016-08-24 20:58:05 -04:00
|
|
|
expect(json_response['success']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq('Could not find the given key')
|
2016-07-26 17:48:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error message when the key is a deploy key' do
|
|
|
|
deploy_key = create(:deploy_key)
|
|
|
|
|
|
|
|
post api('/internal/two_factor_recovery_codes'),
|
|
|
|
secret_token: secret_token,
|
|
|
|
key_id: deploy_key.id
|
|
|
|
|
|
|
|
expect(json_response['success']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq('Deploy keys cannot be used to retrieve recovery codes')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error message when the user does not exist' do
|
|
|
|
key_without_user = create(:key, user: nil)
|
|
|
|
|
|
|
|
post api('/internal/two_factor_recovery_codes'),
|
|
|
|
secret_token: secret_token,
|
|
|
|
key_id: key_without_user.id
|
|
|
|
|
|
|
|
expect(json_response['success']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq('Could not find a user for the given key')
|
|
|
|
expect(json_response['recovery_codes']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when two-factor is enabled' do
|
|
|
|
it 'returns new recovery codes when the user exists' do
|
|
|
|
allow_any_instance_of(User).to receive(:two_factor_enabled?).and_return(true)
|
|
|
|
allow_any_instance_of(User)
|
|
|
|
.to receive(:generate_otp_backup_codes!).and_return(%w(119135e5a3ebce8e 34bd7b74adbc8861))
|
|
|
|
|
|
|
|
post api('/internal/two_factor_recovery_codes'),
|
|
|
|
secret_token: secret_token,
|
|
|
|
key_id: key.id
|
|
|
|
|
|
|
|
expect(json_response['success']).to be_truthy
|
|
|
|
expect(json_response['recovery_codes']).to match_array(%w(119135e5a3ebce8e 34bd7b74adbc8861))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when two-factor is not enabled' do
|
|
|
|
it 'returns an error message' do
|
|
|
|
allow_any_instance_of(User).to receive(:two_factor_enabled?).and_return(false)
|
|
|
|
|
|
|
|
post api('/internal/two_factor_recovery_codes'),
|
|
|
|
secret_token: secret_token,
|
|
|
|
key_id: key.id
|
|
|
|
|
|
|
|
expect(json_response['success']).to be_falsey
|
|
|
|
expect(json_response['recovery_codes']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-19 10:34:32 -04:00
|
|
|
describe "POST /internal/lfs_authenticate" do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-09-19 10:34:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'user key' do
|
|
|
|
it 'returns the correct information about the key' do
|
|
|
|
lfs_auth(key.id, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-19 10:34:32 -04:00
|
|
|
expect(json_response['username']).to eq(user.username)
|
2016-09-28 12:02:31 -04:00
|
|
|
expect(json_response['lfs_token']).to eq(Gitlab::LfsToken.new(key).token)
|
2016-09-19 10:34:32 -04:00
|
|
|
|
|
|
|
expect(json_response['repository_http_path']).to eq(project.http_url_to_repo)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a 404 when the wrong key is provided' do
|
|
|
|
lfs_auth(nil, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-09-19 10:34:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'deploy key' do
|
|
|
|
let(:key) { create(:deploy_key) }
|
|
|
|
|
|
|
|
it 'returns the correct information about the key' do
|
|
|
|
lfs_auth(key.id, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-19 10:34:32 -04:00
|
|
|
expect(json_response['username']).to eq("lfs+deploy-key-#{key.id}")
|
2016-09-28 12:02:31 -04:00
|
|
|
expect(json_response['lfs_token']).to eq(Gitlab::LfsToken.new(key).token)
|
2016-09-19 10:34:32 -04:00
|
|
|
expect(json_response['repository_http_path']).to eq(project.http_url_to_repo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-30 14:38:22 -04:00
|
|
|
describe "GET /internal/discover" do
|
|
|
|
it do
|
|
|
|
get(api("/internal/discover"), key_id: key.id, secret_token: secret_token)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-30 14:38:22 -04:00
|
|
|
|
|
|
|
expect(json_response['name']).to eq(user.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-01 12:53:01 -05:00
|
|
|
describe "GET /internal/authorized_keys" do
|
2018-01-08 13:24:51 -05:00
|
|
|
context "using an existing key's fingerprint" do
|
2016-03-01 12:53:01 -05:00
|
|
|
it "finds the key" do
|
|
|
|
get(api('/internal/authorized_keys'), fingerprint: key.fingerprint, secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response["key"]).to eq(key.key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "non existing key's fingerprint" do
|
|
|
|
it "returns 404" do
|
|
|
|
get(api('/internal/authorized_keys'), fingerprint: "no:t-:va:li:d0", secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "using a partial fingerprint" do
|
|
|
|
it "returns 404" do
|
|
|
|
get(api('/internal/authorized_keys'), fingerprint: "#{key.fingerprint[0..5]}%", secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "sending the key" do
|
|
|
|
it "finds the key" do
|
|
|
|
get(api('/internal/authorized_keys'), key: key.key.split[1], secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response["key"]).to eq(key.key)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 with a partial key" do
|
|
|
|
get(api('/internal/authorized_keys'), key: key.key.split[1][0...-3], secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 with an not valid base64 string" do
|
|
|
|
get(api('/internal/authorized_keys'), key: "whatever!", secret_token: secret_token)
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
describe "POST /internal/allowed", :clean_gitlab_redis_shared_state do
|
2013-02-26 15:53:59 -05:00
|
|
|
context "access granted" do
|
2017-08-11 06:36:03 -04:00
|
|
|
around do |example|
|
|
|
|
Timecop.freeze { example.run }
|
2016-10-05 10:41:32 -04:00
|
|
|
end
|
|
|
|
|
2017-08-11 06:36:03 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
|
2017-04-05 03:29:30 -04:00
|
|
|
context 'with env passed as a JSON' do
|
2018-03-30 05:19:46 -04:00
|
|
|
let(:gl_repository) { project.gl_repository(is_wiki: true) }
|
|
|
|
|
|
|
|
it 'sets env in RequestStore' do
|
|
|
|
obj_dir_relative = './objects'
|
|
|
|
alt_obj_dirs_relative = ['./alt-objects-1', './alt-objects-2']
|
|
|
|
|
|
|
|
expect(Gitlab::Git::HookEnv).to receive(:set).with(gl_repository, {
|
|
|
|
'GIT_OBJECT_DIRECTORY_RELATIVE' => obj_dir_relative,
|
|
|
|
'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => alt_obj_dirs_relative
|
|
|
|
})
|
2017-11-14 10:14:35 -05:00
|
|
|
|
2018-03-30 05:19:46 -04:00
|
|
|
push(key, project.wiki, env: {
|
|
|
|
GIT_OBJECT_DIRECTORY_RELATIVE: obj_dir_relative,
|
|
|
|
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE: alt_obj_dirs_relative
|
|
|
|
}.to_json)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-04-05 03:29:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-24 09:54:36 -05:00
|
|
|
context "git push with project.wiki" do
|
2016-02-29 04:59:16 -05:00
|
|
|
it 'responds with success' do
|
2016-07-15 21:31:26 -04:00
|
|
|
push(key, project.wiki)
|
2016-02-26 04:40:30 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-07-15 21:31:26 -04:00
|
|
|
expect(json_response["status"]).to be_truthy
|
2018-05-25 07:45:29 -04:00
|
|
|
expect(json_response["repository_path"]).to eq('/')
|
2017-04-28 12:52:09 -04:00
|
|
|
expect(json_response["gl_repository"]).to eq("wiki-#{project.id}")
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).not_to have_an_activity_record
|
2016-07-15 21:31:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git pull with project.wiki" do
|
|
|
|
it 'responds with success' do
|
|
|
|
pull(key, project.wiki)
|
2016-02-24 09:54:36 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-02-24 09:54:36 -05:00
|
|
|
expect(json_response["status"]).to be_truthy
|
2018-05-25 07:45:29 -04:00
|
|
|
expect(json_response["repository_path"]).to eq('/')
|
2017-04-28 12:52:09 -04:00
|
|
|
expect(json_response["gl_repository"]).to eq("wiki-#{project.id}")
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).to have_an_activity_record
|
2016-02-24 09:54:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-26 15:53:59 -05:00
|
|
|
context "git pull" do
|
2018-01-22 11:51:47 -05:00
|
|
|
it "has the correct payload" do
|
|
|
|
pull(key, project)
|
2017-06-26 09:55:06 -04:00
|
|
|
|
2018-01-22 11:51:47 -05:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(json_response["status"]).to be_truthy
|
2018-05-25 07:45:29 -04:00
|
|
|
expect(json_response["repository_path"]).to eq('/')
|
2018-01-22 11:51:47 -05:00
|
|
|
expect(json_response["gl_repository"]).to eq("project-#{project.id}")
|
|
|
|
expect(json_response["gitaly"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]["storage_name"]).to eq(project.repository.gitaly_repository.storage_name)
|
|
|
|
expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(project.repository.gitaly_repository.relative_path)
|
|
|
|
expect(json_response["gitaly"]["address"]).to eq(Gitlab::GitalyClient.address(project.repository_storage))
|
|
|
|
expect(json_response["gitaly"]["token"]).to eq(Gitlab::GitalyClient.token(project.repository_storage))
|
|
|
|
expect(user).to have_an_activity_record
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git push" do
|
2018-03-06 18:53:44 -05:00
|
|
|
context 'project as namespace/project' do
|
|
|
|
it do
|
2017-06-26 09:55:06 -04:00
|
|
|
push(key, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-06-26 09:55:06 -04:00
|
|
|
expect(json_response["status"]).to be_truthy
|
2018-05-25 07:45:29 -04:00
|
|
|
expect(json_response["repository_path"]).to eq('/')
|
2017-06-26 09:55:06 -04:00
|
|
|
expect(json_response["gl_repository"]).to eq("project-#{project.id}")
|
|
|
|
expect(json_response["gitaly"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]["storage_name"]).to eq(project.repository.gitaly_repository.storage_name)
|
|
|
|
expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(project.repository.gitaly_repository.relative_path)
|
|
|
|
expect(json_response["gitaly"]["address"]).to eq(Gitlab::GitalyClient.address(project.repository_storage))
|
|
|
|
expect(json_response["gitaly"]["token"]).to eq(Gitlab::GitalyClient.token(project.repository_storage))
|
|
|
|
expect(user).not_to have_an_activity_record
|
|
|
|
end
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "access denied" do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(user)
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "git pull" do
|
|
|
|
it do
|
2013-03-07 07:18:30 -05:00
|
|
|
pull(key, project)
|
2013-02-26 15:53:59 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).not_to have_an_activity_record
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git push" do
|
|
|
|
it do
|
2013-03-07 07:18:30 -05:00
|
|
|
push(key, project)
|
2013-02-26 15:53:59 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).not_to have_an_activity_record
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-07 07:18:30 -05:00
|
|
|
context "blocked user" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:personal_project) { create(:project, namespace: user.namespace) }
|
2013-03-07 07:18:30 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.block
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git pull" do
|
|
|
|
it do
|
|
|
|
pull(key, personal_project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).not_to have_an_activity_record
|
2013-03-07 07:18:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git push" do
|
|
|
|
it do
|
|
|
|
push(key, personal_project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2017-03-07 13:34:43 -05:00
|
|
|
expect(user).not_to have_an_activity_record
|
2013-03-07 07:18:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-07-29 08:25:33 -04:00
|
|
|
|
2013-11-29 11:10:59 -05:00
|
|
|
context "archived project" do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2013-11-29 11:10:59 -05:00
|
|
|
project.archive!
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git pull" do
|
|
|
|
it do
|
|
|
|
pull(key, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_truthy
|
2013-11-29 11:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "git push" do
|
|
|
|
it do
|
|
|
|
push(key, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2013-11-29 11:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-29 08:25:33 -04:00
|
|
|
context "deploy key" do
|
|
|
|
let(:key) { create(:deploy_key) }
|
|
|
|
|
|
|
|
context "added to project" do
|
|
|
|
before do
|
|
|
|
key.projects << project
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
archive(key, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_truthy
|
2018-03-21 09:57:06 -04:00
|
|
|
expect(json_response["gitaly"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]).not_to be_nil
|
|
|
|
expect(json_response["gitaly"]["repository"]["storage_name"]).to eq(project.repository.gitaly_repository.storage_name)
|
|
|
|
expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(project.repository.gitaly_repository.relative_path)
|
|
|
|
expect(json_response["gitaly"]["address"]).to eq(Gitlab::GitalyClient.address(project.repository_storage))
|
|
|
|
expect(json_response["gitaly"]["token"]).to eq(Gitlab::GitalyClient.token(project.repository_storage))
|
2013-07-29 08:25:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "not added to project" do
|
|
|
|
it do
|
|
|
|
archive(key, project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2013-07-29 08:25:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-12-01 09:55:33 -05:00
|
|
|
|
|
|
|
context 'project does not exist' do
|
2017-12-01 08:58:49 -05:00
|
|
|
it 'returns a 200 response with status: false' do
|
|
|
|
project.destroy
|
|
|
|
|
|
|
|
pull(key, project)
|
2014-12-01 09:55:33 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2014-12-01 09:55:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not exist' do
|
|
|
|
it do
|
|
|
|
pull(OpenStruct.new(id: 0), project)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response["status"]).to be_falsey
|
2014-12-01 09:55:33 -05:00
|
|
|
end
|
|
|
|
end
|
2016-06-22 20:16:24 -04:00
|
|
|
|
|
|
|
context 'ssh access has been disabled' do
|
|
|
|
before do
|
2017-01-21 19:11:19 -05:00
|
|
|
stub_application_setting(enabled_git_access_protocol: 'http')
|
2016-06-22 20:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the SSH push' do
|
|
|
|
push(key, project)
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['status']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq 'Git access over SSH is not allowed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the SSH pull' do
|
|
|
|
pull(key, project)
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['status']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq 'Git access over SSH is not allowed'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'http access has been disabled' do
|
|
|
|
before do
|
2017-01-21 19:11:19 -05:00
|
|
|
stub_application_setting(enabled_git_access_protocol: 'ssh')
|
2016-06-22 20:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the HTTP push' do
|
|
|
|
push(key, project, 'http')
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['status']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq 'Git access over HTTP is not allowed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the HTTP pull' do
|
|
|
|
pull(key, project, 'http')
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['status']).to be_falsey
|
|
|
|
expect(json_response['message']).to eq 'Git access over HTTP is not allowed'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'web actions are always allowed' do
|
|
|
|
it 'allows WEB push' do
|
2017-01-21 19:11:19 -05:00
|
|
|
stub_application_setting(enabled_git_access_protocol: 'ssh')
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-06-22 20:16:24 -04:00
|
|
|
push(key, project, 'web')
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['status']).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2017-06-15 20:03:54 -04:00
|
|
|
|
|
|
|
context 'the project path was changed' do
|
2017-12-01 08:58:49 -05:00
|
|
|
let(:project) { create(:project, :repository, :legacy_storage) }
|
2017-06-15 20:03:54 -04:00
|
|
|
let!(:old_path_to_repo) { project.repository.path_to_repo }
|
2017-12-08 12:42:43 -05:00
|
|
|
let!(:repository) { project.repository }
|
2017-06-15 20:03:54 -04:00
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-06-15 20:03:54 -04:00
|
|
|
project.path = 'new_path'
|
|
|
|
project.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the push' do
|
2017-12-08 12:42:43 -05:00
|
|
|
push(key, project)
|
2017-06-15 20:03:54 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-12-08 12:42:43 -05:00
|
|
|
expect(json_response['status']).to be_falsy
|
2017-06-15 20:03:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the SSH pull' do
|
2017-12-08 12:42:43 -05:00
|
|
|
pull(key, project)
|
2017-06-15 20:03:54 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-12-08 12:42:43 -05:00
|
|
|
expect(json_response['status']).to be_falsy
|
2017-06-15 20:03:54 -04:00
|
|
|
end
|
|
|
|
end
|
2013-03-07 07:18:30 -05:00
|
|
|
end
|
|
|
|
|
2016-07-28 00:04:57 -04:00
|
|
|
describe 'GET /internal/merge_request_urls' do
|
|
|
|
let(:repo_name) { "#{project.namespace.name}/#{project.path}" }
|
|
|
|
let(:changes) { URI.escape("#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch") }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-07-28 00:04:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns link to create new merge request' do
|
2017-03-17 08:35:39 -04:00
|
|
|
get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), secret_token: secret_token
|
|
|
|
|
2016-07-28 00:04:57 -04:00
|
|
|
expect(json_response).to match [{
|
|
|
|
"branch_name" => "new_branch",
|
2016-11-18 07:17:10 -05:00
|
|
|
"url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
|
2016-07-28 00:04:57 -04:00
|
|
|
"new_merge_request" => true
|
|
|
|
}]
|
|
|
|
end
|
2017-03-17 08:35:39 -04:00
|
|
|
|
|
|
|
it 'returns empty array if printing_merge_request_link_enabled is false' do
|
|
|
|
project.update!(printing_merge_request_link_enabled: false)
|
|
|
|
|
|
|
|
get api("/internal/merge_request_urls?project=#{repo_name}&changes=#{changes}"), secret_token: secret_token
|
|
|
|
|
|
|
|
expect(json_response).to eq([])
|
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
|
|
|
|
context 'with a gl_repository parameter' do
|
|
|
|
let(:gl_repository) { "project-#{project.id}" }
|
|
|
|
|
|
|
|
it 'returns link to create new merge request' do
|
|
|
|
get api("/internal/merge_request_urls?gl_repository=#{gl_repository}&changes=#{changes}"), secret_token: secret_token
|
|
|
|
|
|
|
|
expect(json_response).to match [{
|
|
|
|
"branch_name" => "new_branch",
|
|
|
|
"url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
|
|
|
|
"new_merge_request" => true
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
end
|
2016-07-28 00:04:57 -04:00
|
|
|
end
|
|
|
|
|
2017-05-18 15:33:43 -04:00
|
|
|
# TODO: Uncomment when the end-point is reenabled
|
|
|
|
# describe 'POST /notify_post_receive' do
|
|
|
|
# let(:valid_params) do
|
|
|
|
# { project: project.repository.path, secret_token: secret_token }
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# let(:valid_wiki_params) do
|
|
|
|
# { project: project.wiki.repository.path, secret_token: secret_token }
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# before do
|
|
|
|
# allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it "calls the Gitaly client with the project's repository" do
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:new).with(gitlab_git_repository_with(path: project.repository.path)).
|
|
|
|
# and_call_original
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect_any_instance_of(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:post_receive)
|
|
|
|
#
|
|
|
|
# post api("/internal/notify_post_receive"), valid_params
|
|
|
|
#
|
2017-10-19 14:28:19 -04:00
|
|
|
# expect(response).to have_gitlab_http_status(200)
|
2017-05-18 15:33:43 -04:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it "calls the Gitaly client with the wiki's repository if it's a wiki" do
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:new).with(gitlab_git_repository_with(path: project.wiki.repository.path)).
|
|
|
|
# and_call_original
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect_any_instance_of(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:post_receive)
|
|
|
|
#
|
|
|
|
# post api("/internal/notify_post_receive"), valid_wiki_params
|
|
|
|
#
|
2017-10-19 14:28:19 -04:00
|
|
|
# expect(response).to have_gitlab_http_status(200)
|
2017-05-18 15:33:43 -04:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it "returns 500 if the gitaly call fails" do
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect_any_instance_of(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:post_receive).and_raise(GRPC::Unavailable)
|
|
|
|
#
|
|
|
|
# post api("/internal/notify_post_receive"), valid_params
|
|
|
|
#
|
2017-10-19 14:28:19 -04:00
|
|
|
# expect(response).to have_gitlab_http_status(500)
|
2017-05-18 15:33:43 -04:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# context 'with a gl_repository parameter' do
|
|
|
|
# let(:valid_params) do
|
|
|
|
# { gl_repository: "project-#{project.id}", secret_token: secret_token }
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# let(:valid_wiki_params) do
|
|
|
|
# { gl_repository: "wiki-#{project.id}", secret_token: secret_token }
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it "calls the Gitaly client with the project's repository" do
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:new).with(gitlab_git_repository_with(path: project.repository.path)).
|
|
|
|
# and_call_original
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect_any_instance_of(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:post_receive)
|
|
|
|
#
|
|
|
|
# post api("/internal/notify_post_receive"), valid_params
|
|
|
|
#
|
2017-10-19 14:28:19 -04:00
|
|
|
# expect(response).to have_gitlab_http_status(200)
|
2017-05-18 15:33:43 -04:00
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it "calls the Gitaly client with the wiki's repository if it's a wiki" do
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:new).with(gitlab_git_repository_with(path: project.wiki.repository.path)).
|
|
|
|
# and_call_original
|
2017-07-18 03:59:36 -04:00
|
|
|
# expect_any_instance_of(Gitlab::GitalyClient::NotificationService).
|
2017-05-18 15:33:43 -04:00
|
|
|
# to receive(:post_receive)
|
|
|
|
#
|
|
|
|
# post api("/internal/notify_post_receive"), valid_wiki_params
|
|
|
|
#
|
2017-10-19 14:28:19 -04:00
|
|
|
# expect(response).to have_gitlab_http_status(200)
|
2017-05-18 15:33:43 -04:00
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
2017-02-05 13:04:23 -05:00
|
|
|
|
2017-12-08 12:42:43 -05:00
|
|
|
describe 'POST /internal/post_receive', :clean_gitlab_redis_shared_state do
|
2017-08-29 22:10:41 -04:00
|
|
|
let(:identifier) { 'key-123' }
|
|
|
|
|
|
|
|
let(:valid_params) do
|
|
|
|
{
|
|
|
|
gl_repository: gl_repository,
|
|
|
|
secret_token: secret_token,
|
|
|
|
identifier: identifier,
|
|
|
|
changes: changes
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:changes) do
|
|
|
|
"#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch"
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-12-08 12:42:43 -05:00
|
|
|
allow(described_class).to receive(:identify).and_return(user)
|
|
|
|
allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(user)
|
2017-08-29 22:10:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueues a PostReceive worker job' do
|
|
|
|
expect(PostReceive).to receive(:perform_async)
|
|
|
|
.with(gl_repository, identifier, changes)
|
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'decreases the reference counter and returns the result' do
|
|
|
|
expect(Gitlab::ReferenceCounter).to receive(:new).with(gl_repository)
|
|
|
|
.and_return(reference_counter)
|
|
|
|
expect(reference_counter).to receive(:decrease).and_return(true)
|
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(json_response['reference_counter_decreased']).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns link to create new merge request' do
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(json_response['merge_request_urls']).to match [{
|
|
|
|
"branch_name" => "new_branch",
|
|
|
|
"url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch",
|
|
|
|
"new_merge_request" => true
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty array if printing_merge_request_link_enabled is false' do
|
|
|
|
project.update!(printing_merge_request_link_enabled: false)
|
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(json_response['merge_request_urls']).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'broadcast message exists' do
|
|
|
|
let!(:broadcast_message) { create(:broadcast_message, starts_at: 1.day.ago, ends_at: 1.day.from_now ) }
|
|
|
|
|
|
|
|
it 'returns one broadcast message' do
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-29 22:10:41 -04:00
|
|
|
expect(json_response['broadcast_message']).to eq(broadcast_message.message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'broadcast message does not exist' do
|
|
|
|
it 'returns empty string' do
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-29 22:10:41 -04:00
|
|
|
expect(json_response['broadcast_message']).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'nil broadcast message' do
|
|
|
|
it 'returns empty string' do
|
|
|
|
allow(BroadcastMessage).to receive(:current).and_return(nil)
|
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-29 22:10:41 -04:00
|
|
|
expect(json_response['broadcast_message']).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2017-12-08 12:42:43 -05:00
|
|
|
|
|
|
|
context 'with a redirected data' do
|
|
|
|
it 'returns redirected message on the response' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_moved = Gitlab::Checks::ProjectMoved.new(project, user, 'http', 'foo/baz')
|
|
|
|
project_moved.add_message
|
2017-12-08 12:42:43 -05:00
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(json_response["redirected_message"]).to be_present
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(json_response["redirected_message"]).to eq(project_moved.message)
|
2017-12-08 12:42:43 -05:00
|
|
|
end
|
|
|
|
end
|
2017-12-24 12:03:58 -05:00
|
|
|
|
2018-01-22 13:10:56 -05:00
|
|
|
context 'with new project data' do
|
|
|
|
it 'returns new project message on the response' do
|
2018-01-26 09:28:08 -05:00
|
|
|
project_created = Gitlab::Checks::ProjectCreated.new(project, user, 'http')
|
|
|
|
project_created.add_message
|
2018-01-22 13:10:56 -05:00
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2018-01-25 07:26:52 -05:00
|
|
|
expect(json_response["project_created_message"]).to be_present
|
2018-01-26 09:28:08 -05:00
|
|
|
expect(json_response["project_created_message"]).to eq(project_created.message)
|
2018-01-22 13:10:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-24 12:03:58 -05:00
|
|
|
context 'with an orphaned write deploy key' do
|
|
|
|
it 'does not try to notify that project moved' do
|
|
|
|
allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(nil)
|
|
|
|
|
|
|
|
post api("/internal/post_receive"), valid_params
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
2017-08-29 22:10:41 -04:00
|
|
|
end
|
|
|
|
|
2017-08-31 17:01:07 -04:00
|
|
|
describe 'POST /internal/pre_receive' do
|
|
|
|
let(:valid_params) do
|
|
|
|
{ gl_repository: gl_repository, secret_token: secret_token }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'decreases the reference counter and returns the result' do
|
|
|
|
expect(Gitlab::ReferenceCounter).to receive(:new).with(gl_repository)
|
|
|
|
.and_return(reference_counter)
|
|
|
|
expect(reference_counter).to receive(:increase).and_return(true)
|
|
|
|
|
|
|
|
post api("/internal/pre_receive"), valid_params
|
|
|
|
|
|
|
|
expect(json_response['reference_counter_increased']).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-01 08:58:49 -05:00
|
|
|
def gl_repository_for(project_or_wiki)
|
|
|
|
case project_or_wiki
|
|
|
|
when ProjectWiki
|
|
|
|
project_or_wiki.project.gl_repository(is_wiki: true)
|
|
|
|
when Project
|
|
|
|
project_or_wiki.gl_repository(is_wiki: false)
|
|
|
|
else
|
|
|
|
nil
|
2016-11-15 10:02:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 20:16:24 -04:00
|
|
|
def pull(key, project, protocol = 'ssh')
|
2014-09-03 02:06:16 -04:00
|
|
|
post(
|
2013-03-07 07:18:30 -05:00
|
|
|
api("/internal/allowed"),
|
|
|
|
key_id: key.id,
|
2017-12-01 08:58:49 -05:00
|
|
|
project: project.full_path,
|
|
|
|
gl_repository: gl_repository_for(project),
|
2017-06-15 20:03:54 -04:00
|
|
|
action: 'git-upload-pack',
|
|
|
|
secret_token: secret_token,
|
|
|
|
protocol: protocol
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-04-05 03:29:30 -04:00
|
|
|
def push(key, project, protocol = 'ssh', env: nil)
|
2014-09-03 02:06:16 -04:00
|
|
|
post(
|
2013-03-07 07:18:30 -05:00
|
|
|
api("/internal/allowed"),
|
2014-09-02 04:35:34 -04:00
|
|
|
changes: 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master',
|
2013-03-07 07:18:30 -05:00
|
|
|
key_id: key.id,
|
2017-12-01 08:58:49 -05:00
|
|
|
project: project.full_path,
|
|
|
|
gl_repository: gl_repository_for(project),
|
2017-06-15 20:03:54 -04:00
|
|
|
action: 'git-receive-pack',
|
|
|
|
secret_token: secret_token,
|
|
|
|
protocol: protocol,
|
|
|
|
env: env
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2013-07-29 08:25:33 -04:00
|
|
|
def archive(key, project)
|
2014-09-03 02:06:16 -04:00
|
|
|
post(
|
2013-07-29 08:25:33 -04:00
|
|
|
api("/internal/allowed"),
|
|
|
|
ref: 'master',
|
|
|
|
key_id: key.id,
|
2017-12-01 08:58:49 -05:00
|
|
|
project: project.full_path,
|
|
|
|
gl_repository: gl_repository_for(project),
|
2014-10-15 11:26:15 -04:00
|
|
|
action: 'git-upload-archive',
|
2016-06-22 20:16:24 -04:00
|
|
|
secret_token: secret_token,
|
|
|
|
protocol: 'ssh'
|
2013-07-29 08:25:33 -04:00
|
|
|
)
|
|
|
|
end
|
2016-09-19 10:34:32 -04:00
|
|
|
|
|
|
|
def lfs_auth(key_id, project)
|
|
|
|
post(
|
|
|
|
api("/internal/lfs_authenticate"),
|
|
|
|
key_id: key_id,
|
|
|
|
secret_token: secret_token,
|
2017-12-01 08:58:49 -05:00
|
|
|
project: project.full_path
|
2016-09-19 10:34:32 -04:00
|
|
|
)
|
|
|
|
end
|
2013-02-26 15:53:59 -05:00
|
|
|
end
|