Skip to content

Commit 035e5ce

Browse files
Fix LDAP search to include an optional trailing slash (#417)
* Fix LDAP search to include an optional trailing slash * Code review feedback --------- Co-authored-by: Bala-Sakabattula <bsakabat@redhat.com>
1 parent 0a2303f commit 035e5ce

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Rover_Lookup/lookup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ def github_username_to_emails(
5454

5555
# Construct the LDAP filter to match the GitHub "Professional Social Media" URL.
5656
# The rhatSocialURL field contains values like "Github->https://github.com/username".
57+
# However, 5% of the entries include a trailing slash (which GitHub accepts),
58+
# so look for those, too.
5759
github_url = f"https://github.com/{github_username}"
58-
ldap_filter = f"(rhatSocialURL=Github->{github_url})"
60+
filter_clause = f"rhatSocialURL=Github->{github_url}"
61+
ldap_filter = f"(|({filter_clause})({filter_clause}/))"
5962

6063
# Attributes to retrieve (email fields)
6164
attributes = ["rhatPrimaryMail", "mail", "rhatPreferredAlias"]

Rover_Lookup/tests/test_lookup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ def test_successful_lookup_single_record(self, mock_connection_class, caplog):
7272
# Verify LDAP query was called correctly
7373
mock_conn.search.assert_called_once()
7474
search_args = mock_conn.search.call_args
75-
assert (
76-
search_args[1]["search_filter"]
77-
== "(rhatSocialURL=Github->https://github.com/test-user)"
78-
)
75+
filter_part = "rhatSocialURL=Github->https://github.com/test-user"
76+
expected_filter = f"(|({filter_part})({filter_part}/))"
77+
assert search_args[1]["search_filter"] == expected_filter
7978
assert "rhatPrimaryMail" in search_args[1]["attributes"]
8079
assert "mail" in search_args[1]["attributes"]
8180
assert "rhatPreferredAlias" in search_args[1]["attributes"]

0 commit comments

Comments
 (0)