mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 12:28:06 +00:00
store tokens in guid-directories
This commit is contained in:
@@ -30,17 +30,22 @@ class Notifier:
|
|||||||
|
|
||||||
def set_token(self, guid, token):
|
def set_token(self, guid, token):
|
||||||
guid_path = self.metadata_dir.joinpath(guid)
|
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.write_text(token)
|
||||||
write_path.rename(guid_path)
|
write_path.rename(token_path)
|
||||||
|
|
||||||
def del_token(self, guid):
|
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):
|
def get_token(self, guid):
|
||||||
guid_path = self.metadata_dir / guid
|
guid_path = self.metadata_dir / guid
|
||||||
if guid_path.exists():
|
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):
|
def new_message_for_guid(self, guid):
|
||||||
self.to_notify_queue.put(guid)
|
self.to_notify_queue.put(guid)
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ def test_notifier_persistence(tmp_path):
|
|||||||
assert notifier1.get_token("guid00") is None
|
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):
|
def test_handle_dovecot_request_lookup_fails(notifier):
|
||||||
res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier)
|
res = handle_dovecot_request("Lpriv/123/chatmail", {}, notifier)
|
||||||
assert res == "N\n"
|
assert res == "N\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user