Exemplo n.º 1
0
async def test_udpsession_handle_packet(fake_udp_socket_manager):
    session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce",
                                0, None, fake_udp_socket_manager)
    session.action = 123
    session.transaction_id = 124
    assert not session.is_failed
    fake_udp_socket_manager.response = struct.pack("!iiq", 123, 124, 126)
    await session.connect()
    assert not session.is_failed
Exemplo n.º 2
0
 async 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)
     self.socket_mgr.response = struct.pack("!iiq", 123, 124, 126)
     await session.connect()
     self.assertFalse(session.is_failed)
Exemplo n.º 3
0
async def test_udpsession_mismatch(fake_udp_socket_manager):
    session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce",
                                0, None, fake_udp_socket_manager)
    session.action = 123
    session.transaction_id = 124
    session.infohash_list = [b'\x00' * 20]
    assert not session.is_failed
    fake_udp_socket_manager.response = struct.pack("!ii", 123, 124)
    with pytest.raises(ValueError):
        await session.scrape()
    assert session.is_failed
Exemplo n.º 4
0
 async def test_udpsession_response_list_len_mismatch(self):
     session = UdpTrackerSession("localhost", ("localhost", 4782),
                                 "/announce", 0, self.socket_mgr)
     session.action = 123
     session.transaction_id = 123
     self.assertFalse(session.is_failed)
     session._infohash_list = [b"test", b"test2"]
     self.socket_mgr.response = struct.pack("!iiiii", 123, 123, 0, 1, 2)
     with self.assertRaises(ValueError):
         await session.scrape()
     self.assertTrue(session.is_failed)
Exemplo n.º 5
0
async def test_udpsession_response_list_len_mismatch(fake_udp_socket_manager):
    session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce",
                                0, None, fake_udp_socket_manager)
    session.action = 123
    session.transaction_id = 123
    assert not session.is_failed
    session._infohash_list = [b"test", b"test2"]
    fake_udp_socket_manager.response = struct.pack("!iiiii", 123, 123, 0, 1, 2)
    with pytest.raises(ValueError):
        await session.scrape()
    assert session.is_failed
    await session.cleanup()
Exemplo n.º 6
0
async def test_udpsession_handle_response_wrong_len(fake_udp_socket_manager):
    session = UdpTrackerSession("localhost", ("localhost", 4782), "/announce",
                                0, None, fake_udp_socket_manager)
    assert not session.is_failed
    fake_udp_socket_manager.response = b"too short"
    with pytest.raises(ValueError):
        await session.connect()
    assert session.is_failed

    # After receiving a correct packet, it session should still be in a failed state
    session.action = 123
    session.transaction_id = 124
    fake_udp_socket_manager.response = struct.pack("!iiq", 123, 124, 126)
    await session.connect()
    assert session.is_failed
Exemplo n.º 7
0
    async def test_udpsession_handle_response_wrong_len(self):
        session = UdpTrackerSession("localhost", ("localhost", 4782),
                                    "/announce", 0, self.socket_mgr)
        self.assertFalse(session.is_failed)
        self.socket_mgr.response = b"too short"
        with self.assertRaises(ValueError):
            await session.connect()
        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
        self.socket_mgr.response = struct.pack("!iiq", 123, 124, 126)
        await session.connect()
        self.assertTrue(session.is_failed)