2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-26 22:06:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe AutocompleteController do
|
2017-08-10 03:45:03 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { project.owner }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-11-29 06:21:50 -05:00
|
|
|
context 'GET users' do
|
2016-08-05 09:29:20 -04:00
|
|
|
let!(:user2) { create(:user) }
|
|
|
|
let!(:non_member) { create(:user) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'project members' do
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2016-02-17 06:49:38 -05:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns the project members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.map { |u| u["username"] }).to include(user.username)
|
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: 'unknown' })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
it { expect(response).to have_gitlab_http_status(:not_found) }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'group members' do
|
|
|
|
let(:group) { create(:group) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
group.add_owner(user)
|
2017-08-10 03:45:03 -04:00
|
|
|
sign_in(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with group ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { group_id: group.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns the group members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first["username"]).to eq user.username
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with unknown group ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { group_id: 'unknown' })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
it { expect(response).to have_gitlab_http_status(:not_found) }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'non-member login for public project' do
|
2017-08-10 03:45:03 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(non_member)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: project.id, current_user: true })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-08-06 03:20:41 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns the project members and non-members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
expect(json_response.map { |u| u['username'] }).to include(user.username, non_member.username)
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'all users' do
|
2015-08-06 03:20:41 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
|
|
|
get(:users)
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response.size).to eq User.count }
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2017-07-14 07:16:20 -04:00
|
|
|
context 'user order' do
|
|
|
|
it 'shows exact matches first' do
|
|
|
|
reported_user = create(:user, username: 'reported_user', name: 'Doug')
|
|
|
|
user = create(:user, username: 'user', name: 'User')
|
|
|
|
user1 = create(:user, username: 'user1', name: 'Ian')
|
|
|
|
|
|
|
|
sign_in(user)
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { search: 'user' })
|
2017-07-14 07:16:20 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
response_usernames = json_response.map { |user| user['username'] }
|
2017-07-14 07:16:20 -04:00
|
|
|
|
|
|
|
expect(response_usernames.take(3)).to match_array([user.username, reported_user.username, user1.username])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-26 13:59:00 -04:00
|
|
|
context 'limited users per page' do
|
|
|
|
before do
|
2020-01-09 13:07:52 -05:00
|
|
|
create_list(:user, 25)
|
2018-02-15 13:33:35 -05:00
|
|
|
|
2017-05-26 13:59:00 -04:00
|
|
|
sign_in(user)
|
2018-02-15 13:33:35 -05:00
|
|
|
get(:users)
|
2017-05-26 13:59:00 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
2018-02-15 13:33:35 -05:00
|
|
|
it { expect(json_response.size).to eq(20) }
|
2017-05-26 13:59:00 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'unauthenticated user' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:public_project) { create(:project, :public) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with public project' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
public_project.add_guest(user)
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: public_project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response.size).to eq 2 }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with project' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
it { expect(response).to have_gitlab_http_status(:not_found) }
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { project_id: 'unknown' })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
it { expect(response).to have_gitlab_http_status(:not_found) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with inaccessible group' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
project.add_guest(user)
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { group_id: user.namespace.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
it { expect(response).to have_gitlab_http_status(:not_found) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with no project' do
|
|
|
|
before do
|
|
|
|
get(:users)
|
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response).to be_empty }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2016-11-29 04:49:43 -05:00
|
|
|
|
|
|
|
describe 'GET #users with todo filter' do
|
|
|
|
it 'gives an array of users' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :users, params: { todo_filter: true }
|
2016-11-29 04:49:43 -05:00
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-10 03:45:03 -04:00
|
|
|
expect(json_response).to be_kind_of(Array)
|
2016-11-29 04:49:43 -05:00
|
|
|
end
|
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'author of issuable included' do
|
2017-06-08 12:52:27 -04:00
|
|
|
context 'authenticated' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the author' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { author_id: non_member.id })
|
2017-06-08 12:52:27 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
expect(json_response.first["username"]).to eq non_member.username
|
2017-06-08 12:52:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects non existent user ids' do
|
2020-04-01 11:07:45 -04:00
|
|
|
get(:users, params: { author_id: non_existing_record_id })
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2020-04-01 11:07:45 -04:00
|
|
|
expect(json_response.collect { |u| u['id'] }).not_to include(non_existing_record_id)
|
2017-06-08 12:52:27 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
|
2017-06-08 12:52:27 -04:00
|
|
|
context 'without authenticating' do
|
|
|
|
it 'returns empty result' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { author_id: non_member.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
expect(json_response).to be_empty
|
2017-06-08 12:52:27 -04:00
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'skip_users parameter included' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
it 'skips the user IDs passed' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:users, params: { skip_users: [user, user2].map(&:id) })
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
response_user_ids = json_response.map { |user| user['id'] }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
expect(response_user_ids).to contain_exactly(non_member.id)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
2019-08-01 12:51:14 -04:00
|
|
|
|
|
|
|
context 'merge_request_iid parameter included' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes can_merge option to users' do
|
|
|
|
merge_request = create(:merge_request, source_project: project)
|
|
|
|
|
|
|
|
get(:users, params: { merge_request_iid: merge_request.iid, project_id: project.id })
|
|
|
|
|
|
|
|
expect(json_response.first).to have_key('can_merge')
|
|
|
|
end
|
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
|
2016-11-29 06:21:50 -05:00
|
|
|
context 'GET projects' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:authorized_project) { create(:project) }
|
|
|
|
let(:authorized_search_project) { create(:project, name: 'rugged') }
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2016-02-09 06:02:52 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-02-09 06:02:52 -05:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects' do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
authorized_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:projects, params: { project_id: project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
2016-02-09 06:02:52 -05:00
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(json_response.first['id']).to eq authorized_project.id
|
2018-03-05 11:25:52 -05:00
|
|
|
expect(json_response.first['name_with_namespace']).to eq authorized_project.full_name
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
end
|
2016-04-06 03:37:46 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects and search' do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
authorized_project.add_maintainer(user)
|
|
|
|
authorized_search_project.add_maintainer(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID and search' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:projects, params: { project_id: project.id, search: 'rugged' })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(json_response.first['id']).to eq authorized_search_project.id
|
2018-03-05 11:25:52 -05:00
|
|
|
expect(json_response.first['name_with_namespace']).to eq authorized_search_project.full_name
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
2016-04-06 03:37:46 -04:00
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects apply limit' do
|
|
|
|
before do
|
2018-07-30 11:45:49 -04:00
|
|
|
allow(Kaminari.config).to receive(:default_per_page).and_return(2)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
create_list(:project, 2) do |project|
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:projects, params: { project_id: project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
2017-08-10 03:45:03 -04:00
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
2018-07-30 11:45:49 -04:00
|
|
|
expect(json_response.size).to eq(Kaminari.config.default_per_page)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects without admin_issue ability' do
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(user.can?(:admin_issue, authorized_project)).to eq(false)
|
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
2018-12-17 17:52:17 -05:00
|
|
|
get(:projects, params: { project_id: project.id })
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
it 'returns no projects' do
|
2017-08-10 03:45:03 -04:00
|
|
|
expect(json_response).to be_kind_of(Array)
|
2017-08-14 03:26:19 -04:00
|
|
|
expect(json_response.size).to eq(0)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-30 03:48:55 -04:00
|
|
|
|
|
|
|
context 'GET award_emojis' do
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let!(:award_emoji1) { create_list(:award_emoji, 2, user: user, name: 'thumbsup') }
|
|
|
|
let!(:award_emoji2) { create_list(:award_emoji, 1, user: user, name: 'thumbsdown') }
|
|
|
|
let!(:award_emoji3) { create_list(:award_emoji, 3, user: user, name: 'star') }
|
|
|
|
let!(:award_emoji4) { create_list(:award_emoji, 1, user: user, name: 'tea') }
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sign in as user without award emoji' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
sign_in(user2)
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sign in as user with award emoji' do
|
|
|
|
it 'returns json sorted by name count' do
|
|
|
|
sign_in(user)
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response.count).to eq 4
|
|
|
|
expect(json_response[0]).to match('name' => 'star')
|
|
|
|
expect(json_response[1]).to match('name' => 'thumbsup')
|
|
|
|
expect(json_response[2]).to match('name' => 'tea')
|
|
|
|
expect(json_response[3]).to match('name' => 'thumbsdown')
|
|
|
|
end
|
|
|
|
end
|
2019-11-29 19:06:03 -05:00
|
|
|
end
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2020-07-15 08:09:26 -04:00
|
|
|
context 'GET deploy_keys_with_owners' do
|
|
|
|
let!(:deploy_key) { create(:deploy_key, user: user) }
|
|
|
|
let!(:deploy_keys_project) { create(:deploy_keys_project, :write_access, project: project, deploy_key: deploy_key) }
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
|
|
|
it 'returns a not found response' do
|
|
|
|
get(:deploy_keys_with_owners, params: { project_id: project.id })
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user who can read the project is logged in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the deploy key in a json payload, with its owner' do
|
|
|
|
get(:deploy_keys_with_owners, params: { project_id: project.id })
|
|
|
|
|
|
|
|
expect(json_response.count).to eq(1)
|
|
|
|
expect(json_response.first['title']).to eq(deploy_key.title)
|
|
|
|
expect(json_response.first['owner']['id']).to eq(deploy_key.user.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unknown project' do
|
|
|
|
it 'returns a not found response' do
|
|
|
|
get(:deploy_keys_with_owners, params: { project_id: 9999 })
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and the user cannot read the owner of the key' do
|
|
|
|
before do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
allow(Ability).to receive(:allowed?).with(user, :read_user, deploy_key.user).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a payload without owner' do
|
|
|
|
get(:deploy_keys_with_owners, params: { project_id: project.id })
|
|
|
|
|
|
|
|
expect(json_response.count).to eq(1)
|
|
|
|
expect(json_response.first['title']).to eq(deploy_key.title)
|
|
|
|
expect(json_response.first['owner']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-29 19:06:03 -05:00
|
|
|
context 'Get merge_request_target_branches' do
|
|
|
|
let!(:merge_request) { create(:merge_request, source_project: project, target_branch: 'feature') }
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2019-11-29 19:06:03 -05:00
|
|
|
context 'anonymous user' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
get :merge_request_target_branches, params: { project_id: project.id }
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-11-29 19:06:03 -05:00
|
|
|
expect(json_response).to be_empty
|
2019-03-09 07:22:58 -05:00
|
|
|
end
|
2019-11-29 19:06:03 -05:00
|
|
|
end
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2019-11-29 19:06:03 -05:00
|
|
|
context 'user without any accessible merge requests' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
sign_in(create(:user))
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2019-11-29 19:06:03 -05:00
|
|
|
get :merge_request_target_branches, params: { project_id: project.id }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-11-29 19:06:03 -05:00
|
|
|
expect(json_response).to be_empty
|
2019-03-09 07:22:58 -05:00
|
|
|
end
|
2019-11-29 19:06:03 -05:00
|
|
|
end
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2019-11-29 19:06:03 -05:00
|
|
|
context 'user with an accessible merge request but no scope' do
|
2019-12-13 19:08:27 -05:00
|
|
|
where(
|
|
|
|
params: [
|
|
|
|
{},
|
|
|
|
{ group_id: ' ' },
|
|
|
|
{ project_id: ' ' },
|
|
|
|
{ group_id: ' ', project_id: ' ' }
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns an error' do
|
|
|
|
sign_in(user)
|
2019-03-09 07:22:58 -05:00
|
|
|
|
2019-12-13 19:08:27 -05:00
|
|
|
get :merge_request_target_branches, params: params
|
2019-11-29 19:06:03 -05:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-12-13 19:08:27 -05:00
|
|
|
expect(json_response).to eq({ 'error' => 'At least one of group_id or project_id must be specified' })
|
|
|
|
end
|
2019-11-29 19:06:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user with an accessible merge request by project' do
|
|
|
|
it 'returns json' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get :merge_request_target_branches, params: { project_id: project.id }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-11-29 19:06:03 -05:00
|
|
|
expect(json_response).to contain_exactly({ 'title' => 'feature' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user with an accessible merge request by group' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: group) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'returns json' do
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get :merge_request_target_branches, params: { group_id: group.id }
|
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-11-29 19:06:03 -05:00
|
|
|
expect(json_response).to contain_exactly({ 'title' => 'feature' })
|
2019-03-09 07:22:58 -05:00
|
|
|
end
|
|
|
|
end
|
2017-08-30 03:48:55 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|