From bf8e0416db4d5094a3f4148671b2635f6f89d01a Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Tue, 3 Feb 2026 17:40:28 -0500 Subject: [PATCH 1/2] Fix LDAP search to include an optional trailing slash --- Rover_Lookup/lookup.py | 5 ++++- Rover_Lookup/tests/test_lookup.py | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Rover_Lookup/lookup.py b/Rover_Lookup/lookup.py index 00631a16..6f6be868 100644 --- a/Rover_Lookup/lookup.py +++ b/Rover_Lookup/lookup.py @@ -54,8 +54,11 @@ def github_username_to_emails( # Construct the LDAP filter to match the GitHub "Professional Social Media" URL. # The rhatSocialURL field contains values like "Github->https://github.com/username". + # However, 5% of the entries include a trailing slash (which GitHub accepts), + # so look for those, too. github_url = f"https://github.com/{github_username}" - ldap_filter = f"(rhatSocialURL=Github->{github_url})" + filter_clause = f"rhatSocialURL=Github->{github_url}" + ldap_filter = f"(|({filter_clause}) ({filter_clause}/))" # Attributes to retrieve (email fields) attributes = ["rhatPrimaryMail", "mail", "rhatPreferredAlias"] diff --git a/Rover_Lookup/tests/test_lookup.py b/Rover_Lookup/tests/test_lookup.py index 43efd2d3..3b10e705 100644 --- a/Rover_Lookup/tests/test_lookup.py +++ b/Rover_Lookup/tests/test_lookup.py @@ -72,10 +72,9 @@ def test_successful_lookup_single_record(self, mock_connection_class, caplog): # Verify LDAP query was called correctly mock_conn.search.assert_called_once() search_args = mock_conn.search.call_args - assert ( - search_args[1]["search_filter"] - == "(rhatSocialURL=Github->https://github.com/test-user)" - ) + filter_part = "rhatSocialURL=Github->https://github.com/test-user" + expected_filter = f"(|({filter_part}) ({filter_part}/))" + assert search_args[1]["search_filter"] == expected_filter assert "rhatPrimaryMail" in search_args[1]["attributes"] assert "mail" in search_args[1]["attributes"] assert "rhatPreferredAlias" in search_args[1]["attributes"] From 538ee274ce27a7542ad16c546188c9bcf2bfce16 Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Tue, 3 Feb 2026 18:31:31 -0500 Subject: [PATCH 2/2] Code review feedback --- Rover_Lookup/lookup.py | 2 +- Rover_Lookup/tests/test_lookup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Rover_Lookup/lookup.py b/Rover_Lookup/lookup.py index 6f6be868..454e4452 100644 --- a/Rover_Lookup/lookup.py +++ b/Rover_Lookup/lookup.py @@ -58,7 +58,7 @@ def github_username_to_emails( # so look for those, too. github_url = f"https://github.com/{github_username}" filter_clause = f"rhatSocialURL=Github->{github_url}" - ldap_filter = f"(|({filter_clause}) ({filter_clause}/))" + ldap_filter = f"(|({filter_clause})({filter_clause}/))" # Attributes to retrieve (email fields) attributes = ["rhatPrimaryMail", "mail", "rhatPreferredAlias"] diff --git a/Rover_Lookup/tests/test_lookup.py b/Rover_Lookup/tests/test_lookup.py index 3b10e705..d2edc863 100644 --- a/Rover_Lookup/tests/test_lookup.py +++ b/Rover_Lookup/tests/test_lookup.py @@ -73,7 +73,7 @@ def test_successful_lookup_single_record(self, mock_connection_class, caplog): mock_conn.search.assert_called_once() search_args = mock_conn.search.call_args filter_part = "rhatSocialURL=Github->https://github.com/test-user" - expected_filter = f"(|({filter_part}) ({filter_part}/))" + expected_filter = f"(|({filter_part})({filter_part}/))" assert search_args[1]["search_filter"] == expected_filter assert "rhatPrimaryMail" in search_args[1]["attributes"] assert "mail" in search_args[1]["attributes"]