Skip to content
Snippets Groups Projects
Commit 17ab40ca authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 66d42037
No related branches found
No related tags found
No related merge requests found
Showing
with 514 additions and 221 deletions
Loading
@@ -212,7 +212,7 @@ describe Gitlab::Profiler do
Loading
@@ -212,7 +212,7 @@ describe Gitlab::Profiler do
stub_const('STDOUT', stdout) stub_const('STDOUT', stdout)
end end
   
it 'prints a profile result sorted by total time' do it 'prints a profile result sorted by total time', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/206907' do
described_class.print_by_total_time(result) described_class.print_by_total_time(result)
   
total_times = total_times =
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe Gitlab::ReactiveCacheSetCache, :clean_gitlab_redis_cache do
Loading
@@ -12,7 +12,7 @@ describe Gitlab::ReactiveCacheSetCache, :clean_gitlab_redis_cache do
subject { cache.cache_key(cache_prefix) } subject { cache.cache_key(cache_prefix) }
   
it 'includes the suffix' do it 'includes the suffix' do
expect(subject).to eq "#{cache_prefix}:set" expect(subject).to eq "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:#{cache_prefix}:set"
end end
end end
   
Loading
Loading
Loading
@@ -129,6 +129,17 @@ describe Gitlab::TreeSummary do
Loading
@@ -129,6 +129,17 @@ describe Gitlab::TreeSummary do
expect(commits).to satisfy_one { |c| c.id == whitespace_commit_sha } expect(commits).to satisfy_one { |c| c.id == whitespace_commit_sha }
end end
end end
context 'in a subdirectory with non-ASCII filenames' do
let(:path) { 'encoding' }
it 'returns commits for entries in the subdirectory' do
entry = entries.find { |x| x[:file_name] == 'テスト.txt' }
expect(entry).to be_a(Hash)
expect(entry).to include(:commit)
end
end
end end
   
describe '#more?' do describe '#more?' do
Loading
Loading
Loading
@@ -145,4 +145,28 @@ describe Ci::Processable do
Loading
@@ -145,4 +145,28 @@ describe Ci::Processable do
expect(another_build.reload.scheduling_type).to be_nil expect(another_build.reload.scheduling_type).to be_nil
end end
end end
describe '#needs_attributes' do
let(:build) { create(:ci_build, :created, project: project, pipeline: pipeline) }
context 'with needs' do
before do
create(:ci_build_need, build: build, name: 'test1')
create(:ci_build_need, build: build, name: 'test2')
end
it 'returns all needs attributes' do
expect(build.needs_attributes).to contain_exactly(
{ 'artifacts' => true, 'name' => 'test1' },
{ 'artifacts' => true, 'name' => 'test2' }
)
end
end
context 'without needs' do
it 'returns all needs attributes' do
expect(build.needs_attributes).to be_empty
end
end
end
end end
Loading
@@ -112,6 +112,43 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
Loading
@@ -112,6 +112,43 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end end
end end
   
describe '#with_reactive_cache_set', :use_clean_rails_redis_caching do
subject(:go!) do
instance.with_reactive_cache_set('resource', {}) do |data|
data
end
end
it 'calls with_reactive_cache' do
expect(instance)
.to receive(:with_reactive_cache)
go!
end
context 'data returned' do
let(:resource) { 'resource' }
let(:set_key) { "#{cache_key}:#{resource}" }
let(:set_cache) { Gitlab::ReactiveCacheSetCache.new }
before do
stub_reactive_cache(instance, true, resource, {})
end
it 'saves keys in set' do
expect(set_cache.read(set_key)).to be_empty
go!
expect(set_cache.read(set_key)).not_to be_empty
end
it 'returns the data' do
expect(go!).to eq(true)
end
end
end
describe '.reactive_cache_worker_finder' do describe '.reactive_cache_worker_finder' do
context 'with default reactive_cache_worker_finder' do context 'with default reactive_cache_worker_finder' do
let(:args) { %w(other args) } let(:args) { %w(other args) }
Loading
Loading
Loading
@@ -8,7 +8,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
Loading
@@ -8,7 +8,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
   
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
   
subject { create(:project_error_tracking_setting, project: project) } subject(:setting) { create(:project_error_tracking_setting, project: project) }
   
describe 'Associations' do describe 'Associations' do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
Loading
@@ -453,4 +453,23 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
Loading
@@ -453,4 +453,23 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end end
end end
end end
describe '#expire_issues_cache', :use_clean_rails_redis_caching do
let(:issues) { [:some, :issues] }
let(:opt) { 'list_issues' }
let(:params) { { issue_status: 'unresolved', limit: 20, sort: 'last_seen' } }
before do
start_reactive_cache_lifetime(subject, opt, params.stringify_keys)
stub_reactive_cache(subject, issues, opt, params.stringify_keys)
end
it 'clears the cache' do
expect(subject.list_sentry_issues(params)).to eq(issues)
subject.expire_issues_cache
expect(subject.list_sentry_issues(params)).to eq(nil)
end
end
end end
Loading
@@ -16,7 +16,7 @@ describe API::Markdown do
Loading
@@ -16,7 +16,7 @@ describe API::Markdown do
   
shared_examples "rendered markdown text without GFM" do shared_examples "rendered markdown text without GFM" do
it "renders markdown text" do it "renders markdown text" do
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response.headers["Content-Type"]).to eq("application/json") expect(response.headers["Content-Type"]).to eq("application/json")
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
expect(json_response["html"]).to eq("<p>#{text}</p>") expect(json_response["html"]).to eq("<p>#{text}</p>")
Loading
@@ -25,7 +25,7 @@ describe API::Markdown do
Loading
@@ -25,7 +25,7 @@ describe API::Markdown do
   
