Example #1
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.")
Example #2
0
 def setUpClass(self):
     glconnect.stop()
     auth_token = 'graphlab_awesome'
     self.server = start_test_tcp_server(auth_token=auth_token)
     glconnect.launch(self.server.get_server_addr(), auth_token=auth_token)
     self.tempfile = tempfile.NamedTemporaryFile().name
     (self.graph, self.sframe, self.model) = create_test_objects()
Example #3
0
    def test_launch_to_tcp(self):
        auth_token = 'graphlab_awesome'
        tcp_server = start_test_tcp_server(auth_token)

        #launch with remote server tcp address
        glconnect.launch(tcp_server.get_server_addr(), auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(), server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        tcp_server.stop()
Example #4
0
    def test_launch_to_tcp(self):
        auth_token = 'graphlab_awesome'
        tcp_server = start_test_tcp_server(auth_token)

        #launch with remote server tcp address
        glconnect.launch(tcp_server.get_server_addr(), auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(),
                                   server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        tcp_server.stop()
Example #5
0
    def test_launch_to_ipc(self):
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        auth_token = 'graphlab_awesome'
        ipc_server = create_server(ipc_addr, auth_token)
        ipc_server.start()
        #default local launch
        glconnect.launch()
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with remote server ipc address
        glconnect.launch(ipc_addr, auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(),
                                   server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with remote server addr, and server_bin(ignored)
        glconnect.launch(ipc_addr,
                         os.getenv("GRAPHLAB_UNITY"),
                         auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(),
                                   server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        ipc_server.stop()
Example #6
0
    def test_launch_to_ipc(self):
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        auth_token = 'graphlab_awesome'
        ipc_server = create_server(ipc_addr, auth_token)
        ipc_server.start()
        #default local launch
        glconnect.launch()
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with remote server ipc address
        glconnect.launch(ipc_addr, auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(), server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with remote server addr, and server_bin(ignored)
        glconnect.launch(ipc_addr, os.getenv("GRAPHLAB_UNITY"), auth_token=auth_token)
        self.assertTrue(glconnect.is_connected())
        self.assertTrue(isinstance(glconnect.get_server(), server.RemoteServer))
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        ipc_server.stop()
Example #7
0
    def test_launch(self):
        #default launch
        glconnect.launch()
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with server address
        tmpname = tempfile.NamedTemporaryFile().name
        tmpaddr = 'ipc://' + tmpname
        glconnect.launch(tmpaddr)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        #check that the ipc file gets deleted
        self.assertFalse(os.path.exists(tmpname))

        #launch address and binary
        graphlab_bin = os.getenv("GRAPHLAB_UNITY")
        glconnect.launch(server_addr=tmpaddr,
                         server_bin=graphlab_bin)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        self.assertFalse(os.path.exists(tmpname))
Example #8
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.")
Example #9
0
    def test_launch_with_exception(self, mock_logging):
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        auth_token = 'graphlab_awesome'
        ipc_server = create_server(ipc_addr, auth_token)
        ipc_server.start()

        #default launch without stopping
        glconnect.launch(server_addr=ipc_addr)
        glconnect.launch()
        self.assertTrue(mock_logging.warning.called_once_with(SubstringMatcher(containing="existing server")))
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server path (path is not listend by server)
        with tempfile.NamedTemporaryFile() as f:
            glconnect.launch(server_addr=('ipc://' + f.name))
            self.assertTrue(mock_logging.warning.called_once_with(SubstringMatcher(containing="communication failure")))
            self.assertFalse(glconnect.is_connected())
Example #10
0
    def test_launch_with_exception(self, mock_logging):
        ipc_addr = 'ipc://' + tempfile.NamedTemporaryFile().name
        auth_token = 'graphlab_awesome'
        ipc_server = create_server(ipc_addr, auth_token)
        ipc_server.start()

        #default launch without stopping
        glconnect.launch(server_addr=ipc_addr)
        glconnect.launch()
        self.assertTrue(
            mock_logging.warning.called_once_with(
                SubstringMatcher(containing="existing server")))
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server path (path is not listend by server)
        with tempfile.NamedTemporaryFile() as f:
            glconnect.launch(server_addr=('ipc://' + f.name))
            self.assertTrue(
                mock_logging.warning.called_once_with(
                    SubstringMatcher(containing="communication failure")))
            self.assertFalse(glconnect.is_connected())
Example #11
0
    def test_launch(self):
        #default launch
        glconnect.launch()
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        #launch with server address
        tmpname = tempfile.NamedTemporaryFile().name
        tmpaddr = 'ipc://' + tmpname
        glconnect.launch(tmpaddr)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        #check that the ipc file gets deleted
        self.assertFalse(os.path.exists(tmpname))

        #launch address and binary
        graphlab_bin = os.getenv("GRAPHLAB_UNITY")
        glconnect.launch(server_addr=tmpaddr, server_bin=graphlab_bin)
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())
        self.assertFalse(os.path.exists(tmpname))
Example #12
0
    def test_launch_with_exception(self, mock_logging):
        # Assert warning logged when launching without stopping
        glconnect.launch()
        glconnect.launch()
        self.assertTrue(
            mock_logging.warning.called_once_with(
                SubstringMatcher(containing="existing server")))
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server binary (path is not executable)
        with tempfile.NamedTemporaryFile() as f:
            random_server_bin = f.name
            glconnect.launch(server_bin=random_server_bin)
            self.assertTrue(
                mock_logging.error.called_once_with(
                    SubstringMatcher(containing="Invalid server binary")))
            self.assertFalse(glconnect.is_connected())

        #launch with server address without permission
        tmpaddr = 'ipc:///root/bad_server'
        glconnect.launch(tmpaddr)
        self.assertTrue(
            mock_logging.warning.called_once_with(
                SubstringMatcher(containing="communication error")))
        self.assertFalse(glconnect.is_connected())
        glconnect.stop()

        # launch with binary that does not exist
        tmpname = tempfile.NamedTemporaryFile().name
        glconnect.launch(server_bin=tmpname)
        self.assertTrue(
            mock_logging.error.called_once_with(
                SubstringMatcher(containing="Invalid server binary")))
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server binary (path is a faked executable)
        with tempfile.NamedTemporaryFile() as f:
            os.chmod(f.name, stat.S_IXUSR)
            random_server_bin = f.name
            glconnect.launch(server_bin=random_server_bin)
            self.assertTrue(
                mock_logging.error.called_once_with(
                    SubstringMatcher(containing="Invalid server binary")))
            self.assertFalse(glconnect.is_connected())
Example #13
0
    def test_launch_with_exception(self, mock_logging):
        # Assert warning logged when launching without stopping
        glconnect.launch()
        glconnect.launch()
        self.assertTrue(mock_logging.warning.called_once_with(SubstringMatcher(containing="existing server")))
        self.assertTrue(glconnect.is_connected())
        glconnect.stop()
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server binary (path is not executable)
        with tempfile.NamedTemporaryFile() as f:
            random_server_bin = f.name
            glconnect.launch(server_bin=random_server_bin)
            self.assertTrue(mock_logging.error.called_once_with(SubstringMatcher(containing="Invalid server binary")))
            self.assertFalse(glconnect.is_connected())

        #launch with server address without permission
        tmpaddr = 'ipc:///root/bad_server'
        glconnect.launch(tmpaddr)
        self.assertTrue(mock_logging.warning.called_once_with(SubstringMatcher(containing="communication error")))
        self.assertFalse(glconnect.is_connected())
        glconnect.stop()

        # launch with binary that does not exist
        tmpname = tempfile.NamedTemporaryFile().name
        glconnect.launch(server_bin=tmpname)
        self.assertTrue(mock_logging.error.called_once_with(SubstringMatcher(containing="Invalid server binary")))
        self.assertFalse(glconnect.is_connected())

        # launch with bogus server binary (path is a faked executable)
        with tempfile.NamedTemporaryFile() as f:
            os.chmod(f.name, stat.S_IXUSR)
            random_server_bin = f.name
            glconnect.launch(server_bin=random_server_bin)
            self.assertTrue(mock_logging.error.called_once_with(SubstringMatcher(containing="Invalid server binary")))
            self.assertFalse(glconnect.is_connected())