store tokens in guid-directories

This commit is contained in:
holger krekel 2024-03-27 10:29:22 +01:00
parent c44f4efced
commit 1a2b73a862
2 changed files with 14 additions and 4 deletions

View File

@ -30,17 +30,22 @@ class Notifier:
def set_token(self, guid, token):
guid_path = self.metadata_dir.joinpath(guid)
write_path = guid_path.with_suffix(".tmp")
if not guid_path.exists():
guid_path.mkdir()
token_path = guid_path / "token"
write_path = token_path.with_suffix(".tmp")
write_path.write_text(token)
write_path.rename(guid_path)
write_path.rename(token_path)
def del_token(self, guid):
self.metadata_dir.joinpath(guid).unlink(missing_ok=True)
self.metadata_dir.joinpath(guid).joinpath("token").unlink(missing_ok=True)
def get_token(self, guid):
guid_path = self.metadata_dir / guid
if guid_path.exists():
return guid_path.read_text()
token_path = guid_path / "token"
if token_path.exists():
return token_path.read_text()
def new_message_for_guid(self, guid):
self.to_notify_queue.put(guid)

View File

@ -31,6 +31,11 @@ def test_notifier_persistence(tmp_path):
assert notifier1.get_token("guid00") is None
def test_notifier_delete_without_set(notifier):
notifier.del_token("guid00")
assert not notifier.get_token("guid00")
def test_handle_dovecot_request_lookup_fails(notifier):
res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier)
assert res == "N\n"