2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe API::CommitStatuses do
|
2021-05-19 05:10:19 -04:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:commit) { project.repository.commit }
|
|
|
|
let_it_be(:guest) { create_user(:guest) }
|
|
|
|
let_it_be(:reporter) { create_user(:reporter) }
|
|
|
|
let_it_be(:developer) { create_user(:developer) }
|
|
|
|
let_it_be(:sha) { commit.id }
|
2016-03-01 06:33:25 -05:00
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
describe "GET /projects/:id/repository/commits/:sha/statuses" do
|
2016-03-01 06:33:25 -05:00
|
|
|
let(:get_url) { "/projects/#{project.id}/repository/commits/#{sha}/statuses" }
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-02-29 07:54:33 -05:00
|
|
|
context 'ci commit exists' do
|
2021-12-03 10:10:36 -05:00
|
|
|
let!(:master) do
|
|
|
|
project.ci_pipelines.build(source: :push, sha: commit.id, ref: 'master', protected: false).tap do |p|
|
|
|
|
p.ensure_project_iid! # Necessary to avoid cross-database modification error
|
|
|
|
p.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:develop) do
|
|
|
|
project.ci_pipelines.build(source: :push, sha: commit.id, ref: 'develop', protected: false).tap do |p|
|
|
|
|
p.ensure_project_iid! # Necessary to avoid cross-database modification error
|
|
|
|
p.save!
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-02-29 07:54:33 -05:00
|
|
|
context "reporter user" do
|
|
|
|
let(:statuses_id) { json_response.map { |status| status['id'] } }
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-04-11 10:55:40 -04:00
|
|
|
def create_status(commit, opts = {})
|
2016-06-03 06:29:00 -04:00
|
|
|
create(:commit_status, { pipeline: commit, ref: commit.ref }.merge(opts))
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
|
|
|
|
2017-04-16 07:14:39 -04:00
|
|
|
let!(:status1) { create_status(master, status: 'running', retried: true) }
|
|
|
|
let!(:status2) { create_status(master, name: 'coverage', status: 'pending', retried: true) }
|
2016-04-11 10:55:40 -04:00
|
|
|
let!(:status3) { create_status(develop, status: 'running', allow_failure: true) }
|
|
|
|
let!(:status4) { create_status(master, name: 'coverage', status: 'success') }
|
|
|
|
let!(:status5) { create_status(develop, name: 'coverage', status: 'success') }
|
|
|
|
let!(:status6) { create_status(master, status: 'success') }
|
2016-02-29 07:54:33 -05:00
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
context 'latest commit statuses' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api(get_url, reporter)
|
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
|
|
|
it 'returns latest commit statuses' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-02-29 07:54:33 -05:00
|
|
|
|
2017-02-20 09:39:16 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-02-29 08:20:11 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(statuses_id).to contain_exactly(status3.id, status4.id, status5.id, status6.id)
|
2017-08-09 05:52:22 -04:00
|
|
|
json_response.sort_by! { |status| status['id'] }
|
|
|
|
expect(json_response.map { |status| status['allow_failure'] }).to eq([true, false, false, false])
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
context 'all commit statuses' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get api(get_url, reporter), params: { all: 1 }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
|
|
|
it 'returns all commit statuses' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-02-29 08:20:11 -05:00
|
|
|
expect(json_response).to be_an Array
|
2016-03-01 06:33:25 -05:00
|
|
|
expect(statuses_id).to contain_exactly(status1.id, status2.id,
|
|
|
|
status3.id, status4.id,
|
|
|
|
status5.id, status6.id)
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
context 'latest commit statuses for specific ref' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get api(get_url, reporter), params: { ref: 'develop' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
it 'returns latest commit statuses for specific ref' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-02-29 08:20:11 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(statuses_id).to contain_exactly(status3.id, status5.id)
|
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
context 'latest commit statues for specific name' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get api(get_url, reporter), params: { name: 'coverage' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
|
|
|
it 'return latest commit statuses for specific name' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-02-29 08:20:11 -05:00
|
|
|
expect(json_response).to be_an Array
|
2016-03-01 06:33:25 -05:00
|
|
|
expect(statuses_id).to contain_exactly(status4.id, status5.id)
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2016-02-29 07:54:33 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-02-29 07:54:33 -05:00
|
|
|
context 'ci commit does not exist' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api(get_url, reporter)
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-02-29 07:54:33 -05:00
|
|
|
it 'returns empty array' do
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2015-10-06 06:01:16 -04:00
|
|
|
expect(json_response).to be_an Array
|
2016-02-29 07:54:33 -05:00
|
|
|
expect(json_response).to be_empty
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "guest user" do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api(get_url, guest)
|
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "does not return project commits" do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "unauthorized user" do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
get api(get_url)
|
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "does not return project commits" do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-12 06:15:35 -04:00
|
|
|
describe 'POST /projects/:id/statuses/:sha' do
|
2016-03-01 06:33:25 -05:00
|
|
|
let(:post_url) { "/projects/#{project.id}/statuses/#{sha}" }
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-02-06 09:01:37 -05:00
|
|
|
context 'developer user' do
|
2019-10-18 07:11:44 -04:00
|
|
|
context 'uses only required parameters' do
|
|
|
|
%w[pending running success failed canceled].each do |status|
|
|
|
|
context "for #{status}" do
|
|
|
|
context 'when pipeline for sha does not exists' do
|
2021-12-02 07:10:10 -05:00
|
|
|
it 'creates commit status and sets pipeline iid' do
|
2019-10-18 07:11:44 -04:00
|
|
|
post api(post_url, developer), params: { state: status }
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2019-10-18 07:11:44 -04:00
|
|
|
expect(json_response['sha']).to eq(commit.id)
|
|
|
|
expect(json_response['status']).to eq(status)
|
|
|
|
expect(json_response['name']).to eq('default')
|
|
|
|
expect(json_response['ref']).not_to be_empty
|
|
|
|
expect(json_response['target_url']).to be_nil
|
|
|
|
expect(json_response['description']).to be_nil
|
|
|
|
|
|
|
|
if status == 'failed'
|
|
|
|
expect(CommitStatus.find(json_response['id'])).to be_api_failure
|
|
|
|
end
|
2021-12-02 07:10:10 -05:00
|
|
|
|
|
|
|
expect(::Ci::Pipeline.last.iid).not_to be_nil
|
2019-10-18 07:11:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline already exists for the specified sha' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, sha: sha, ref: 'ref') }
|
|
|
|
let(:params) { { state: 'pending' } }
|
|
|
|
|
|
|
|
shared_examples_for 'creates a commit status for the existing pipeline' do
|
|
|
|
it do
|
|
|
|
expect do
|
|
|
|
post api(post_url, developer), params: params
|
|
|
|
end.not_to change { Ci::Pipeline.count }
|
|
|
|
|
|
|
|
job = pipeline.statuses.find_by_name(json_response['name'])
|
2016-08-25 11:52:09 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2019-10-18 07:11:44 -04:00
|
|
|
expect(job.status).to eq('pending')
|
2020-01-30 16:08:47 -05:00
|
|
|
expect(job.stage_idx).to eq(GenericCommitStatus::EXTERNAL_STAGE_IDX)
|
2016-08-25 11:52:09 -04:00
|
|
|
end
|
|
|
|
end
|
2019-10-18 07:11:44 -04:00
|
|
|
|
|
|
|
it_behaves_like 'creates a commit status for the existing pipeline'
|
|
|
|
|
|
|
|
context 'with pipeline for merge request' do
|
|
|
|
let!(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline, source_project: project) }
|
|
|
|
let!(:pipeline) { merge_request.all_pipelines.last }
|
|
|
|
let(:sha) { pipeline.sha }
|
|
|
|
|
|
|
|
it_behaves_like 'creates a commit status for the existing pipeline'
|
|
|
|
end
|
2016-08-25 11:52:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'transitions status from pending' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: { state: 'pending' }
|
2016-08-25 11:52:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
%w[running success failed canceled].each do |status|
|
|
|
|
it "to #{status}" do
|
2018-12-17 17:52:17 -05:00
|
|
|
expect { post api(post_url, developer), params: { state: status } }.not_to change { CommitStatus.count }
|
2016-08-25 11:52:09 -04:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2016-08-25 11:52:09 -04:00
|
|
|
expect(json_response['status']).to eq(status)
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with all optional parameters' do
|
2017-03-01 07:59:15 -05:00
|
|
|
context 'when creating a commit status' do
|
2017-06-27 08:08:40 -04:00
|
|
|
subject do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: {
|
2017-03-01 07:59:15 -05:00
|
|
|
state: 'success',
|
|
|
|
context: 'coverage',
|
2017-06-27 08:08:40 -04:00
|
|
|
ref: 'master',
|
2017-03-01 07:59:15 -05:00
|
|
|
description: 'test',
|
|
|
|
coverage: 80.0,
|
2017-03-01 09:11:10 -05:00
|
|
|
target_url: 'http://gitlab.com/status'
|
|
|
|
}
|
2017-06-27 08:08:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates commit status' do
|
|
|
|
subject
|
2017-03-01 07:59:15 -05:00
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2017-03-01 07:59:15 -05:00
|
|
|
expect(json_response['sha']).to eq(commit.id)
|
|
|
|
expect(json_response['status']).to eq('success')
|
|
|
|
expect(json_response['name']).to eq('coverage')
|
2017-06-27 08:08:40 -04:00
|
|
|
expect(json_response['ref']).to eq('master')
|
2017-03-01 07:59:15 -05:00
|
|
|
expect(json_response['coverage']).to eq(80.0)
|
|
|
|
expect(json_response['description']).to eq('test')
|
|
|
|
expect(json_response['target_url']).to eq('http://gitlab.com/status')
|
|
|
|
end
|
2017-06-27 08:08:40 -04:00
|
|
|
|
|
|
|
context 'when merge request exists for given branch' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'develop') }
|
|
|
|
|
|
|
|
it 'sets head pipeline' do
|
|
|
|
subject
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2017-06-27 08:08:40 -04:00
|
|
|
expect(merge_request.reload.head_pipeline).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2021-05-19 05:10:19 -04:00
|
|
|
context 'when updating a commit status' do
|
|
|
|
let(:parameters) do
|
|
|
|
{
|
|
|
|
state: 'success',
|
|
|
|
name: 'coverage',
|
|
|
|
ref: 'master'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:updatable_optional_attributes) do
|
|
|
|
{
|
|
|
|
description: 'new description',
|
|
|
|
coverage: 90.0
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# creating the initial commit status
|
2017-03-01 07:59:15 -05:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: {
|
2017-03-01 07:59:15 -05:00
|
|
|
state: 'running',
|
|
|
|
context: 'coverage',
|
2017-06-27 08:08:40 -04:00
|
|
|
ref: 'master',
|
2017-03-01 07:59:15 -05:00
|
|
|
description: 'coverage test',
|
2021-05-19 05:10:19 -04:00
|
|
|
coverage: 10.0,
|
2017-03-01 09:11:10 -05:00
|
|
|
target_url: 'http://gitlab.com/status'
|
|
|
|
}
|
2021-05-19 05:10:19 -04:00
|
|
|
end
|
2017-03-01 07:59:15 -05:00
|
|
|
|
2021-05-19 05:10:19 -04:00
|
|
|
subject(:send_request) do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: {
|
2021-05-19 05:10:19 -04:00
|
|
|
**parameters,
|
|
|
|
**updatable_optional_attributes
|
2017-03-01 09:11:10 -05:00
|
|
|
}
|
2017-03-01 07:59:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates a commit status' do
|
2021-05-19 05:10:19 -04:00
|
|
|
send_request
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2017-03-01 07:59:15 -05:00
|
|
|
expect(json_response['sha']).to eq(commit.id)
|
|
|
|
expect(json_response['status']).to eq('success')
|
|
|
|
expect(json_response['name']).to eq('coverage')
|
2017-06-27 08:08:40 -04:00
|
|
|
expect(json_response['ref']).to eq('master')
|
2017-03-01 07:59:15 -05:00
|
|
|
expect(json_response['coverage']).to eq(90.0)
|
|
|
|
expect(json_response['description']).to eq('new description')
|
|
|
|
expect(json_response['target_url']).to eq('http://gitlab.com/status')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a new commit status' do
|
2021-05-19 05:10:19 -04:00
|
|
|
expect { send_request }.not_to change { CommitStatus.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the `state` parameter is sent the same' do
|
|
|
|
let(:parameters) do
|
|
|
|
{
|
|
|
|
state: 'running',
|
|
|
|
name: 'coverage',
|
|
|
|
ref: 'master'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update the commit status' do
|
|
|
|
send_request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
|
|
|
|
commit_status = project.commit_statuses.find_by!(name: 'coverage')
|
|
|
|
|
|
|
|
expect(commit_status.description).to eq('coverage test')
|
|
|
|
expect(commit_status.coverage).to eq(10.0)
|
|
|
|
end
|
2017-03-01 07:59:15 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2019-07-16 19:36:49 -04:00
|
|
|
|
|
|
|
context 'when a pipeline id is specified' do
|
2021-12-03 10:10:36 -05:00
|
|
|
let!(:first_pipeline) do
|
|
|
|
project.ci_pipelines.build(source: :push, sha: commit.id, ref: 'master', status: 'created').tap do |p|
|
|
|
|
p.ensure_project_iid! # Necessary to avoid cross-database modification error
|
|
|
|
p.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:other_pipeline) do
|
|
|
|
project.ci_pipelines.build(source: :push, sha: commit.id, ref: 'master', status: 'created').tap do |p|
|
|
|
|
p.ensure_project_iid! # Necessary to avoid cross-database modification error
|
|
|
|
p.save!
|
|
|
|
end
|
|
|
|
end
|
2019-07-16 19:36:49 -04:00
|
|
|
|
|
|
|
subject do
|
|
|
|
post api(post_url, developer), params: {
|
|
|
|
pipeline_id: other_pipeline.id,
|
|
|
|
state: 'success',
|
|
|
|
ref: 'master'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'update the correct pipeline', :sidekiq_might_not_need_inline do
|
2019-07-16 19:36:49 -04:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(first_pipeline.reload.status).to eq('created')
|
|
|
|
expect(other_pipeline.reload.status).to eq('success')
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2017-07-05 03:36:08 -04:00
|
|
|
context 'when retrying a commit status' do
|
2021-03-09 07:08:52 -05:00
|
|
|
subject(:post_request) do
|
2017-07-05 03:36:08 -04:00
|
|
|
post api(post_url, developer),
|
2018-12-17 17:52:17 -05:00
|
|
|
params: { state: 'failed', name: 'test', ref: 'master' }
|
2017-07-05 03:36:08 -04:00
|
|
|
|
|
|
|
post api(post_url, developer),
|
2018-12-17 17:52:17 -05:00
|
|
|
params: { state: 'success', name: 'test', ref: 'master' }
|
2017-07-05 03:36:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly posts a new commit status' do
|
2021-03-09 07:08:52 -05:00
|
|
|
post_request
|
|
|
|
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2017-07-05 03:36:08 -04:00
|
|
|
expect(json_response['sha']).to eq(commit.id)
|
|
|
|
expect(json_response['status']).to eq('success')
|
|
|
|
end
|
|
|
|
|
2021-09-06 08:11:14 -04:00
|
|
|
it 'retries the commit status', :sidekiq_might_not_need_inline do
|
|
|
|
post_request
|
2021-03-09 07:08:52 -05:00
|
|
|
|
2021-09-06 08:11:14 -04:00
|
|
|
expect(CommitStatus.count).to eq 2
|
|
|
|
expect(CommitStatus.first).to be_retried
|
|
|
|
expect(CommitStatus.last.pipeline).to be_success
|
2017-07-05 03:36:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-18 06:24:53 -05:00
|
|
|
context 'when status is invalid' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: { state: 'invalid' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
|
|
|
|
2017-01-18 06:24:53 -05:00
|
|
|
context 'when request without a state made' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
post api(post_url, developer)
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2016-02-29 08:20:11 -05:00
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
|
2020-01-30 16:08:47 -05:00
|
|
|
context 'when updating a protected ref' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'master')
|
|
|
|
post api(post_url, user), params: { state: 'running', ref: 'master' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with user as developer' do
|
|
|
|
let(:user) { developer }
|
|
|
|
|
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2020-01-30 16:08:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with user as maintainer' do
|
|
|
|
let(:user) { create_user(:maintainer) }
|
|
|
|
|
|
|
|
it 'creates commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:created)
|
2020-01-30 16:08:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-18 06:24:53 -05:00
|
|
|
context 'when commit SHA is invalid' do
|
2016-03-01 06:33:25 -05:00
|
|
|
let(:sha) { 'invalid_sha' }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: { state: 'running' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
|
|
|
it 'returns not found error' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-18 06:24:53 -05:00
|
|
|
|
|
|
|
context 'when target URL is an invalid address' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, developer), params: {
|
|
|
|
state: 'pending',
|
|
|
|
target_url: 'invalid url'
|
|
|
|
}
|
2017-01-18 06:24:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with bad request status and validation errors' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2017-01-18 06:24:53 -05:00
|
|
|
expect(json_response['message']['target_url'])
|
2019-04-11 02:29:07 -04:00
|
|
|
.to include 'is blocked: Only allowed schemes are http, https'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when target URL is an unsupported scheme' do
|
|
|
|
before do
|
|
|
|
post api(post_url, developer), params: {
|
|
|
|
state: 'pending',
|
|
|
|
target_url: 'git://example.com'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with bad request status and validation errors' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-04-11 02:29:07 -04:00
|
|
|
expect(json_response['message']['target_url'])
|
|
|
|
.to include 'is blocked: Only allowed schemes are http, https'
|
2017-01-18 06:24:53 -05:00
|
|
|
end
|
|
|
|
end
|
2020-01-30 16:08:47 -05:00
|
|
|
|
|
|
|
context 'when trying to update a status of a different type' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, sha: sha, ref: 'ref') }
|
|
|
|
let!(:ci_build) { create(:ci_build, pipeline: pipeline, name: 'test-job') }
|
|
|
|
let(:params) { { state: 'pending', name: 'test-job' } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
post api(post_url, developer), params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with bad request status and validation errors' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2020-01-30 16:08:47 -05:00
|
|
|
expect(json_response['message']['name'])
|
|
|
|
.to include 'has already been taken'
|
|
|
|
end
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
|
2016-02-06 09:01:37 -05:00
|
|
|
context 'reporter user' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, reporter), params: { state: 'running' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2016-02-06 09:01:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-06 06:01:16 -04:00
|
|
|
context 'guest user' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
post api(post_url, guest), params: { state: 'running' }
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
post api(post_url)
|
|
|
|
end
|
2016-02-29 08:20:11 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not create commit status' do
|
2020-02-21 07:09:07 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-06 09:01:37 -05:00
|
|
|
|
2016-03-06 16:53:22 -05:00
|
|
|
def create_user(access_level_trait)
|
2016-02-06 09:01:37 -05:00
|
|
|
user = create(:user)
|
2016-03-06 16:53:22 -05:00
|
|
|
create(:project_member, access_level_trait, user: user, project: project)
|
2016-02-06 09:01:37 -05:00
|
|
|
user
|
|
|
|
end
|
2015-10-06 06:01:16 -04:00
|
|
|
end
|