def _test_transport(self, transport, server_addr, ssl=False): transport, protocol = run( turn.create_turn_endpoint( DummyClientProtocol, server_addr=server_addr, username="******", password="******", lifetime=6, ssl=ssl, transport=transport, ) ) self.assertIsNone(transport.get_extra_info("peername")) self.assertIsNotNone(transport.get_extra_info("sockname")) # send ping, expect pong transport.sendto(b"ping", self.echo_server.udp_address) run(asyncio.sleep(1)) self.assertEqual(protocol.received_addr, self.echo_server.udp_address) self.assertEqual(protocol.received_data, b"ping") # wait some more to allow allocation refresh run(asyncio.sleep(5)) # close transport.close() run(asyncio.sleep(0))
def test_transport(self): transport, protocol = run(turn.create_turn_endpoint( DummyClientProtocol, server_addr=self.server_addr, username='******', password='******', lifetime=6)) self.assertEqual(transport.get_extra_info('peername'), None) self.assertEqual(transport.get_extra_info('sockname'), ('1.2.3.4', 1234)) run(asyncio.sleep(10)) self.assertEqual(protocol.received_addr, ('8.8.8.8', 53)) self.assertEqual(protocol.received_data, b'pong') transport.close()
def _test_transport_allocate_failure(self, transport, server_addr, ssl): # make the server reject the ALLOCATE request self.turn_server.simulated_failure = (403, "Forbidden") with self.assertRaises(stun.TransactionFailed) as cm: run( turn.create_turn_endpoint( DummyClientProtocol, server_addr=server_addr, username="******", password="******", ssl=ssl, transport=transport, )) self.assertEqual(str(cm.exception), "STUN transaction failed (403 - Forbidden)")
def _test_transport_delete_failure(self, transport, server_addr, ssl): transport, protocol = run( turn.create_turn_endpoint( DummyClientProtocol, server_addr=server_addr, username="******", password="******", ssl=ssl, transport=transport, )) self.assertIsNone(transport.get_extra_info("peername")) self.assertIsNotNone(transport.get_extra_info("sockname")) # make the server reject the final REFRESH request self.turn_server.simulated_failure = (403, "Forbidden") # close client transport.close() run(asyncio.sleep(0))