shared_examples "404 Project Not Found" do shared_examples "404 Project Not Found" do
it "responses with 404 Not Found" do it "responses with 404 Not Found" do
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(response.headers["Content-Type"]).to eq("application/json") expect(response.headers["Content-Type"]).to eq("application/json")
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
expect(json_response["message"]).to eq("404 Project Not Found") expect(json_response["message"]).to eq("404 Project Not Found")
Loading
@@ -37,7 +37,7 @@ describe API::Markdown do
Loading
@@ -37,7 +37,7 @@ describe API::Markdown do
let(:params) { {} } let(:params) { {} }
   
it "responses with 400 Bad Request" do it "responses with 400 Bad Request" do
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(response.headers["Content-Type"]).to eq("application/json") expect(response.headers["Content-Type"]).to eq("application/json")
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
expect(json_response["error"]).to eq("text is missing") expect(json_response["error"]).to eq("text is missing")
Loading
@@ -83,7 +83,7 @@ describe API::Markdown do
Loading
@@ -83,7 +83,7 @@ describe API::Markdown do
let(:params) { { text: text, gfm: true } } let(:params) { { text: text, gfm: true } }
   
it "renders markdown text" do it "renders markdown text" do
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response.headers["Content-Type"]).to eq("application/json") expect(response.headers["Content-Type"]).to eq("application/json")
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
expect(json_response["html"]).to include("Hello world!") expect(json_response["html"]).to include("Hello world!")
Loading
@@ -100,7 +100,7 @@ describe API::Markdown do
Loading
@@ -100,7 +100,7 @@ describe API::Markdown do
let(:user) { project.owner } let(:user) { project.owner }
   
it "renders markdown text" do it "renders markdown text" do
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response.headers["Content-Type"]).to eq("application/json") expect(response.headers["Content-Type"]).to eq("application/json")
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
expect(json_response["html"]).to include("Hello world!") expect(json_response["html"]).to include("Hello world!")
Loading
@@ -120,7 +120,7 @@ describe API::Markdown do
Loading
@@ -120,7 +120,7 @@ describe API::Markdown do
   
shared_examples 'user without proper access' do shared_examples 'user without proper access' do
it 'does not render the title or link' do it 'does not render the title or link' do
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response["html"]).not_to include('Confidential title') expect(json_response["html"]).not_to include('Confidential title')
expect(json_response["html"]).not_to include('<a href=') expect(json_response["html"]).not_to include('<a href=')
expect(json_response["html"]).to include('Hello world!') expect(json_response["html"]).to include('Hello world!')
Loading
@@ -146,7 +146,7 @@ describe API::Markdown do
Loading
@@ -146,7 +146,7 @@ describe API::Markdown do
let(:user) { confidential_issue.author } let(:user) { confidential_issue.author }
   
it 'renders the title or link' do it 'renders the title or link' do
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response["html"]).to include('Confidential title') expect(json_response["html"]).to include('Confidential title')
expect(json_response["html"]).to include('Hello world!') expect(json_response["html"]).to include('Hello world!')
.and include('data-name="tada"') .and include('data-name="tada"')
Loading
Loading
Loading
@@ -43,7 +43,7 @@ describe API::Members do
Loading
@@ -43,7 +43,7 @@ describe API::Members do
   
get api(members_url, user) get api(members_url, user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
Loading
@@ -72,7 +72,7 @@ describe API::Members do
Loading
@@ -72,7 +72,7 @@ describe API::Members do
   
get api(members_url, developer) get api(members_url, developer)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
Loading
@@ -82,7 +82,7 @@ describe API::Members do
Loading
@@ -82,7 +82,7 @@ describe API::Members do
it 'finds members with query string' do it 'finds members with query string' do
get api(members_url, developer), params: { query: maintainer.username } get api(members_url, developer), params: { query: maintainer.username }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
Loading
@@ -92,7 +92,7 @@ describe API::Members do
Loading
@@ -92,7 +92,7 @@ describe API::Members do
it 'finds members with the given user_ids' do it 'finds members with the given user_ids' do
get api(members_url, developer), params: { user_ids: [maintainer.id, developer.id, stranger.id] } get api(members_url, developer), params: { user_ids: [maintainer.id, developer.id, stranger.id] }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |u| u['id'] }).to contain_exactly(maintainer.id, developer.id) expect(json_response.map { |u| u['id'] }).to contain_exactly(maintainer.id, developer.id)
Loading
@@ -101,7 +101,7 @@ describe API::Members do
Loading
@@ -101,7 +101,7 @@ describe API::Members do
it 'finds all members with no query specified' do it 'finds all members with no query specified' do
get api(members_url, developer), params: { query: '' } get api(members_url, developer), params: { query: '' }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.count).to eq(2) expect(json_response.count).to eq(2)
Loading
@@ -137,7 +137,7 @@ describe API::Members do
Loading
@@ -137,7 +137,7 @@ describe API::Members do
it 'finds all project members including inherited members' do it 'finds all project members including inherited members' do
get api("/projects/#{project.id}/members/all", developer) get api("/projects/#{project.id}/members/all", developer)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id, project_user.id, linked_group_user.id] expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id, project_user.id, linked_group_user.id]
Loading
@@ -148,7 +148,7 @@ describe API::Members do
Loading
@@ -148,7 +148,7 @@ describe API::Members do
   
get api("/projects/#{project.id}/members/all", developer) get api("/projects/#{project.id}/members/all", developer)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
   
