Esempio n. 1
0
def start_test_tcp_server(auth_token=None):
    MAX_NUM_PORT_ATTEMPTS = 10
    num_attempted_ports = 0
    server = None

    while(num_attempted_ports < MAX_NUM_PORT_ATTEMPTS):
        port = random.randint(8000, 65535)
        tcp_addr = 'tcp://127.0.0.1:%d' % port
        server = create_server(tcp_addr, auth_token)
        num_attempted_ports += 1

        try:
            server.start()
        except:
            # Occasionally we pick a port that's already in use.
            server.try_stop()
        else:
            break  # Success, port was not in use.

    assert(num_attempted_ports < MAX_NUM_PORT_ATTEMPTS)
    return server
Esempio n. 2
0
    def test_secure_communication(self, mock_logging):
        SERVER_PUBLIC_KEY = "Ee4##T$OmI4]hzyKqZT@H&Fixt95^.72&%MK!UR."
        SERVER_SECRET_KEY = "lIn2Szq0.mpPiB<N)t6fR2/4^4&wYnFs-x72HlTz"

        # Non-error case
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr, public_key=SERVER_PUBLIC_KEY, secret_key=SERVER_SECRET_KEY)
        server.start()
        glconnect.launch(server_addr=ipc_addr, server_public_key=SERVER_PUBLIC_KEY)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # Tests with bogus key
        BOGUS_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr, public_key=BOGUS_KEY, secret_key=SERVER_SECRET_KEY)
        try:
            server.start()
        except:
            pass
        else: 
            self.fail("Server started with bogus key.")
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr, public_key=SERVER_PUBLIC_KEY, secret_key=BOGUS_KEY)
        try:
            server.start()
        except:
            pass
        else: 
            self.fail("Server started with bogus key.")
Esempio n. 3
0
    def test_secure_communication(self, mock_logging):
        SERVER_PUBLIC_KEY = "Ee4##T$OmI4]hzyKqZT@H&Fixt95^.72&%MK!UR."
        SERVER_SECRET_KEY = "lIn2Szq0.mpPiB<N)t6fR2/4^4&wYnFs-x72HlTz"

        # Non-error case
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr,
                               public_key=SERVER_PUBLIC_KEY,
                               secret_key=SERVER_SECRET_KEY)
        server.start()
        glconnect.launch(server_addr=ipc_addr,
                         server_public_key=SERVER_PUBLIC_KEY)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # Tests with bogus key
        BOGUS_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr,
                               public_key=BOGUS_KEY,
                               secret_key=SERVER_SECRET_KEY)
        try:
            server.start()
        except:
            pass
        else:
            self.fail("Server started with bogus key.")
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        server = create_server(ipc_addr,
                               public_key=SERVER_PUBLIC_KEY,
                               secret_key=BOGUS_KEY)
        try:
            server.start()
        except:
            pass
        else:
            self.fail("Server started with bogus key.")