From f9a7e846910ee4869675d9cadb3595773ee61cdb Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Wed, 9 Nov 2022 17:30:50 +0000 Subject: [PATCH 1/7] feat(groups): add a list_ldap_group_links to go along with the pre existing add_ldap_group_link and delete_ldap_group_link --- gitlab/v4/objects/groups.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 9a6c47391..5d1d88530 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -194,6 +194,21 @@ 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): + """Add an LDAP group link. + + 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 = "/groups/%s/ldap_group_links" % self.get_id() + return self.manager.gitlab.http_get(path, **kwargs) + @cli.register_custom_action("Group") @exc.on_http_error(exc.GitlabCreateError) def ldap_sync(self, **kwargs: Any) -> None: From 90089831ebfb73663631db95ab5f66a052668062 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Wed, 9 Nov 2022 18:07:42 +0000 Subject: [PATCH 2/7] fix(groups): fixing comment in list_ldap_group_links --- gitlab/v4/objects/groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 5d1d88530..c0a26eea2 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -197,7 +197,7 @@ def delete_ldap_group_link( @cli.register_custom_action("Group") @exc.on_http_error(exc.GitlabGetError) def list_ldap_group_links(self, **kwargs): - """Add an LDAP group link. + """List LDAP group links. Args: **kwargs: Extra options to send to the server (e.g. sudo) From dd93e85e72c16b72d6888932bf4739ff5af17c97 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Thu, 10 Nov 2022 15:41:31 +0000 Subject: [PATCH 3/7] fix(groups): making list_ldap_group_links use fstrings --- gitlab/v4/objects/groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index c0a26eea2..4c223c212 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -206,7 +206,7 @@ def list_ldap_group_links(self, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request """ - path = "/groups/%s/ldap_group_links" % self.get_id() + path = f"/groups/{self.encoded_id}/ldap_group_links" return self.manager.gitlab.http_get(path, **kwargs) @cli.register_custom_action("Group") From 10319a24af87d06bd5d9f8492678f48412853d21 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Thu, 10 Nov 2022 16:04:46 +0000 Subject: [PATCH 4/7] fix(groups): making list_ldap_group_links use use function type annotations --- gitlab/v4/objects/groups.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 4c223c212..b1357299d 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -196,7 +196,9 @@ def delete_ldap_group_link( @cli.register_custom_action("Group") @exc.on_http_error(exc.GitlabGetError) - def list_ldap_group_links(self, **kwargs): + def list_ldap_group_links( + self, **kwargs: Any + ) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]: """List LDAP group links. Args: From 742f2bd6af55027b9a71e8b75a308f21d2588299 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Thu, 10 Nov 2022 16:06:45 +0000 Subject: [PATCH 5/7] fix(groups): making list_ldap_group_links use use http_list --- gitlab/v4/objects/groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index b1357299d..93321a18e 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -209,7 +209,7 @@ def list_ldap_group_links( GitlabGetError: If the server cannot perform the request """ path = f"/groups/{self.encoded_id}/ldap_group_links" - return self.manager.gitlab.http_get(path, **kwargs) + return self.manager.gitlab.http_list(path, **kwargs) @cli.register_custom_action("Group") @exc.on_http_error(exc.GitlabCreateError) From 5adc81c7913bae921a63d834d1adb01229775667 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Thu, 10 Nov 2022 21:27:02 +0000 Subject: [PATCH 6/7] fix(groups): adding unit test for list_ldap_group_sync --- tests/unit/objects/test_groups.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/objects/test_groups.py b/tests/unit/objects/test_groups.py index 6ca5cfe13..5d0a84d64 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, @@ -261,6 +269,19 @@ def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_grou assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"] +@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 + + @pytest.mark.skip("GitLab API endpoint not implemented") def test_refresh_group_export_status(group, resp_export): export = group.exports.create() From 6194085f9e4384b5fe2e39d2004715bd96b3a9e6 Mon Sep 17 00:00:00 2001 From: Ray Powell Date: Wed, 16 Nov 2022 15:19:52 +0000 Subject: [PATCH 7/7] fix(groups): adding unit test for list_ldap_group_sync - try 2 --- tests/unit/objects/test_groups.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/unit/objects/test_groups.py b/tests/unit/objects/test_groups.py index 5d0a84d64..5cba6dcee 100644 --- a/tests/unit/objects/test_groups.py +++ b/tests/unit/objects/test_groups.py @@ -224,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) @@ -269,17 +282,10 @@ def test_list_group_descendant_groups(group, resp_list_subgroups_descendant_grou assert descendant_groups[0].path == subgroup_descgroup_content[0]["path"] -@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_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")