Loading
@@ -165,7 +165,7 @@ describe API::Members do
Loading
@@ -165,7 +165,7 @@ describe API::Members do
it 'finds all group members including inherited members' do it 'finds all group members including inherited members' do
get api("/groups/#{nested_group.id}/members/all", developer) get api("/groups/#{nested_group.id}/members/all", developer)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id] expect(json_response.map { |u| u['id'] }).to match_array [maintainer.id, developer.id, nested_user.id]
Loading
@@ -185,7 +185,7 @@ describe API::Members do
Loading
@@ -185,7 +185,7 @@ describe API::Members do
user = public_send(type) user = public_send(type)
get api("/#{source_type.pluralize}/#{source.id}/members/#{all ? 'all/' : ''}#{developer.id}", user) get api("/#{source_type.pluralize}/#{source.id}/members/#{all ? 'all/' : ''}#{developer.id}", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
# User attributes # User attributes
expect(json_response['id']).to eq(developer.id) expect(json_response['id']).to eq(developer.id)
expect(json_response['name']).to eq(developer.name) expect(json_response['name']).to eq(developer.name)
Loading
@@ -220,7 +220,7 @@ describe API::Members do
Loading
@@ -220,7 +220,7 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", user), post api("/#{source_type.pluralize}/#{source.id}/members", user),
params: { user_id: access_requester.id, access_level: Member::MAINTAINER } params: { user_id: access_requester.id, access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
Loading
@@ -233,7 +233,7 @@ describe API::Members do
Loading
@@ -233,7 +233,7 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: access_requester.id, access_level: Member::MAINTAINER } params: { user_id: access_requester.id, access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end.to change { source.members.count }.by(1) end.to change { source.members.count }.by(1)
expect(source.requesters.count).to eq(0) expect(source.requesters.count).to eq(0)
expect(json_response['id']).to eq(access_requester.id) expect(json_response['id']).to eq(access_requester.id)
Loading
@@ -246,7 +246,7 @@ describe API::Members do
Loading
@@ -246,7 +246,7 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: stranger.id, access_level: Member::DEVELOPER, expires_at: '2016-08-05' } params: { user_id: stranger.id, access_level: Member::DEVELOPER, expires_at: '2016-08-05' }
   
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end.to change { source.members.count }.by(1) end.to change { source.members.count }.by(1)
expect(json_response['id']).to eq(stranger.id) expect(json_response['id']).to eq(stranger.id)
expect(json_response['access_level']).to eq(Member::DEVELOPER) expect(json_response['access_level']).to eq(Member::DEVELOPER)
Loading
@@ -265,7 +265,7 @@ describe API::Members do
Loading
@@ -265,7 +265,7 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: stranger.id, access_level: Member::REPORTER } params: { user_id: stranger.id, access_level: Member::REPORTER }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['access_level']).to eq(["should be greater than or equal to Developer inherited membership from group #{parent.name}"]) expect(json_response['message']['access_level']).to eq(["should be greater than or equal to Developer inherited membership from group #{parent.name}"])
end end
   
Loading
@@ -279,7 +279,7 @@ describe API::Members do
Loading
@@ -279,7 +279,7 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: stranger.id, access_level: Member::MAINTAINER } params: { user_id: stranger.id, access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['id']).to eq(stranger.id) expect(json_response['id']).to eq(stranger.id)
expect(json_response['access_level']).to eq(Member::MAINTAINER) expect(json_response['access_level']).to eq(Member::MAINTAINER)
end end
Loading
@@ -289,14 +289,14 @@ describe API::Members do
Loading
@@ -289,14 +289,14 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: maintainer.id, access_level: Member::MAINTAINER } params: { user_id: maintainer.id, access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
end end
   
it 'returns 404 when the user_id is not valid' do it 'returns 404 when the user_id is not valid' do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: 0, access_level: Member::MAINTAINER } params: { user_id: 0, access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
   
Loading
@@ -304,21 +304,21 @@ describe API::Members do
Loading
@@ -304,21 +304,21 @@ describe API::Members do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { access_level: Member::MAINTAINER } params: { access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
   
it 'returns 400 when access_level is not given' do it 'returns 400 when access_level is not given' do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: stranger.id } params: { user_id: stranger.id }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
   
it 'returns 400 when access_level is not valid' do it 'returns 400 when access_level is not valid' do
post api("/#{source_type.pluralize}/#{source.id}/members", maintainer), post api("/#{source_type.pluralize}/#{source.id}/members", maintainer),
params: { user_id: stranger.id, access_level: 1234 } params: { user_id: stranger.id, access_level: 1234 }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
end end
Loading
@@ -340,7 +340,7 @@ describe API::Members do
Loading
@@ -340,7 +340,7 @@ describe API::Members do
put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user), put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user),
params: { access_level: Member::MAINTAINER } params: { access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
Loading
@@ -351,7 +351,7 @@ describe API::Members do
Loading
@@ -351,7 +351,7 @@ describe API::Members do
put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer),
params: { access_level: Member::MAINTAINER, expires_at: '2016-08-05' } params: { access_level: Member::MAINTAINER, expires_at: '2016-08-05' }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq(developer.id) expect(json_response['id']).to eq(developer.id)
expect(json_response['access_level']).to eq(Member::MAINTAINER) expect(json_response['access_level']).to eq(Member::MAINTAINER)
expect(json_response['expires_at']).to eq('2016-08-05') expect(json_response['expires_at']).to eq('2016-08-05')
Loading
@@ -362,20 +362,20 @@ describe API::Members do
Loading
@@ -362,20 +362,20 @@ describe API::Members do
put api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer), put api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer),
params: { access_level: Member::MAINTAINER } params: { access_level: Member::MAINTAINER }
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
   
it 'returns 400 when access_level is not given' do it 'returns 400 when access_level is not given' do
put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer)
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
   
