diff options
Diffstat (limited to 'tests/integration')
| -rw-r--r-- | tests/integration/test_announce.py | 15 | ||||
| -rw-r--r-- | tests/integration/test_udp.py | 33 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/integration/test_announce.py b/tests/integration/test_announce.py index ffbc07b..2d21417 100644 --- a/tests/integration/test_announce.py +++ b/tests/integration/test_announce.py | |||
| @@ -118,9 +118,24 @@ class AnnounceRejects(TrackerTestCase): | |||
| 118 | def test_a_port_out_of_range_is_rejected(self): | 118 | def test_a_port_out_of_range_is_rejected(self): |
| 119 | self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=65536&left=0") | 119 | self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=65536&left=0") |
| 120 | 120 | ||
| 121 | def test_a_negative_port_is_rejected(self): | ||
| 122 | self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=-1&left=0") | ||
| 123 | |||
| 121 | def test_a_port_that_is_not_a_number_is_rejected(self): | 124 | def test_a_port_that_is_not_a_number_is_rejected(self): |
| 122 | self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=abc&left=0") | 125 | self.assert_rejected("info_hash=" + "a" * 20 + "&peer_id=" + "b" * 20 + "&port=abc&left=0") |
| 123 | 126 | ||
| 127 | def test_an_ip_that_fills_the_reply_buffer_is_refused(self): | ||
| 128 | """The value is decoded into the reply buffer and then terminated, so | ||
| 129 | the longest one that fits has to leave room for the terminator. 8096 | ||
| 130 | bytes is what lies between where it is decoded and the buffer's end.""" | ||
| 131 | connection = self.tracker.connect() | ||
| 132 | try: | ||
| 133 | connection.sock.sendall(b"GET /a?ip=" + b"1" * 8096 + b"\n\n") | ||
| 134 | status, _, _ = connection.reply() | ||
| 135 | self.assertTrue(status.startswith(b"HTTP/1.0 400"), status) | ||
| 136 | finally: | ||
| 137 | connection.close() | ||
| 138 | |||
| 124 | def test_two_info_hashes_are_rejected(self): | 139 | def test_two_info_hashes_are_rejected(self): |
| 125 | self.assert_rejected("info_hash=" + "a" * 20 + "&info_hash=" + "c" * 20 + "&peer_id=" + "b" * 20 + "&port=6881&left=0") | 140 | self.assert_rejected("info_hash=" + "a" * 20 + "&info_hash=" + "c" * 20 + "&peer_id=" + "b" * 20 + "&port=6881&left=0") |
| 126 | 141 | ||
diff --git a/tests/integration/test_udp.py b/tests/integration/test_udp.py index 1cb2389..b60bd56 100644 --- a/tests/integration/test_udp.py +++ b/tests/integration/test_udp.py | |||
| @@ -44,6 +44,17 @@ class UdpProtocol(TrackerTestCase): | |||
| 44 | self.assertEqual(action, 3, "action 3 is the error packet") | 44 | self.assertEqual(action, 3, "action 3 is the error packet") |
| 45 | self.assertIn(b"Connection ID missmatch", answer[8:]) | 45 | self.assertIn(b"Connection ID missmatch", answer[8:]) |
| 46 | 46 | ||
| 47 | def test_a_wrong_connection_id_is_not_answered_with_more_than_was_sent(self): | ||
| 48 | """The sender's address is unverified at this point, so the error | ||
| 49 | must not be a way to throw bytes at somebody else.""" | ||
| 50 | scrape = struct.pack(">QII", 0, 2, 3) + self.hash_for("udpbadscrape") | ||
| 51 | answer = self.tracker.udp_raw(scrape) | ||
| 52 | self.assertIsNotNone(answer, "a whole scrape is long enough to be told") | ||
| 53 | self.assertLessEqual(len(answer), len(scrape)) | ||
| 54 | self.assertIsNone(self.tracker.udp_raw(scrape[:16])) | ||
| 55 | self.assertIsNone(self.tracker.udp_raw(scrape[: len(answer) - 1])) | ||
| 56 | self.assertIsNotNone(self.tracker.udp_raw(scrape[: len(answer)])) | ||
| 57 | |||
| 47 | def test_a_packet_shorter_than_the_header_is_ignored(self): | 58 | def test_a_packet_shorter_than_the_header_is_ignored(self): |
| 48 | self.assertIsNone(self.tracker.udp_raw(b"\x00" * 15)) | 59 | self.assertIsNone(self.tracker.udp_raw(b"\x00" * 15)) |
| 49 | 60 | ||
| @@ -148,6 +159,28 @@ class UdpScrape(TrackerTestCase): | |||
| 148 | finally: | 159 | finally: |
| 149 | sock.close() | 160 | sock.close() |
| 150 | 161 | ||
| 162 | def test_a_hash_cut_short_is_not_scraped(self): | ||
| 163 | """What follows the last whole hash is not a hash, and the bytes that | ||
| 164 | would complete it are not the client's.""" | ||
| 165 | info_hash = self.hash_for("udpcut") | ||
| 166 | sock, connection_id = self.tracker.udp_connect() | ||
| 167 | try: | ||
| 168 | sock.sendto( | ||
| 169 | struct.pack(">QII", connection_id, 2, 3) + info_hash + b"\x00" * 7, ("127.0.0.1", self.tracker.port) | ||
| 170 | ) | ||
| 171 | self.assertEqual(len(sock.recv(2048)), 8 + 12) | ||
| 172 | finally: | ||
| 173 | sock.close() | ||
| 174 | |||
| 175 | def test_a_scrape_answers_no_more_hashes_than_the_protocol_allows(self): | ||
| 176 | sock, connection_id = self.tracker.udp_connect() | ||
| 177 | try: | ||
| 178 | hashes = b"".join(self.hash_for("udpmany%d" % n) for n in range(80)) | ||
| 179 | sock.sendto(struct.pack(">QII", connection_id, 2, 4) + hashes, ("127.0.0.1", self.tracker.port)) | ||
| 180 | self.assertEqual(len(sock.recv(2048)), 8 + 12 * 74) | ||
| 181 | finally: | ||
| 182 | sock.close() | ||
| 183 | |||
| 151 | 184 | ||
| 152 | class UdpWorkersConfiguredAfterTheListener(TrackerTestCase): | 185 | class UdpWorkersConfiguredAfterTheListener(TrackerTestCase): |
| 153 | """The harness writes its listen lines first, so this directive lands | 186 | """The harness writes its listen lines first, so this directive lands |
