def test_send_incorrect_state_request(self): conn = Connection(our_role="server") conn._conn.machine.set_state("request") event = GreetingRequest((AUTH_TYPE["NO_AUTH"], )) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_incorrect_state_response(self): conn = Connection(our_role="client") conn._conn.machine.set_state("response") event = GreetingResponse(AUTH_TYPE["NO_AUTH"]) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_with_unsupported_auth(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 5 conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]] event = GreetingResponse(AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]) conn.send(event) self.assertEqual(conn._conn.state, "end")
def test_send_greeting_response_with_valid_auth(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 5 conn._conn._auth_methods = [AUTH_TYPE["USERNAME_PASSWD"]] event = GreetingResponse(AUTH_TYPE["USERNAME_PASSWD"]) conn.send(event) self.assertEqual(conn._conn.state, "auth_inprogress")
def test_send_greeting_response_socks4_with_incorrect_event_detail_verion(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 4 conn._conn._port = 5580 event = GreetingResponse(AUTH_TYPE["NO_AUTH"]) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_socks4_with_incorrect_event_detail_port(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 4 conn._conn._port = 5580 event = Socks4Response(0x5a, "127.0.0.1", 5581) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_with_incorrect_event_detail_auth_type(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 5 conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]] event = GreetingResponse(AUTH_TYPE["NO_AUTH"]) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_with_incorrect_event_detail_version(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 5 conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]] event = Socks4Response(0x5a, "127.0.0.1", 5580) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_socks4_with_incorrect_event_detail_port( self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 4 conn._conn._port = 5580 event = Socks4Response(0x5a, "127.0.0.1", 5581) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_greeting_response_socks4_with_incorrect_event_detail_verion( self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 4 conn._conn._port = 5580 event = GreetingResponse(AUTH_TYPE["NO_AUTH"]) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_response_with_incorrect_event_detail_port(self): conn = Connection(our_role="server") conn._conn.machine.set_state("response") conn._conn._version = 5 conn._conn._addr_type = ADDR_TYPE["IPV4"] conn._conn._addr = ipaddress.IPv4Address("127.0.0.1") conn._conn._port = 8080 event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"], "127.0.0.1", 5580) with self.assertRaises(ProtocolError): conn.send(event)
def test_send_in_greeting_request_socks4(self): conn = Connection(our_role="client") conn._conn.machine.set_state("greeting_request") event = Socks4Request(1, "127.0.0.1", 5580, "Johnny") data = conn.send(event) expected_data = struct.pack("!BBH4B6sB", 0x4, 0x1, 5580, 127, 0, 0, 1, "Johnny".encode("ascii"), 0) self.assertEqual(conn._conn.state, "greeting_response") self.assertEqual(data, expected_data)
def test_send_in_request_request(self): conn = Connection(our_role="client") conn._conn.machine.set_state("request") event = Request(REQ_COMMAND["CONNECT"], ADDR_TYPE["IPV4"], u"127.0.0.1", 8080) data = conn.send(event) expected_data = struct.pack("!BBxB4BH", 0x5, 0x1, 0x1, 127, 0, 0, 1, 8080) self.assertEqual(conn._conn.state, "response") self.assertEqual(data, expected_data)
def test_send_in_greeting_request(self): conn = Connection(our_role="client") conn._conn.machine.set_state("greeting_request") event = GreetingRequest((AUTH_TYPE["NO_AUTH"], )) data = conn.send(event) expected_data = struct.pack("!BBB", 0x5, 0x1, 0x00) self.assertEqual(conn._conn.state, "greeting_response") self.assertEqual(data, expected_data)
def test_send_greeting_response_no_auth(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 5 conn._conn._auth_methods = [AUTH_TYPE["NO_AUTH"]] event = GreetingResponse(AUTH_TYPE["NO_AUTH"]) data = conn.send(event) expected_data = struct.pack("!BB", 0x5, 0x0) self.assertEqual(conn._conn.state, "request") self.assertEqual(data, expected_data)
def test_send_greeting_response_socks4(self): conn = Connection(our_role="server") conn._conn.machine.set_state("greeting_response") conn._conn._version = 4 conn._conn._port = 5580 event = Socks4Response(0x5a, "127.0.0.1", 5580) data = conn.send(event) expected_data = struct.pack("!BBH4B", 0, 0x5a, 5580, 127, 0, 0, 1) self.assertEqual(conn._conn.state, "end") self.assertEqual(data, expected_data)
def test_send_response(self): conn = Connection(our_role="server") conn._conn.machine.set_state("response") conn._conn._version = 5 conn._conn._addr_type = ADDR_TYPE["IPV4"] conn._conn._addr = ipaddress.IPv4Address("127.0.0.1") conn._conn._port = 8080 event = Response(RESP_STATUS["SUCCESS"], ADDR_TYPE["IPV4"], "127.0.0.1", 8080) data = conn.send(event) expected_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 1, 8080) self.assertEqual(conn._conn.state, "end") self.assertEqual(data, expected_data)