it 'returns 400 when access level is not valid' do it 'returns 400 when access level is not valid' do
put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer), put api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer),
params: { access_level: 1234 } params: { access_level: 1234 }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
end end
Loading
@@ -393,7 +393,7 @@ describe API::Members do
Loading
@@ -393,7 +393,7 @@ describe API::Members do
user = public_send(type) user = public_send(type)
delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user) delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", user)
   
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
Loading
@@ -404,7 +404,7 @@ describe API::Members do
Loading
@@ -404,7 +404,7 @@ describe API::Members do
expect do expect do
delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", developer) delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", developer)
   
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { source.members.count }.by(-1) end.to change { source.members.count }.by(-1)
end end
end end
Loading
@@ -415,7 +415,7 @@ describe API::Members do
Loading
@@ -415,7 +415,7 @@ describe API::Members do
expect do expect do
delete api("/#{source_type.pluralize}/#{source.id}/members/#{access_requester.id}", maintainer) delete api("/#{source_type.pluralize}/#{source.id}/members/#{access_requester.id}", maintainer)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end.not_to change { source.requesters.count } end.not_to change { source.requesters.count }
end end
end end
Loading
@@ -424,7 +424,7 @@ describe API::Members do
Loading
@@ -424,7 +424,7 @@ describe API::Members do
expect do expect do
delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer) delete api("/#{source_type.pluralize}/#{source.id}/members/#{developer.id}", maintainer)
   
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { source.members.count }.by(-1) end.to change { source.members.count }.by(-1)
end end
   
Loading
@@ -436,7 +436,7 @@ describe API::Members do
Loading
@@ -436,7 +436,7 @@ describe API::Members do
it 'returns 404 if member does not exist' do it 'returns 404 if member does not exist' do
delete api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer) delete api("/#{source_type.pluralize}/#{source.id}/members/123", maintainer)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
Loading
@@ -491,7 +491,7 @@ describe API::Members do
Loading
@@ -491,7 +491,7 @@ describe API::Members do
post api("/projects/#{project.id}/members", maintainer), post api("/projects/#{project.id}/members", maintainer),
params: { user_id: stranger.id, access_level: Member::OWNER } params: { user_id: stranger.id, access_level: Member::OWNER }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end.to change { project.members.count }.by(0) end.to change { project.members.count }.by(0)
end end
end end
Loading
Loading
Loading
@@ -28,12 +28,12 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
Loading
@@ -28,12 +28,12 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
   
it 'returns a 404 when merge_request id is used instead of the iid' do it 'returns a 404 when merge_request id is used instead of the iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
   
