@@ -0,0 +1,2494 @@
+#!/usr/bin/env python2%0Aimport unittest%0Afrom socket import *%0A%0Afrom common import *%0Afrom testdc import *%0A%0ACONFIG = %22%22%22%5C%0Amessagedirector:%0A    bind: 127.0.0.1:57123%0A%0Ageneral:%0A    dc_files:%0A        - %25r%0A%0Aroles:%0A    - type: clientagent%0A      bind: 127.0.0.1:57128%0A      version: %22Sword Art Online v5.1%22%0A%22%22%22 %25 test_dc%0AVERSION = 'Sword Art Online v5.1'%0A%0Aclass TestClientAgent(unittest.TestCase):%0A    @classmethod%0A    def setUpClass(cls):%0A        cls.daemon = Daemon(CONFIG)%0A        cls.daemon.start()%0A%0A        s = socket(AF_INET, SOCK_STREAM)%0A        s.connect(('127.0.0.1', 57123))%0A        cls.server = MDConnection(s)%0A%0A    @classmethod%0A    def tearDownClass(cls):%0A        cls.server.close()%0A        cls.daemon.stop()%0A%0A    def assertDisconnect(self, s, reason_code):%0A        while True:%0A            dg = s.recv()%0A            dgi = DatagramIterator(dg)%0A            if dgi.read_uint16() == CLIENT_GO_GET_LOST:%0A                self.assertEqual(dgi.read_uint16(), reason_code)%0A                s.close()%0A                return%0A%0A    def connect(self):%0A        s = socket(AF_INET, SOCK_STREAM)%0A        s.connect(('127.0.0.1', 57128))%0A        client = ClientConnection(s)%0A%0A        return client%0A%0A    def test_hello(self):%0A        # First, see if the CA ensures that the first datagram is a HELLO.%0A        client = self.connect()%0A        dg = Datagram()%0A        dg.add_uint16(5) # invalid msgtype%0A        client.send(dg)%0A        self.assertDisconnect(client, CLIENT_DISCONNECT_NO_HELLO)%0A%0A        # Next, see if the version gets validated:%0A        client = self.connect()%0A        dg = Datagram()%0A        dg.add_uint16(CLIENT_HELLO)%0A        dg.add_uint32(DC_HASH)%0A        dg.add_string('Equestria Online v5.7')%0A        client.send(dg)%0A        self.assertDisconnect(client, CLIENT_DISCONNECT_BAD_VERSION)%0A%0A        # Now dchash validation:%0A        client = self.connect()%0A        dg = Datagram()%0A        dg.add_uint16(CLIENT_HELLO)%0A        dg.add_uint32(0x12345678)%0A        dg.add_string(VERSION)%0A        client.send(dg)%0A        self.assertDisconnect(client, CLIENT_DISCONNECT_BAD_DCHASH)%0A%0A        # If everything is correct, it should simply allow us in:%0A        client = self.connect()%0A        dg = Datagram()%0A        dg.add_uint16(CLIENT_HELLO)%0A        dg.add_uint32(DC_HASH)%0A        dg.add_string(VERSION)%0A        client.send(dg)%0A        dg = Datagram()%0A        dg.add_uint16(CLIENT_HELLO_RESP)%0A        self.assertTrue(client.expect(dg))%0A%0A        client.close()%0A%0Aif __name__ == '__main__':%0A    unittest.main()%0A

Create clientagent unittest file, with test for CLIENT_HELLO behavior.