diff --git a/Rover_Lookup/lookup.py b/Rover_Lookup/lookup.py index 00631a16..454e4452 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..d2edc863 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"]