it 'returns a 404 when merge_request_iid not found' do it 'returns a 404 when merge_request_iid not found' do
get api("/projects/#{project.id}/merge_requests/0/versions", user) get api("/projects/#{project.id}/merge_requests/0/versions", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
   
Loading
@@ -51,17 +51,17 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
Loading
@@ -51,17 +51,17 @@ describe API::MergeRequestDiffs, 'MergeRequestDiffs' do
   
it 'returns a 404 when merge_request id is used instead of the iid' do it 'returns a 404 when merge_request id is used instead of the iid' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/versions/#{merge_request_diff.id}", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
   
it 'returns a 404 when merge_request version_id is not found' do it 'returns a 404 when merge_request version_id is not found' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/0", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/versions/0", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
   
it 'returns a 404 when merge_request_iid is not found' do it 'returns a 404 when merge_request_iid is not found' do
get api("/projects/#{project.id}/merge_requests/12345/versions/#{merge_request_diff.id}", user) get api("/projects/#{project.id}/merge_requests/12345/versions/#{merge_request_diff.id}", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
This diff is collapsed.
Loading
@@ -12,7 +12,7 @@ describe API::Namespaces do
Loading
@@ -12,7 +12,7 @@ describe API::Namespaces do
context "when unauthenticated" do context "when unauthenticated" do
it "returns authentication error" do it "returns authentication error" do
get api("/namespaces") get api("/namespaces")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
   
Loading
@@ -23,7 +23,7 @@ describe API::Namespaces do
Loading
@@ -23,7 +23,7 @@ describe API::Namespaces do
group_kind_json_response = json_response.find { |resource| resource['kind'] == 'group' } group_kind_json_response = json_response.find { |resource| resource['kind'] == 'group' }
user_kind_json_response = json_response.find { |resource| resource['kind'] == 'user' } user_kind_json_response = json_response.find { |resource| resource['kind'] == 'user' }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(group_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path', expect(group_kind_json_response.keys).to include('id', 'kind', 'name', 'path', 'full_path',
'parent_id', 'members_count_with_descendants') 'parent_id', 'members_count_with_descendants')
Loading
@@ -34,7 +34,7 @@ describe API::Namespaces do
Loading
@@ -34,7 +34,7 @@ describe API::Namespaces do
it "admin: returns an array of all namespaces" do it "admin: returns an array of all namespaces" do
get api("/namespaces", admin) get api("/namespaces", admin)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(Namespace.count) expect(json_response.length).to eq(Namespace.count)
Loading
@@ -43,7 +43,7 @@ describe API::Namespaces do
Loading
@@ -43,7 +43,7 @@ describe API::Namespaces do
it "admin: returns an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{group2.name}", admin) get api("/namespaces?search=#{group2.name}", admin)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
Loading
@@ -77,7 +77,7 @@ describe API::Namespaces do
Loading
@@ -77,7 +77,7 @@ describe API::Namespaces do
it "user: returns an array of namespaces" do it "user: returns an array of namespaces" do
get api("/namespaces", user) get api("/namespaces", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
Loading
@@ -86,7 +86,7 @@ describe API::Namespaces do
Loading
@@ -86,7 +86,7 @@ describe API::Namespaces do
it "admin: returns an array of matched namespaces" do it "admin: returns an array of matched namespaces" do
get api("/namespaces?search=#{user.username}", user) get api("/namespaces?search=#{user.username}", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
Loading
@@ -102,7 +102,7 @@ describe API::Namespaces do
Loading
@@ -102,7 +102,7 @@ describe API::Namespaces do
it 'returns namespace details' do it 'returns namespace details' do
get api("/namespaces/#{namespace_id}", request_actor) get api("/namespaces/#{namespace_id}", request_actor)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
   
expect(json_response['id']).to eq(requested_namespace.id) expect(json_response['id']).to eq(requested_namespace.id)
expect(json_response['path']).to eq(requested_namespace.path) expect(json_response['path']).to eq(requested_namespace.path)
Loading
@@ -153,7 +153,7 @@ describe API::Namespaces do
Loading
@@ -153,7 +153,7 @@ describe API::Namespaces do
it 'returns not-found' do it 'returns not-found' do
get api('/namespaces/0', request_actor) get api('/namespaces/0', request_actor)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
Loading
@@ -162,7 +162,7 @@ describe API::Namespaces do
Loading
@@ -162,7 +162,7 @@ describe API::Namespaces do
it 'returns authentication error' do it 'returns authentication error' do
get api("/namespaces/#{group1.id}") get api("/namespaces/#{group1.id}")
   
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
   
Loading
@@ -174,7 +174,7 @@ describe API::Namespaces do
Loading
@@ -174,7 +174,7 @@ describe API::Namespaces do
it 'returns not-found' do it 'returns not-found' do
get api("/namespaces/#{group2.id}", request_actor) get api("/namespaces/#{group2.id}", request_actor)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
   
Loading
@@ -182,7 +182,7 @@ describe API::Namespaces do
Loading
@@ -182,7 +182,7 @@ describe API::Namespaces do
it 'returns not-found' do it 'returns not-found' do
get api("/namespaces/#{user2.namespace.id}", request_actor) get api("/namespaces/#{user2.namespace.id}", request_actor)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
Loading
Loading
Loading
@@ -72,7 +72,7 @@ describe API::Notes do
Loading
@@ -72,7 +72,7 @@ describe API::Notes do
it "returns an empty array" do it "returns an empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response).to be_empty expect(json_response).to be_empty
Loading
@@ -86,7 +86,7 @@ describe API::Notes do
Loading
@@ -86,7 +86,7 @@ describe API::Notes do
it "returns 404" do it "returns 404" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", user)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
Loading
@@ -95,7 +95,7 @@ describe API::Notes do
Loading
@@ -95,7 +95,7 @@ describe API::Notes do
it "returns a non-empty array" do it "returns a non-empty array" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes", private_user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['body']).to eq(cross_reference_note.note) expect(json_response.first['body']).to eq(cross_reference_note.note)
Loading
@@ -114,7 +114,7 @@ describe API::Notes do
Loading
@@ -114,7 +114,7 @@ describe API::Notes do
   
shared_examples 'a notes request' do shared_examples 'a notes request' do
it 'is a note array response' do it 'is a note array response' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
end end
Loading
@@ -177,7 +177,7 @@ describe API::Notes do
Loading
@@ -177,7 +177,7 @@ describe API::Notes do
it "returns a 404 error" do it "returns a 404 error" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", user)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
   
context "when issue is confidential" do context "when issue is confidential" do
Loading
@@ -188,7 +188,7 @@ describe API::Notes do
Loading
@@ -188,7 +188,7 @@ describe API::Notes do
it "returns 404" do it "returns 404" do
get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{issue_note.id}", private_user) get api("/projects/#{project.id}/issues/#{issue.iid}/notes/#{issue_note.id}", private_user)
   
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
Loading
@@ -197,7 +197,7 @@ describe API::Notes do
Loading
@@ -197,7 +197,7 @@ describe API::Notes do
it "returns an issue note by id" do it "returns an issue note by id" do
get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", private_user) get api("/projects/#{ext_proj.id}/issues/#{ext_issue.iid}/notes/#{cross_reference_note.id}", private_user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['body']).to eq(cross_reference_note.note) expect(json_response['body']).to eq(cross_reference_note.note)
end end
end end
Loading
@@ -237,7 +237,7 @@ describe API::Notes do
Loading
@@ -237,7 +237,7 @@ describe API::Notes do
it 'returns 200 status' do it 'returns 200 status' do
subject subject
   
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
   
it 'creates a new note' do it 'creates a new note' do
Loading
@@ -251,7 +251,7 @@ describe API::Notes do
Loading
@@ -251,7 +251,7 @@ describe API::Notes do
it 'returns 403 status' do it 'returns 403 status' do
subject subject
   
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
   
it 'does not create a new note' do it 'does not create a new note' do
Loading
Loading
Loading
@@ -11,7 +11,7 @@ describe API::NotificationSettings do
Loading
@@ -11,7 +11,7 @@ describe API::NotificationSettings do
it "returns global notification settings for the current user" do it "returns global notification settings for the current user" do
get api("/notification_settings", user) get api("/notification_settings", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
expect(json_response['notification_email']).to eq(user.notification_email) expect(json_response['notification_email']).to eq(user.notification_email)
expect(json_response['level']).to eq(user.global_notification_setting.level) expect(json_response['level']).to eq(user.global_notification_setting.level)
Loading
@@ -24,7 +24,7 @@ describe API::NotificationSettings do
Loading
@@ -24,7 +24,7 @@ describe API::NotificationSettings do
it "updates global notification settings for the current user" do it "updates global notification settings for the current user" do
put api("/notification_settings", user), params: { level: 'watch', notification_email: email.email } put api("/notification_settings", user), params: { level: 'watch', notification_email: email.email }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['notification_email']).to eq(email.email) expect(json_response['notification_email']).to eq(email.email)
expect(user.reload.notification_email).to eq(email.email) expect(user.reload.notification_email).to eq(email.email)
expect(json_response['level']).to eq(user.reload.global_notification_setting.level) expect(json_response['level']).to eq(user.reload.global_notification_setting.level)
Loading
@@ -35,7 +35,7 @@ describe API::NotificationSettings do
Loading
@@ -35,7 +35,7 @@ describe API::NotificationSettings do
it "fails on non-user email address" do it "fails on non-user email address" do
put api("/notification_settings", user), params: { notification_email: 'invalid@example.com' } put api("/notification_settings", user), params: { notification_email: 'invalid@example.com' }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
   
Loading
@@ -43,7 +43,7 @@ describe API::NotificationSettings do
Loading
@@ -43,7 +43,7 @@ describe API::NotificationSettings do
it "returns group level notification settings for the current user" do it "returns group level notification settings for the current user" do
get api("/groups/#{group.id}/notification_settings", user) get api("/groups/#{group.id}/notification_settings", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
expect(json_response['level']).to eq(user.notification_settings_for(group).level) expect(json_response['level']).to eq(user.notification_settings_for(group).level)
end end
Loading
@@ -53,7 +53,7 @@ describe API::NotificationSettings do
Loading
@@ -53,7 +53,7 @@ describe API::NotificationSettings do
it "updates group level notification settings for the current user" do it "updates group level notification settings for the current user" do
put api("/groups/#{group.id}/notification_settings", user), params: { level: 'watch' } put api("/groups/#{group.id}/notification_settings", user), params: { level: 'watch' }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['level']).to eq(user.reload.notification_settings_for(group).level) expect(json_response['level']).to eq(user.reload.notification_settings_for(group).level)
end end
end end
Loading
@@ -62,7 +62,7 @@ describe API::NotificationSettings do
Loading
@@ -62,7 +62,7 @@ describe API::NotificationSettings do
it "returns project level notification settings for the current user" do it "returns project level notification settings for the current user" do
get api("/projects/#{project.id}/notification_settings", user) get api("/projects/#{project.id}/notification_settings", user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash expect(json_response).to be_a Hash
expect(json_response['level']).to eq(user.notification_settings_for(project).level) expect(json_response['level']).to eq(user.notification_settings_for(project).level)
end end
Loading
@@ -72,7 +72,7 @@ describe API::NotificationSettings do
Loading
@@ -72,7 +72,7 @@ describe API::NotificationSettings do
it "updates project level notification settings for the current user" do it "updates project level notification settings for the current user" do
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true } put api("/projects/#{project.id}/notification_settings", user), params: { level: 'custom', new_note: true }
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['level']).to eq(user.reload.notification_settings_for(project).level) expect(json_response['level']).to eq(user.reload.notification_settings_for(project).level)
expect(json_response['events']['new_note']).to be_truthy expect(json_response['events']['new_note']).to be_truthy
expect(json_response['events']['new_issue']).to be_falsey expect(json_response['events']['new_issue']).to be_falsey
Loading
@@ -83,7 +83,7 @@ describe API::NotificationSettings do
Loading
@@ -83,7 +83,7 @@ describe API::NotificationSettings do
it "fails on invalid level" do it "fails on invalid level" do
put api("/projects/#{project.id}/notification_settings", user), params: { level: 'invalid' } put api("/projects/#{project.id}/notification_settings", user), params: { level: 'invalid' }
   
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
end end
Loading
@@ -14,7 +14,7 @@ describe 'OAuth tokens' do
Loading
@@ -14,7 +14,7 @@ describe 'OAuth tokens' do
   
request_oauth_token(user) request_oauth_token(user)
   
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
expect(json_response['error']).to eq('invalid_grant') expect(json_response['error']).to eq('invalid_grant')
end end
end end
Loading
@@ -25,7 +25,7 @@ describe 'OAuth tokens' do
Loading
@@ -25,7 +25,7 @@ describe 'OAuth tokens' do
   
request_oauth_token(user) request_oauth_token(user)
   
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['access_token']).not_to be_nil expect(json_response['access_token']).not_to be_nil
end end
end end
Loading
@@ -33,7 +33,7 @@ describe 'OAuth tokens' do
Loading
@@ -33,7 +33,7 @@ describe 'OAuth tokens' do
shared_examples 'does not create an access token' do shared_examples 'does not create an access token' do
let(:user) { create(:user) } let(:user) { create(:user) }
   
