Make email lookup case-insensitive

This commit is contained in:
Piotr F. Mieszkowski 2024-11-08 12:48:11 +01:00 committed by pfm
parent ea3eb7c09b
commit 82368f58c5
2 changed files with 11 additions and 2 deletions

View file

@ -11,7 +11,7 @@ class KeyCache:
With keyring_dir given, set location of the directory from which keys should be loaded.
"""
self._keys = keys
self._keys = { fpr: eml.upper() for (fpr, eml) in keys.items() }
def __getitem__(self, fingerpring):
"""Look up email assigned to the given fingerprint."""
@ -29,7 +29,7 @@ class KeyCache:
def has_email(self, email):
"""Check if cache contains a key assigned to the given email."""
return email in self._keys.values()
return email.upper() in self._keys.values()
def __repr__(self):
"""Return text representation of this object."""

View file

@ -18,3 +18,12 @@ class LacreKeyCacheTest(unittest.TestCase):
self.assertTrue(kc.has_email('bob@example.com'))
self.assertFalse(kc.has_email('dave@example.com'))
def test_case_insensitivity(self):
kc = KeyCache({
'FINGERPRINT': 'alice@example.com',
'OTHERPRINT': 'bob@example.com',
})
self.assertTrue(kc.has_email('Alice@example.com'))
self.assertTrue(kc.has_email('BOB@EXAMPLE.COM'))