Skip to content

feat(groups): add a list_ldap_group_links to go along with the pre ex… #2371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 16, 2022
17 changes: 17 additions & 0 deletions gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/objects/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down