it { expect(response).to have_gitlab_http_status(401) } it { expect(response).to have_gitlab_http_status(:unauthorized) }
end end
   
context 'when user is blocked' do context 'when user is blocked' do
Loading
Loading
Loading
@@ -1979,6 +1979,21 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
Loading
@@ -1979,6 +1979,21 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end end
end end
   
context 'when object storage throws errors' do
let(:params) { { artifact_type: :archive, artifact_format: :zip } }
it 'does not store artifacts' do
allow_next_instance_of(JobArtifactUploader) do |uploader|
allow(uploader).to receive(:store!).and_raise(Errno::EIO)
end
upload_artifacts(file_upload, headers_with_token, params)
expect(response).to have_gitlab_http_status(:service_unavailable)
expect(job.reload.job_artifacts_archive).to be_nil
end
end
context 'when artifacts are being stored outside of tmp path' do context 'when artifacts are being stored outside of tmp path' do
let(:new_tmpdir) { Dir.mktmpdir } let(:new_tmpdir) { Dir.mktmpdir }
   
Loading
Loading
Loading
@@ -3,8 +3,9 @@
Loading
@@ -3,8 +3,9 @@
require 'spec_helper' require 'spec_helper'
   
describe Ci::CreateJobArtifactsService do describe Ci::CreateJobArtifactsService do
let(:service) { described_class.new } let_it_be(:project) { create(:project) }
let(:job) { create(:ci_build) } let(:service) { described_class.new(project) }
let(:job) { create(:ci_build, project: project) }
let(:artifacts_sha256) { '0' * 64 } let(:artifacts_sha256) { '0' * 64 }
let(:metadata_file) { nil } let(:metadata_file) { nil }
   
Loading
@@ -64,7 +65,7 @@ describe Ci::CreateJobArtifactsService do
Loading
@@ -64,7 +65,7 @@ describe Ci::CreateJobArtifactsService do
it 'sets expiration date according to application settings' do it 'sets expiration date according to application settings' do
expected_expire_at = 1.day.from_now expected_expire_at = 1.day.from_now
   
