def test_udpsession_handle_response_wrong_len(self): session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce", 5) session.on_ip_address_resolved("127.0.0.1", start_scraper=False) self.assertFalse(session.is_failed) session.handle_connection_response("too short") self.assertTrue(session.is_failed)
def test_udpsession_handle_wrong_action_transaction(self): session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce", 0, self.socket_mgr) session.on_ip_address_resolved("127.0.0.1", start_scraper=None) self.assertFalse(session.is_failed) packet = struct.pack("!qq4s", 123, 123, "test") session.handle_connection_response(packet) self.assertTrue(session.is_failed)
def test_udpsession_handle_packet(self): session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce", 0, self.socket_mgr) session.action = 123 session.transaction_id = 124 self.assertFalse(session.is_failed) packet = struct.pack("!iiq", 123, 124, 126) session.handle_connection_response(packet) self.assertFalse(session.is_failed)
def test_udpsession_handle_response_wrong_len(self): session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce", 0, self.socket_mgr) session.on_ip_address_resolved("127.0.0.1") self.assertFalse(session.is_failed) session.handle_connection_response("too short") self.assertTrue(session.is_failed) # After receiving a correct packet, it session should still be in a failed state session.action = 123 session.transaction_id = 124 packet = struct.pack("!iiq", 123, 124, 126) session.handle_response(packet) self.assertTrue(session.expect_connection_response) self.assertTrue(session.is_failed)