diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-05 16:03:35 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-05 16:03:35 +0100 |
| commit | 2a7bc3f8a7cd232cad0a858b4d810a2cac3193d8 (patch) | |
| tree | 068ba4de5c5672bafea62f85a56fde788bbd23c6 /tests | |
| parent | 4e0b179014ced8c16c90bdfd6d82df625fea47e9 (diff) | |
Read the accesslist before any consumer consults it
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/integration/test_accesslist.py | 24 |
1 files changed, 23 insertions, 1 deletions
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 | |||
| 5 | produces: an empty file, and a last line with no newline after it. | 5 | produces: an empty file, and a last line with no newline after it. |
| 6 | """ | 6 | """ |
| 7 | 7 | ||
| 8 | import os | ||
| 8 | import struct | 9 | import struct |
| 9 | import unittest | 10 | import unittest |
| 10 | 11 | ||
| 11 | from harness import TrackerTestCase | 12 | from harness import Tracker, TrackerTestCase |
| 12 | 13 | ||
| 13 | BLOCKED = b"\xb1" * 20 | 14 | BLOCKED = b"\xb1" * 20 |
| 14 | ALLOWED = b"\xa1" * 20 | 15 | ALLOWED = b"\xa1" * 20 |
| @@ -96,5 +97,26 @@ class MissingBlacklist(TrackerTestCase): | |||
| 96 | self.assertEqual(self.tracker.announce(BLOCKED, port=6881, left=0)[b"complete"], 1) | 97 | self.assertEqual(self.tracker.announce(BLOCKED, port=6881, left=0)[b"complete"], 1) |
| 97 | 98 | ||
| 98 | 99 | ||
| 100 | class ListIsInPlaceBeforeTheStateFile(TrackerTestCase): | ||
| 101 | """The loader used to run in a thread of its own, so a state file read at | ||
| 102 | startup was checked against a list that was still empty.""" | ||
| 103 | |||
| 104 | config = "access.blacklist {dir}/blacklist\n" | ||
| 105 | files = {"blacklist": listing(BLOCKED)} | ||
| 106 | |||
| 107 | def test_a_blacklisted_torrent_in_a_state_file_is_not_restored(self): | ||
| 108 | path = os.path.join(self.tracker.dir, "state") | ||
| 109 | with open(path, "w") as handle: | ||
| 110 | handle.write("%s:5:7\n%s:5:7\n" % (BLOCKED.hex(), ALLOWED.hex())) | ||
| 111 | |||
| 112 | restarted = Tracker(self.config, self.files, extra_args=["-l", path]) | ||
| 113 | try: | ||
| 114 | self.assertNotIn(BLOCKED, restarted.scrape(BLOCKED)[b"files"], "the blacklist was not in place when the state file was read") | ||
| 115 | self.assertIn(ALLOWED, restarted.scrape(ALLOWED)[b"files"], "the state file was not read at all") | ||
| 116 | restarted.stop() | ||
| 117 | finally: | ||
| 118 | restarted._cleanup() | ||
| 119 | |||
| 120 | |||
| 99 | if __name__ == "__main__": | 121 | if __name__ == "__main__": |
| 100 | unittest.main() | 122 | unittest.main() |