expect(subject).to be_truthy expect(subject).to match(a_hash_including(status: :success))
archive_artifact, metadata_artifact = job.job_artifacts.last(2) archive_artifact, metadata_artifact = job.job_artifacts.last(2)
   
expect(job.artifacts_expire_at).to be_within(1.minute).of(expected_expire_at) expect(job.artifacts_expire_at).to be_within(1.minute).of(expected_expire_at)
Loading
@@ -80,7 +81,7 @@ describe Ci::CreateJobArtifactsService do
Loading
@@ -80,7 +81,7 @@ describe Ci::CreateJobArtifactsService do
it 'sets expiration date according to the parameter' do it 'sets expiration date according to the parameter' do
expected_expire_at = 2.hours.from_now expected_expire_at = 2.hours.from_now
   
expect(subject).to be_truthy expect(subject).to match(a_hash_including(status: :success))
archive_artifact, metadata_artifact = job.job_artifacts.last(2) archive_artifact, metadata_artifact = job.job_artifacts.last(2)
   
expect(job.artifacts_expire_at).to be_within(1.minute).of(expected_expire_at) expect(job.artifacts_expire_at).to be_within(1.minute).of(expected_expire_at)
Loading
@@ -101,21 +102,50 @@ describe Ci::CreateJobArtifactsService do
Loading
@@ -101,21 +102,50 @@ describe Ci::CreateJobArtifactsService do
   
it 'ignores the changes' do it 'ignores the changes' do
expect { subject }.not_to change { Ci::JobArtifact.count } expect { subject }.not_to change { Ci::JobArtifact.count }
expect(subject).to be_truthy expect(subject).to match(a_hash_including(status: :success))
end end
end end
   
context 'when sha256 of uploading artifact is different than the existing one' do context 'when sha256 of uploading artifact is different than the existing one' do
let(:existing_sha256) { '1' * 64 } let(:existing_sha256) { '1' * 64 }
   
it 'returns false and logs the error' do it 'returns error status' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
   
expect { subject }.not_to change { Ci::JobArtifact.count } expect { subject }.not_to change { Ci::JobArtifact.count }
expect(subject).to be_falsey expect(subject).to match(
expect(job.errors[:base]).to contain_exactly('another artifact of the same type already exists') a_hash_including(http_status: :bad_request,
message: 'another artifact of the same type already exists',
status: :error))
end end
end end
end end
shared_examples 'rescues object storage error' do |klass, message, expected_message|
it "handles #{klass}" do
allow_next_instance_of(JobArtifactUploader) do |uploader|
allow(uploader).to receive(:store!).and_raise(klass, message)
end
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.and_call_original
expect(subject).to match(
a_hash_including(
http_status: :service_unavailable,
message: expected_message || message,
status: :error))
end
end
it_behaves_like 'rescues object storage error',
Errno::EIO, 'some/path', 'Input/output error - some/path'
it_behaves_like 'rescues object storage error',
Google::Apis::ServerError, 'Server error'
it_behaves_like 'rescues object storage error',
Signet::RemoteServerError, 'The service is currently unavailable'
end end
end end
Loading
@@ -36,7 +36,7 @@ describe Ci::RetryBuildService do
Loading
@@ -36,7 +36,7 @@ describe Ci::RetryBuildService do
job_artifacts_performance job_artifacts_lsif job_artifacts_performance job_artifacts_lsif
job_artifacts_codequality job_artifacts_metrics scheduled_at job_artifacts_codequality job_artifacts_metrics scheduled_at
job_variables waiting_for_resource_at job_artifacts_metrics_referee job_variables waiting_for_resource_at job_artifacts_metrics_referee
job_artifacts_network_referee].freeze job_artifacts_network_referee needs].freeze
   
IGNORE_ACCESSORS = IGNORE_ACCESSORS =
%i[type lock_version target_url base_tags trace_sections %i[type lock_version target_url base_tags trace_sections
Loading
@@ -46,7 +46,8 @@ describe Ci::RetryBuildService do
Loading
@@ -46,7 +46,8 @@ describe Ci::RetryBuildService do
sourced_pipelines artifacts_file_store artifacts_metadata_store sourced_pipelines artifacts_file_store artifacts_metadata_store
metadata runner_session trace_chunks upstream_pipeline_id metadata runner_session trace_chunks upstream_pipeline_id
artifacts_file artifacts_metadata artifacts_size commands artifacts_file artifacts_metadata artifacts_size commands
resource resource_group_id processed security_scans].freeze resource resource_group_id processed security_scans author
pipeline_id].freeze
   
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) } let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
Loading
@@ -79,8 +80,15 @@ describe Ci::RetryBuildService do
Loading
@@ -79,8 +80,15 @@ describe Ci::RetryBuildService do
end end
   
describe 'clone accessors' do describe 'clone accessors' do
let(:forbidden_associations) do
Ci::Build.reflect_on_all_associations.each_with_object(Set.new) do |assoc, memo|
memo << assoc.name unless assoc.macro == :belongs_to
end
end
CLONE_ACCESSORS.each do |attribute| CLONE_ACCESSORS.each do |attribute|
it "clones #{attribute} build attribute" do it "clones #{attribute} build attribute" do
expect(attribute).not_to be_in(forbidden_associations), "association #{attribute} must be `belongs_to`"
expect(build.send(attribute)).not_to be_nil expect(build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).not_to be_nil expect(new_build.send(attribute)).not_to be_nil
expect(new_build.send(attribute)).to eq build.send(attribute) expect(new_build.send(attribute)).to eq build.send(attribute)
Loading
@@ -97,9 +105,17 @@ describe Ci::RetryBuildService do
Loading
@@ -97,9 +105,17 @@ describe Ci::RetryBuildService do
expect(new_build.protected).to eq build.protected expect(new_build.protected).to eq build.protected
end end
end end
it 'clones only the needs attributes' do
expect(new_build.needs.exists?).to be_truthy
expect(build.needs.exists?).to be_truthy
expect(new_build.needs_attributes).to match(build.needs_attributes)
expect(new_build.needs).not_to match(build.needs)
end
end end
   
