Ejemplo n.º 1
0
    def test_send(self):
        """
        test send_message() in class SenderSocketClient
        :return:
        """
        # send something to echo server, it should return the same thing
        Config.RETURN_MSG = HoneynetSocketUtil.RET_SUCCESS
        client = SenderSocketClient(self.server_addr)
        client.connect()
        self.assertTrue(client.is_connected)
        msg = "something"
        Config.RETURN_MSG = ""
        client.send_message(msg)
        ret_msg = client.sock.recv(Config.BUF_SIZE)

        self.assertEqual(msg, ret_msg)
        client.disconnect()
Ejemplo n.º 2
0
    def test_connect(self):
        """
        test client function connect() in class SenderSocketClient
        :return:
        """
        # test that the client successfully connects to a server which returns SUCCESS
        Config.RETURN_MSG = HoneynetSocketUtil.RET_SUCCESS
        client = SenderSocketClient(self.server_addr)
        self.assertFalse(client.is_connected)
        client.connect()
        self.assertTrue(client.is_connected)
        client.disconnect()
        self.assertFalse(client.is_connected)

        # test that the client fails to connect to a server which returns FAIL
        Config.RETURN_MSG = HoneynetSocketUtil.RET_FAIL
        client = SenderSocketClient(self.server_addr)
        self.assertFalse(client.is_connected)
        with self.assertRaises(HoneynetSocketExceptions.DenySenderException):
            client.connect()
        self.assertFalse(client.is_connected)

        # test that the client fails to connect to a server which returns unknown message
        Config.RETURN_MSG = "This is an unknown message!"
        client = SenderSocketClient(self.server_addr)
        self.assertFalse(client.is_connected)
        with self.assertRaises(HoneynetSocketExceptions.UnknownResponseException):
            client.connect()
        self.assertFalse(client.is_connected)