From 2a1b6673ffc96912322974cc85b93d13b6cd8e7c Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 28 Nov 2026 16:58:10 +0100 Subject: Simplify UDP scraper and prevent an incomplete 75th hash from being processed, adhering to the BEP now --- tests/integration/test_udp.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/integration/test_udp.py') diff --git a/tests/integration/test_udp.py b/tests/integration/test_udp.py index 1cb2389..3afe4ef 100644 --- a/tests/integration/test_udp.py +++ b/tests/integration/test_udp.py @@ -148,6 +148,28 @@ class UdpScrape(TrackerTestCase): finally: sock.close() + def test_a_hash_cut_short_is_not_scraped(self): + """What follows the last whole hash is not a hash, and the bytes that + would complete it are not the client's.""" + info_hash = self.hash_for("udpcut") + sock, connection_id = self.tracker.udp_connect() + try: + sock.sendto( + struct.pack(">QII", connection_id, 2, 3) + info_hash + b"\x00" * 7, ("127.0.0.1", self.tracker.port) + ) + self.assertEqual(len(sock.recv(2048)), 8 + 12) + finally: + sock.close() + + def test_a_scrape_answers_no_more_hashes_than_the_protocol_allows(self): + sock, connection_id = self.tracker.udp_connect() + try: + hashes = b"".join(self.hash_for("udpmany%d" % n) for n in range(80)) + sock.sendto(struct.pack(">QII", connection_id, 2, 4) + hashes, ("127.0.0.1", self.tracker.port)) + self.assertEqual(len(sock.recv(2048)), 8 + 12 * 74) + finally: + sock.close() + class UdpWorkersConfiguredAfterTheListener(TrackerTestCase): """The harness writes its listen lines first, so this directive lands -- cgit v1.3