describe 'reject acessors' do describe 'reject accessors' do
REJECT_ACCESSORS.each do |attribute| REJECT_ACCESSORS.each do |attribute|
it "does not clone #{attribute} build attribute" do it "does not clone #{attribute} build attribute" do
expect(new_build.send(attribute)).not_to eq build.send(attribute) expect(new_build.send(attribute)).not_to eq build.send(attribute)
Loading
@@ -117,8 +133,9 @@ describe Ci::RetryBuildService do
Loading
@@ -117,8 +133,9 @@ describe Ci::RetryBuildService do
# #
current_accessors = current_accessors =
Ci::Build.attribute_names.map(&:to_sym) + Ci::Build.attribute_names.map(&:to_sym) +
Ci::Build.attribute_aliases.keys.map(&:to_sym) +
Ci::Build.reflect_on_all_associations.map(&:name) + Ci::Build.reflect_on_all_associations.map(&:name) +
[:tag_list] [:tag_list, :needs_attributes]
   
current_accessors.uniq! current_accessors.uniq!
   
Loading
Loading
Loading
@@ -43,6 +43,12 @@ describe ErrorTracking::IssueUpdateService do
Loading
@@ -43,6 +43,12 @@ describe ErrorTracking::IssueUpdateService do
update_service.execute update_service.execute
end end
   
it 'clears the reactive cache' do
expect(error_tracking_setting).to receive(:expire_issues_cache)
result
end
context 'related issue and resolving' do context 'related issue and resolving' do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:sentry_issue) { create(:sentry_issue, issue: issue) } let(:sentry_issue) { create(:sentry_issue, issue: issue) }
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Metrics::Dashboard::UpdateDashboardService, :use_clean_rails_memory_store_caching do
include MetricsDashboardHelpers
set(:user) { create(:user) }
set(:project) { create(:project, :repository) }
set(:environment) { create(:environment, project: project) }
describe '#execute' do
subject(:service_call) { described_class.new(project, user, params).execute }
let(:commit_message) { 'test' }
let(:branch) { 'dashboard_new_branch' }
let(:dashboard) { 'config/prometheus/common_metrics.yml' }
let(:file_name) { 'custom_dashboard.yml' }
let(:file_content_hash) { YAML.safe_load(File.read(dashboard)) }
let(:params) do
{
file_name: file_name,
file_content: file_content_hash,
commit_message: commit_message,
branch: branch
}
end
context 'user does not have push right to repository' do
it_behaves_like 'misconfigured dashboard service response', :forbidden, "You can't commit to this project"
end
context 'with rights to push to the repository' do
before do
project.add_maintainer(user)
end
context 'path traversal attack attempt' do
context 'with a yml extension' do
let(:file_name) { 'config/prometheus/../database.yml' }
it_behaves_like 'misconfigured dashboard service response', :bad_request, "A file with this name doesn't exist"
end
context 'without a yml extension' do
let(:file_name) { '../../..../etc/passwd' }
it_behaves_like 'misconfigured dashboard service response', :bad_request, "The file name should have a .yml extension"
end
end
context 'valid parameters' do
it_behaves_like 'valid dashboard update process'
end
context 'selected branch already exists' do
let(:branch) { 'existing_branch' }
before do
project.repository.add_branch(user, branch, 'master')
end
it_behaves_like 'misconfigured dashboard service response', :bad_request, "There was an error updating the dashboard, branch named: existing_branch already exists."
end
context 'Files::UpdateService success' do
before do
allow(::Files::UpdateService).to receive(:new).and_return(double(execute: { status: :success }))
end
it 'returns success', :aggregate_failures do
dashboard_details = {
path: '.gitlab/dashboards/custom_dashboard.yml',
display_name: 'custom_dashboard.yml',
default: false,
system_dashboard: false
}
expect(service_call[:status]).to be :success
expect(service_call[:http_status]).to be :created
expect(service_call[:dashboard]).to match dashboard_details
end
context 'with escaped characters in file name' do
let(:file_name) { "custom_dashboard%26copy.yml" }
it 'escapes the special characters', :aggregate_failures do
dashboard_details = {
path: '.gitlab/dashboards/custom_dashboard&copy.yml',
display_name: 'custom_dashboard&copy.yml',
default: false,
system_dashboard: false
}
expect(service_call[:status]).to be :success
expect(service_call[:http_status]).to be :created
expect(service_call[:dashboard]).to match dashboard_details
end
end
end
context 'Files::UpdateService fails' do
before do
allow(::Files::UpdateService).to receive(:new).and_return(double(execute: { status: :error }))
end
it 'returns error' do
expect(service_call[:status]).to be :error
end
end
end
end
end
Loading
@@ -85,3 +85,24 @@ RSpec.shared_examples 'valid dashboard cloning process' do |dashboard_template,
Loading
@@ -85,3 +85,24 @@ RSpec.shared_examples 'valid dashboard cloning process' do |dashboard_template,
end end
end end
end end
RSpec.shared_examples 'valid dashboard update process' do
let(:dashboard_attrs) do
{
commit_message: commit_message,
branch_name: branch,
start_branch: project.default_branch,
encoding: 'text',
file_path: ".gitlab/dashboards/#{file_name}",
file_content: ::PerformanceMonitoring::PrometheusDashboard.from_json(file_content_hash).to_yaml
}
end
it 'delegates commit creation to Files::UpdateService', :aggregate_failures do
service_instance = instance_double(::Files::UpdateService)
expect(::Files::UpdateService).to receive(:new).with(project, user, dashboard_attrs).and_return(service_instance)
expect(service_instance).to receive(:execute).and_return(status: :success)
service_call
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment