How to use websockify - 10 common examples

To help you get started, we’ve selected a few websockify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github novnc / websockify / tests / test_websocket.py View on Github external
def test_start_server_systemexit(self):
        websocket.ssl = None
        self.stubs.Set(websocket.WebSocketServer, 'socket', self._mock_socket)
        self.stubs.Set(websocket.WebSocketServer, 'daemonize',
                       lambda *args, **kwargs: None)
        self.stubs.Set(select, 'select', self._mock_select_systemexit)
        soc = self._get_websockserver(daemon=True, ssl_only=0, idle_timeout=1,
                                      verbose=True)
        self.assertEqual(None, soc.start_server())
github novnc / websockify / tests / test_websockifyserver.py View on Github external
def test_empty_handshake_fails(self):
        server = self._get_server(daemon=True, ssl_only=0, idle_timeout=1)

        sock = FakeSocket('')

        def fake_select(rlist, wlist, xlist, timeout=None):
            return ([sock], [], [])

        self.stubs.Set(select, 'select', fake_select)
        self.assertRaises(
            websockifyserver.WebSockifyServer.EClose, server.do_handshake,
            sock, '127.0.0.1')
github novnc / websockify / tests / test_websockifyserver.py View on Github external
def _get_server(self, handler_class=websockifyserver.WebSockifyRequestHandler,
                    **kwargs):
        return websockifyserver.WebSockifyServer(
            handler_class, listen_host='localhost',
            listen_port=80, key=self.tmpdir, web=self.tmpdir,
            record=self.tmpdir, **kwargs)
github novnc / websockify / tests / load.py View on Github external
def __init__(self, *args, **kwargs):
        self.delay = kwargs.pop('delay')

        WebSockifyServer.__init__(self, *args, **kwargs)
github novnc / websockify / tests / test_websocketproxy.py View on Github external
def setUp(self):
        super(ProxyRequestHandlerTestCase, self).setUp()
        self.stubs = stubout.StubOutForTesting()
        self.handler = websocketproxy.ProxyRequestHandler(
            FakeSocket(''), "127.0.0.1", FakeServer())
        self.handler.path = "https://localhost:6080/websockify?token=blah"
        self.handler.headers = None
        self.stubs.Set(websockifyserver.WebSockifyServer, 'socket',
                       staticmethod(lambda *args, **kwargs: None))
github novnc / websockify / tests / test_websockifyserver.py View on Github external
    def _get_server(self, handler_class=websockifyserver.WebSockifyRequestHandler,
                    **kwargs):
        return websockifyserver.WebSockifyServer(
            handler_class, listen_host='localhost',
            listen_port=80, key=self.tmpdir, web=self.tmpdir,
            record=self.tmpdir, **kwargs)
github novnc / websockify / tests / test_websockifyserver.py View on Github external
def test_start_server_error(self):
        server = self._get_server(daemon=False, ssl_only=1, idle_timeout=1)
        sock = server.socket('localhost')

        def fake_select(rlist, wlist, xlist, timeout=None):
            raise Exception("fake error")

        self.stubs.Set(websockifyserver.WebSockifyServer, 'socket',
                       lambda *args, **kwargs: sock)
        self.stubs.Set(websockifyserver.WebSockifyServer, 'daemonize',
                       lambda *args, **kwargs: None)
        self.stubs.Set(select, 'select', fake_select)
        server.start_server()
github novnc / websockify / tests / test_websocketproxy.py View on Github external
def test_auth_plugin(self):
        class TestPlugin(auth_plugins.BasePlugin):
            def authenticate(self, headers, target_host, target_port):
                if target_host == self.source:
                    raise auth_plugins.AuthenticationError(response_msg="some_error")

        self.stubs.Set(websocketproxy.ProxyRequestHandler, 'send_auth_error',
                       staticmethod(lambda *args, **kwargs: None))

        self.handler.server.auth_plugin = TestPlugin("somehost")
        self.handler.server.target_host = "somehost"
        self.handler.server.target_port = "someport"

        self.assertRaises(auth_plugins.AuthenticationError,
                          self.handler.auth_connection)

        self.handler.server.target_host = "someotherhost"
        self.handler.auth_connection()
github novnc / websockify / tests / test_websocket.py View on Github external
def _get_websockserver(self, **kwargs):
        return websocket.WebSocketServer(listen_host='localhost',
                                         listen_port=80,
                                         key=self.tmpdir,
                                         web=self.tmpdir,
                                         record=self.tmpdir,
                                         **kwargs)
github novnc / websockify / tests / utf8-list.py View on Github external
#!/usr/bin/python

'''
Display UTF-8 encoding for 0-255.'''

import sys, os, socket, ssl, time, traceback
from select import select
sys.path.insert(0,os.path.join(os.path.dirname(__file__), ".."))
from websockify.websocket import WebSocketServer

if __name__ == '__main__':
    print "val: hybi_base64 | hybi_binary"
    for c in range(0, 256):
        hybi_base64 = WebSocketServer.encode_hybi(chr(c), opcode=1,
                base64=True)
        hybi_binary = WebSocketServer.encode_hybi(chr(c), opcode=2,
                base64=False)
        print "%d: %s | %s" % (c, repr(hybi_base64), repr(hybi_binary))