Commit fcd0b3fb authored by Michael Kozono's avatar Michael Kozono

Return 403 if LDAP extras are disabled

parent 0296a401
class Groups::LdapsController < Groups::ApplicationController class Groups::LdapsController < Groups::ApplicationController
before_action :group before_action :group
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :check_enabled_extras!
def sync def sync
if @group.pending_ldap_sync if @group.pending_ldap_sync
...@@ -12,4 +13,10 @@ class Groups::LdapsController < Groups::ApplicationController ...@@ -12,4 +13,10 @@ class Groups::LdapsController < Groups::ApplicationController
redirect_to group_group_members_path(@group), notice: message redirect_to group_group_members_path(@group), notice: message
end end
private
def check_enabled_extras!
render_403 unless Gitlab::LDAP::Config.enabled_extras?
end
end end
...@@ -204,6 +204,8 @@ module API ...@@ -204,6 +204,8 @@ module API
desc 'Sync a group with LDAP.' desc 'Sync a group with LDAP.'
post ":id/ldap_sync" do post ":id/ldap_sync" do
forbidden!('LDAP is disabled, or LDAP extras are disabled for this license') unless Gitlab::LDAP::Config.enabled_extras?
group = find_group!(params[:id]) group = find_group!(params[:id])
authorize! :admin_group, group authorize! :admin_group, group
......
...@@ -672,21 +672,24 @@ describe API::Groups do ...@@ -672,21 +672,24 @@ describe API::Groups do
end end
describe 'POST /groups/:id/ldap_sync' do describe 'POST /groups/:id/ldap_sync' do
context 'when LDAP config enabled_extras is true' do
before do
allow(Gitlab::LDAP::Config).to receive(:enabled_extras?).and_return(true)
end
context 'when authenticated as the group owner' do context 'when authenticated as the group owner' do
context 'when the group is ready to sync' do context 'when the group is ready to sync' do
it 'returns 202 Accepted' do it 'returns 202 Accepted' do
post api("/groups/#{group1.id}/ldap_sync", user1) ldap_sync(group1.id, user1, :disable!)
expect(response).to have_http_status(202) expect(response).to have_http_status(202)
end end
it 'queues a sync job' do it 'queues a sync job' do
Sidekiq::Testing.fake! do expect { ldap_sync(group1.id, user1, :fake!) }.to change(LdapGroupSyncWorker.jobs, :size).by(1)
expect { post api("/groups/#{group1.id}/ldap_sync", user1) }.to change(LdapGroupSyncWorker.jobs, :size).by(1)
end
end end
it 'sets the ldap_sync state to pending' do it 'sets the ldap_sync state to pending' do
post api("/groups/#{group1.id}/ldap_sync", user1) ldap_sync(group1.id, user1, :disable!)
expect(group1.reload.ldap_sync_pending?).to be_truthy expect(group1.reload.ldap_sync_pending?).to be_truthy
end end
end end
...@@ -697,49 +700,66 @@ describe API::Groups do ...@@ -697,49 +700,66 @@ describe API::Groups do
end end
it 'returns 202 Accepted' do it 'returns 202 Accepted' do
post api("/groups/#{group1.id}/ldap_sync", user1) ldap_sync(group1.id, user1, :disable!)
expect(response).to have_http_status(202) expect(response).to have_http_status(202)
end end
it 'does not queue a sync job' do it 'does not queue a sync job' do
Sidekiq::Testing.fake! do expect { ldap_sync(group1.id, user1, :fake!) }.not_to change(LdapGroupSyncWorker.jobs, :size)
expect { post api("/groups/#{group1.id}/ldap_sync", user1) }.not_to change(LdapGroupSyncWorker.jobs, :size)
end
end end
it 'does not change the ldap_sync state' do it 'does not change the ldap_sync state' do
expect do expect do
post api("/groups/#{group1.id}/ldap_sync", user1) ldap_sync(group1.id, user1, :disable!)
end.not_to change { group1.reload.ldap_sync_status } end.not_to change { group1.reload.ldap_sync_status }
end end
end end
it 'returns 404 for a non existing group' do it 'returns 404 for a non existing group' do
post api('/groups/1328/ldap_sync', user1) ldap_sync(1328, user1, :disable!)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'when authenticated as the admin' do context 'when authenticated as the admin' do
it 'returns 202 Accepted' do it 'returns 202 Accepted' do
post api("/groups/#{group1.id}/ldap_sync", admin) ldap_sync(group1.id, admin, :disable!)
expect(response).to have_http_status(202) expect(response).to have_http_status(202)
end end
end end
context 'when authenticated as an user that can see the group' do context 'when authenticated as a non-owner user that can see the group' do
it 'does not updates the group' do it 'returns 403' do
post api("/groups/#{group1.id}/ldap_sync", user2) ldap_sync(group1.id, user2, :disable!)
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context 'when authenticated as an user that cannot see the group' do context 'when authenticated as an user that cannot see the group' do
it 'returns 404 when trying to update the group' do it 'returns 404' do
post api("/groups/#{group2.id}/ldap_sync", user1) ldap_sync(group2.id, user1, :disable!)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
end end
context 'when LDAP config enabled_extras is false' do
before do
allow(Gitlab::LDAP::Config).to receive(:enabled_extras?).and_return(false)
end
it 'returns 403' do
ldap_sync(group1.id, admin, :disable!)
expect(response).to have_http_status(403)
end
end
end
def ldap_sync(group_id, user, sidekiq_testing_method)
Sidekiq::Testing.send(sidekiq_testing_method) do
post api("/groups/#{group_id}/ldap_sync", user)
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