Add new endpoint for specific ldap group listing

parent f06a60e2
...@@ -4,16 +4,30 @@ module API ...@@ -4,16 +4,30 @@ module API
before { authenticate! } before { authenticate! }
resource :ldap do resource :ldap do
helpers do
def get_group_list(provider, search)
Gitlab::LDAP::Adapter.new(provider).groups("#{search}*", 20)
end
end
# Get a LDAP groups list. Limit size to 20 of them. # Get a LDAP groups list. Limit size to 20 of them.
# Filter results by name using search param # Filter results by name using search param
# #
# Example Request: # Example Request:
# GET /ldap/groups # GET /ldap/groups
get 'groups' do get 'groups' do
# NOTE: this should be deprecated in favour of /ldap/PROVIDER_NAME/groups
# for now we just select the first LDAP server
provider = Gitlab::LDAP::Config.servers.first.provider_name provider = Gitlab::LDAP::Config.servers.first.provider_name
@groups = Gitlab::LDAP::Adapter.new(provider).groups("#{params[:search]}*", 20) @groups = get_group_list(provider, params[:search])
present @groups, with: Entities::LdapGroup
end
# Get a LDAP groups list by the requested provider. Lited size to 20 of them.
# Filter results by name using search param
#
# Example Request:
# GET /ldap/ldapmain/groups
get ':provider/groups' do
@groups = get_group_list(params[:provider], params[:search])
present @groups, with: Entities::LdapGroup present @groups, with: Entities::LdapGroup
end end
end end
......
...@@ -25,7 +25,6 @@ describe API::API do ...@@ -25,7 +25,6 @@ describe API::API do
context "when authenticated as user" do context "when authenticated as user" do
it "should return an array of ldap groups" do it "should return an array of ldap groups" do
pending('Needs refactoring')
get api("/ldap/groups", user) get api("/ldap/groups", user)
response.status.should == 200 response.status.should == 200
json_response.should be_an Array json_response.should be_an Array
...@@ -34,4 +33,23 @@ describe API::API do ...@@ -34,4 +33,23 @@ describe API::API do
end end
end end
end end
describe "GET /ldap/ldapmain/groups" do
context "when unauthenticated" do
it "should return authentication error" do
get api("/ldap/ldapmain/groups")
response.status.should == 401
end
end
context "when authenticated as user" do
it "should return an array of ldap groups" do
get api("/ldap/ldapmain/groups", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 2
json_response.first['cn'].should == 'developers'
end
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