diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 9a6c47391..93321a18e 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -194,6 +194,23 @@ def delete_ldap_group_link( path += f"/{cn}" self.manager.gitlab.http_delete(path, **kwargs) + @cli.register_custom_action("Group") + @exc.on_http_error(exc.GitlabGetError) + def list_ldap_group_links( + self, **kwargs: Any + ) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]: + """List LDAP group links. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabGetError: If the server cannot perform the request + """ + path = f"/groups/{self.encoded_id}/ldap_group_links" + return self.manager.gitlab.http_list(path, **kwargs) + @cli.register_custom_action("Group") @exc.on_http_error(exc.GitlabCreateError) def ldap_sync(self, **kwargs: Any) -> None: diff --git a/tests/unit/objects/test_groups.py b/tests/unit/objects/test_groups.py index 6ca5cfe13..5cba6dcee 100644 --- a/tests/unit/objects/test_groups.py +++ b/tests/unit/objects/test_groups.py @@ -12,6 +12,14 @@ from gitlab.v4.objects.projects import GroupProject, SharedProject content = {"name": "name", "id": 1, "path": "path"} +ldap_group_links_content = [ + { + "cn": None, + "group_access": 40, + "provider": "ldapmain", + "filter": "(memberOf=cn=some_group,ou=groups,ou=fake_ou,dc=sub_dc,dc=example,dc=tld)", + } +] projects_content = [ { "id": 9, @@ -216,6 +224,19 @@ def resp_delete_push_rules_group(no_content): yield rsps +@pytest.fixture +def resp_list_ldap_group_links(no_content): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/groups/1/ldap_group_links", + json=ldap_group_links_content, + content_type="application/json", + status=200, + ) + yield rsps + + def test_get_group(gl, resp_groups): data = gl.groups.get(1) assert isinstance(data, gitlab.v4.objects.Group) @@ -261,6 +282,12 @@ def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_grou assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"] +def test_list_ldap_group_links(group, resp_list_ldap_group_links): + ldap_group_links = group.list_ldap_group_links() + assert isinstance(ldap_group_links, list) + assert ldap_group_links[0]["provider"] == ldap_group_links_content[0]["provider"] + + @pytest.mark.skip("GitLab API endpoint not implemented") def test_refresh_group_export_status(group, resp_export): export = group.exports.create()