Commit fc753ee3 authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot

Merge branch...

Merge branch 'security-pending-invitations-of-public-groups-and-public-projects-are-visible-to-any-user' into 'master'

Require group admin access to list pending invites

See merge request gitlab-org/security/gitlab!1714
parents 3ed2de4c f4b8af4e
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Types module Types
class GroupInvitationType < BaseObject class GroupInvitationType < BaseObject
expose_permissions Types::PermissionTypes::Group expose_permissions Types::PermissionTypes::Group
authorize :read_group authorize :admin_group
implements InvitationInterface implements InvitationInterface
......
...@@ -9,7 +9,7 @@ module Types ...@@ -9,7 +9,7 @@ module Types
implements InvitationInterface implements InvitationInterface
authorize :read_project authorize :admin_project
field :project, Types::ProjectType, null: true, field :project, Types::ProjectType, null: true,
description: 'Project ID for the project of the invitation.' description: 'Project ID for the project of the invitation.'
......
...@@ -46,6 +46,8 @@ module API ...@@ -46,6 +46,8 @@ module API
source = find_source(source_type, params[:id]) source = find_source(source_type, params[:id])
query = params[:query] query = params[:query]
authorize_admin_source!(source_type, source)
invitations = paginate(retrieve_member_invitations(source, query)) invitations = paginate(retrieve_member_invitations(source, query))
present_member_invitations invitations present_member_invitations invitations
......
...@@ -7,7 +7,7 @@ RSpec.describe Types::GroupInvitationType do ...@@ -7,7 +7,7 @@ RSpec.describe Types::GroupInvitationType do
specify { expect(described_class.graphql_name).to eq('GroupInvitation') } specify { expect(described_class.graphql_name).to eq('GroupInvitation') }
specify { expect(described_class).to require_graphql_authorizations(:read_group) } specify { expect(described_class).to require_graphql_authorizations(:admin_group) }
it 'has the expected fields' do it 'has the expected fields' do
expected_fields = %w[ expected_fields = %w[
......
...@@ -7,7 +7,7 @@ RSpec.describe Types::ProjectInvitationType do ...@@ -7,7 +7,7 @@ RSpec.describe Types::ProjectInvitationType do
specify { expect(described_class.graphql_name).to eq('ProjectInvitation') } specify { expect(described_class.graphql_name).to eq('ProjectInvitation') }
specify { expect(described_class).to require_graphql_authorizations(:read_project) } specify { expect(described_class).to require_graphql_authorizations(:admin_project) }
it 'has the expected fields' do it 'has the expected fields' do
expected_fields = %w[ expected_fields = %w[
......
...@@ -259,22 +259,32 @@ RSpec.describe API::Invitations do ...@@ -259,22 +259,32 @@ RSpec.describe API::Invitations do
let(:route) { get invitations_url(source, stranger) } let(:route) { get invitations_url(source, stranger) }
end end
%i[maintainer developer access_requester stranger].each do |type| context "when authenticated as a maintainer" do
it 'returns 200' do
get invitations_url(source, maintainer)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(0)
end
end
%i[developer access_requester stranger].each do |type|
context "when authenticated as a #{type}" do context "when authenticated as a #{type}" do
it 'returns 200' do it 'returns 403' do
user = public_send(type) user = public_send(type)
get invitations_url(source, user) get invitations_url(source, user)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:forbidden)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(0)
end end
end end
end end
it 'avoids N+1 queries' do it 'avoids N+1 queries' do
invite_member_by_email(source, source_type, email, maintainer)
# Establish baseline # Establish baseline
get invitations_url(source, maintainer) get invitations_url(source, maintainer)
...@@ -282,7 +292,7 @@ RSpec.describe API::Invitations do ...@@ -282,7 +292,7 @@ RSpec.describe API::Invitations do
get invitations_url(source, maintainer) get invitations_url(source, maintainer)
end end
invite_member_by_email(source, source_type, email, maintainer) invite_member_by_email(source, source_type, email2, maintainer)
expect do expect do
get invitations_url(source, maintainer) get invitations_url(source, maintainer)
...@@ -290,7 +300,7 @@ RSpec.describe API::Invitations do ...@@ -290,7 +300,7 @@ RSpec.describe API::Invitations do
end end
it 'does not find confirmed members' do it 'does not find confirmed members' do
get invitations_url(source, developer) get invitations_url(source, maintainer)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
...@@ -300,10 +310,10 @@ RSpec.describe API::Invitations do ...@@ -300,10 +310,10 @@ RSpec.describe API::Invitations do
end end
it 'finds all members with no query string specified' do it 'finds all members with no query string specified' do
invite_member_by_email(source, source_type, email, developer) invite_member_by_email(source, source_type, email, maintainer)
invite_member_by_email(source, source_type, email2, developer) invite_member_by_email(source, source_type, email2, maintainer)
get invitations_url(source, developer), params: { query: '' } get invitations_url(source, maintainer), params: { query: '' }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
...@@ -314,17 +324,17 @@ RSpec.describe API::Invitations do ...@@ -314,17 +324,17 @@ RSpec.describe API::Invitations do
end end
it 'finds the invitation by invite_email with query string' do it 'finds the invitation by invite_email with query string' do
invite_member_by_email(source, source_type, email, developer) invite_member_by_email(source, source_type, email, maintainer)
invite_member_by_email(source, source_type, email2, developer) invite_member_by_email(source, source_type, email2, maintainer)
get invitations_url(source, developer), params: { query: email } get invitations_url(source, maintainer), params: { query: email }
expect(response).to have_gitlab_http_status(:ok) 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)
expect(json_response.first['invite_email']).to eq(email) expect(json_response.first['invite_email']).to eq(email)
expect(json_response.first['created_by_name']).to eq(developer.name) expect(json_response.first['created_by_name']).to eq(maintainer.name)
expect(json_response.first['user_name']).to eq(nil) expect(json_response.first['user_name']).to eq(nil)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment