Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fcd0b3fb
Commit
fcd0b3fb
authored
Aug 30, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return 403 if LDAP extras are disabled
parent
0296a401
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
44 deletions
+73
-44
app/controllers/groups/ldaps_controller.rb
app/controllers/groups/ldaps_controller.rb
+7
-0
lib/api/groups.rb
lib/api/groups.rb
+2
-0
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+64
-44
No files found.
app/controllers/groups/ldaps_controller.rb
View file @
fcd0b3fb
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
lib/api/groups.rb
View file @
fcd0b3fb
...
@@ -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
...
...
spec/requests/api/groups_spec.rb
View file @
fcd0b3fb
...
@@ -672,74 +672,94 @@ describe API::Groups do
...
@@ -672,74 +672,94 @@ describe API::Groups do
end
end
describe
'POST /groups/:id/ldap_sync'
do
describe
'POST /groups/:id/ldap_sync'
do
context
'when authenticated as the group owner'
do
context
'when LDAP config enabled_extras is true'
do
context
'when the group is ready to sync'
do
before
do
it
'returns 202 Accepted'
do
allow
(
Gitlab
::
LDAP
::
Config
).
to
receive
(
:enabled_extras?
).
and_return
(
true
)
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
end
expect
(
response
).
to
have_http_status
(
202
)
end
context
'when authenticated as the group owner'
do
context
'when the group is ready to sync'
do
it
'returns 202 Accepted'
do
ldap_sync
(
group1
.
id
,
user1
,
:disable!
)
expect
(
response
).
to
have_http_status
(
202
)
end
it
'queues a sync job'
do
expect
{
ldap_sync
(
group1
.
id
,
user1
,
:fake!
)
}.
to
change
(
LdapGroupSyncWorker
.
jobs
,
:size
).
by
(
1
)
end
it
'queues a sync job
'
do
it
'sets the ldap_sync state to pending
'
do
Sidekiq
::
Testing
.
fake!
do
ldap_sync
(
group1
.
id
,
user1
,
:disable!
)
expect
{
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
}.
to
change
(
LdapGroupSyncWorker
.
jobs
,
:size
).
by
(
1
)
expect
(
group1
.
reload
.
ldap_sync_pending?
).
to
be_truthy
end
end
end
end
it
'sets the ldap_sync state to pending'
do
context
'when the group is already pending a sync'
do
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
before
do
expect
(
group1
.
reload
.
ldap_sync_pending?
).
to
be_truthy
group1
.
pending_ldap_sync!
end
it
'returns 202 Accepted'
do
ldap_sync
(
group1
.
id
,
user1
,
:disable!
)
expect
(
response
).
to
have_http_status
(
202
)
end
it
'does not queue a sync job'
do
expect
{
ldap_sync
(
group1
.
id
,
user1
,
:fake!
)
}.
not_to
change
(
LdapGroupSyncWorker
.
jobs
,
:size
)
end
it
'does not change the ldap_sync state'
do
expect
do
ldap_sync
(
group1
.
id
,
user1
,
:disable!
)
end
.
not_to
change
{
group1
.
reload
.
ldap_sync_status
}
end
end
end
end
context
'when the group is already pending a sync
'
do
it
'returns 404 for a non existing group
'
do
before
do
ldap_sync
(
1328
,
user1
,
:disable!
)
group1
.
pending_ldap_sync!
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
context
'when authenticated as the admin'
do
it
'returns 202 Accepted'
do
it
'returns 202 Accepted'
do
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
ldap_sync
(
group1
.
id
,
admin
,
:disable!
)
expect
(
response
).
to
have_http_status
(
202
)
expect
(
response
).
to
have_http_status
(
202
)
end
end
end
it
'does not queue a sync job'
do
context
'when authenticated as a non-owner user that can see the group'
do
Sidekiq
::
Testing
.
fake!
do
it
'returns 403'
do
expect
{
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
}.
not_to
change
(
LdapGroupSyncWorker
.
jobs
,
:size
)
ldap_sync
(
group1
.
id
,
user2
,
:disable!
)
end
expect
(
response
).
to
have_http_status
(
403
)
end
it
'does not change the ldap_sync state'
do
expect
do
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user1
)
end
.
not_to
change
{
group1
.
reload
.
ldap_sync_status
}
end
end
end
end
it
'returns 404 for a non existing group'
do
context
'when authenticated as an user that cannot see the group'
do
post
api
(
'/groups/1328/ldap_sync'
,
user1
)
it
'returns 404'
do
expect
(
response
).
to
have_http_status
(
404
)
ldap_sync
(
group2
.
id
,
user1
,
:disable!
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
end
context
'when authenticated as the admin'
do
context
'when LDAP config enabled_extras is false'
do
it
'returns 202 Accepted'
do
before
do
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
admin
)
allow
(
Gitlab
::
LDAP
::
Config
).
to
receive
(
:enabled_extras?
).
and_return
(
false
)
expect
(
response
).
to
have_http_status
(
202
)
end
end
end
context
'when authenticated as an user that can see the group
'
do
it
'returns 403
'
do
it
'does not updates the group'
do
ldap_sync
(
group1
.
id
,
admin
,
:disable!
)
post
api
(
"/groups/
#{
group1
.
id
}
/ldap_sync"
,
user2
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
end
context
'when authenticated as an user that cannot see the group'
do
def
ldap_sync
(
group_id
,
user
,
sidekiq_testing_method
)
it
'returns 404 when trying to update the group'
do
Sidekiq
::
Testing
.
send
(
sidekiq_testing_method
)
do
post
api
(
"/groups/
#{
group2
.
id
}
/ldap_sync"
,
user1
)
post
api
(
"/groups/
#{
group_id
}
/ldap_sync"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment