Skip to content

Commit

Permalink
Implement ldap group sync calls
Browse files Browse the repository at this point in the history
  • Loading branch information
baurmatt committed Dec 5, 2019
1 parent 216251a commit 33dbdd3
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/gitlab/client/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,42 @@ def edit_group(id, options = {})
def group_issues(group, options = {})
get("/groups/#{group}/issues", query: options)
end

# Sync group with LDAP
#
# @example
# Gitlab.sync_ldap_group(1)
#
# @param [Integer] id The ID or name of a group.
# @return [Array<Gitlab::ObjectifiedHash>]
def sync_ldap_group(id)
post("/groups/#{url_encode id}/ldap_sync")
end

# Add LDAP group link
#
# @example
# Gitlab.add_ldap_group_links(1, 'all', 50, 'ldap')
#
# @param [Integer] id The ID of a group
# @param [String] cn The CN of a LDAP group
# @param [Integer] group_access Minimum access level for members of the LDAP group.
# @param [String] provider LDAP provider for the LDAP group
# @return [Gitlab::ObjectifiedHash] Information about added ldap group link
def add_ldap_group_links(id, commonname, group_access, provider)
post("/groups/#{url_encode id}/ldap_group_links", body: { cn: commonname, group_access: group_access, provider: provider })
end

# Delete LDAP group link
#
# @example
# Gitlab.delete_ldap_group_links(1, 'all')
#
# @param [Integer] id The ID of a group
# @param [String] cn The CN of a LDAP group
# @return [Gitlab::ObjectifiedHash] Empty hash
def delete_ldap_group_links(id, commonname, provider)
delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/group_add_ldap_links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cn":"all","group_access":50,"provider":"ldap"}
Empty file.
Empty file.
40 changes: 40 additions & 0 deletions spec/gitlab/client/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,44 @@
expect(@merge_requests.first.project_id).to eq(3)
end
end

describe '.sync_ldap_group' do
before do
stub_post('/groups/1/ldap_sync', 'group_ldap_sync')
Gitlab.sync_ldap_group(1)
end

it 'gets the correct resource' do
expect(a_post('/groups/1/ldap_sync')).to have_been_made
end
end

describe '.add_ldap_group_links' do
before do
stub_post('/groups/1/ldap_group_links', 'group_add_ldap_links')
@ldap_link = Gitlab.add_ldap_group_links(1, 'all', 50, 'ldap')
end

it 'gets the correct resource' do
expect(a_post('/groups/1/ldap_group_links')
.with(body: { cn: 'all', group_access: 50, provider: 'ldap' })).to have_been_made
end

it 'returns information about the created ldap link' do
expect(@ldap_link.cn).to eq('all')
expect(@ldap_link.group_access).to eq(50)
expect(@ldap_link.provider).to eq('ldap')
end
end

describe '.delete_ldap_group_links' do
before do
stub_delete('/groups/1/ldap_group_links/ldap/all', 'group_delete_ldap_links')
Gitlab.delete_ldap_group_links(1, 'all', 'ldap')
end

it 'gets the correct resource' do
expect(a_delete('/groups/1/ldap_group_links/ldap/all')).to have_been_made
end
end
end

0 comments on commit 33dbdd3

Please sign in to comment.