예제 #1
0
 def test_receive(self):
     """
     test receive_message() in class ReceiverSocketClient
     :return:
     """
     # send something to custom server, it should return the customized string
     Config.RETURN_MSG = [HoneynetSocketUtil.RET_SUCCESS, Config.CUSTOM_MSG]
     client = ReceiverSocketClient(self.server_addr)
     client.connect()
     self.assertTrue(client.is_connected)
     self.assertEqual(client.receive_message(), Config.CUSTOM_MSG)
     client.disconnect()
예제 #2
0
    def test_connect(self):
        """
        test client function connect() in class ReceiverSocketClient
        :return:
        """
        # test that the client successfully connects to a server which returns SUCCESS
        Config.RETURN_MSG = HoneynetSocketUtil.RET_SUCCESS
        client = ReceiverSocketClient(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 = ReceiverSocketClient(self.server_addr)
        self.assertFalse(client.is_connected)
        with self.assertRaises(HoneynetSocketExceptions.DenyReceiverException):
            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 = ReceiverSocketClient(self.server_addr)
        self.assertFalse(client.is_connected)
        with self.assertRaises(HoneynetSocketExceptions.UnknownResponseException):
            client.connect()
        self.assertFalse(client.is_connected)