From 2a7bc3f8a7cd232cad0a858b4d810a2cac3193d8 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Thu, 5 Nov 2026 16:03:35 +0100 Subject: Read the accesslist before any consumer consults it --- tests/integration/test_accesslist.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/integration') diff --git a/tests/integration/test_accesslist.py b/tests/integration/test_accesslist.py index 41ff654..1c84ccf 100644 --- a/tests/integration/test_accesslist.py +++ b/tests/integration/test_accesslist.py @@ -5,10 +5,11 @@ entry, and the file parser has to cope with the shapes an operator actually produces: an empty file, and a last line with no newline after it. """ +import os import struct import unittest -from harness import TrackerTestCase +from harness import Tracker, TrackerTestCase BLOCKED = b"\xb1" * 20 ALLOWED = b"\xa1" * 20 @@ -96,5 +97,26 @@ class MissingBlacklist(TrackerTestCase): self.assertEqual(self.tracker.announce(BLOCKED, port=6881, left=0)[b"complete"], 1) +class ListIsInPlaceBeforeTheStateFile(TrackerTestCase): + """The loader used to run in a thread of its own, so a state file read at + startup was checked against a list that was still empty.""" + + config = "access.blacklist {dir}/blacklist\n" + files = {"blacklist": listing(BLOCKED)} + + def test_a_blacklisted_torrent_in_a_state_file_is_not_restored(self): + path = os.path.join(self.tracker.dir, "state") + with open(path, "w") as handle: + handle.write("%s:5:7\n%s:5:7\n" % (BLOCKED.hex(), ALLOWED.hex())) + + restarted = Tracker(self.config, self.files, extra_args=["-l", path]) + try: + self.assertNotIn(BLOCKED, restarted.scrape(BLOCKED)[b"files"], "the blacklist was not in place when the state file was read") + self.assertIn(ALLOWED, restarted.scrape(ALLOWED)[b"files"], "the state file was not read at all") + restarted.stop() + finally: + restarted._cleanup() + + if __name__ == "__main__": unittest.main() -- cgit v1.3