Пример #1
0
    def test05_unknown_ssl_server_timeout_raise(self):
        # result queue
        queue = Queue.Queue()
        # starting the server in a thread
        t = threading.Thread(target=build_ssl_server,
                             args=(
                                 queue,
                                 fail_crtfile_server,
                                 fail_keyfile_server,
                                 fail_pemfile_root,
                             ))
        t.start()

        # client connection
        connector = Connector(
            HOST,
            PORT,
            keyfile_client,
            crtfile_client,
        )
        client_sock = connector.connect()
        # sending some data
        client_sock.sendall("something")
        # geting the data received on server
        result = queue.get()
        print "test5 result: %s" % result
        self.assertEqual(result, "something")

        client_sock.close()
Пример #2
0
    def test02_establish_and_verify_sent_data_ssl(self):
        """A simple echo test with SSL authentification"""

        # result queue
        queue = Queue.Queue()
        # starting the server in a thread
        t = threading.Thread(target=build_ssl_server,
                             args=(
                                 queue,
                                 crtfile_server,
                                 keyfile_server,
                                 pemfile_root,
                             ))
        t.start()

        # client connection
        connector = Connector(
            HOST,
            PORT,
            keyfile_client,
            crtfile_client,
        )
        client_sock = connector.connect()
        # sending some data
        client_sock.sendall("something")
        # geting the data received on server
        result = queue.get()
        self.assertEqual(result, "something")

        client_sock.close()
Пример #3
0
    def test03_connection_refused(self):
        """ Test for catch ConnectionRefused exception. """

        connector = Connector(
            HOST,
            PORT,
            keyfile_client,
            crtfile_client,
        )

        self.assertRaises(ConnectionRefused, connector.connect)
Пример #4
0
    def test04_nossl_server_timeout_raise(self):
        """Try to serve no SSL service to SSL client"""

        timeout = 2

        with SimpleSocketServer(HOST, PORT):

            # client connection
            connector = Connector(
                HOST,
                PORT,
                keyfile_client,
                crtfile_client,
                timeout,
            )
            # because client is truing to connect to a server
            # without SSL authentification, client 2 seconds after
            # raises ConnectionTimeout exception
            self.assertRaises(ConnectionTimeout, connector.connect)
Пример #5
0
    def test01_establish_and_verify_sent_data_nossl(self):
        """A simple echo test without SSL authentification"""

        with SimpleSocketServer(HOST, PORT) as server:
            # establish a client connection
            connector = Connector(HOST, PORT)
            client_sock = connector.connect()

            client_sock.sendall("something")

            # server side
            client_connection, address = server.accept()
            # client_connection - client's socket on server side
            if client_connection:
                result = client_connection.recv(1024)
                client_connection.close()
                # compare with sent data
                self.assertEqual(result, "something")

            client_sock.close()