Exemple #1
0
 def _on_read_raw(self, event, *args):
     if self._sock is not None:
         if args[0] != self._sock:
             return
         data = args[1]
     else:
         data = args[0]
     messages = self._parse_messages(bytearray(data))
     for message in messages:
         if self._sock is not None:
             self.fire(read(self._sock, message))
         else:
             self.fire(read(message))
     event.stop()
Exemple #2
0
 def _on_read_raw(self, event, *args):
     if self._sock is not None:
         if args[0] != self._sock:
             return
         data = args[1]
     else:
         data = args[0]
     messages = self._parse_messages(bytearray(data))
     for message in messages:
         if self._sock is not None:
             self.fire(read(self._sock, message))
         else:
             self.fire(read(message))
     event.stop()
Exemple #3
0
	def on_started(self, *args, **kwargs):
		for client in self.requests:
			scheme = client.request.uri.scheme
			client.request.uri.scheme = None
			yield  # self.wait('routes.create')  # handle all other started events, which are registering the routes
			self.fire(read(client.socket, (str(client.request) + str(client.request.headers) + str(client.request.body))), self.channel)
			client.request.uri.scheme = scheme
Exemple #4
0
 def on_started(self, *args, **kwargs):
     for client in self.requests:
         scheme = client.request.uri.scheme
         client.request.uri.scheme = None
         yield  # self.wait('routes.create')  # handle all other started events, which are registering the routes
         self.fire(
             read(client.socket,
                  (str(client.request) + str(client.request.headers) +
                   str(client.request.body))), self.channel)
         client.request.uri.scheme = scheme
Exemple #5
0
def test_responses(app, data, event):
    app.reset()
    app.fire(read(data))
    while len(app):
        app.flush()

    e = app.events[-1]

    assert event.name == e.name
    assert event.args == e.args
    assert event.kwargs == e.kwargs
Exemple #6
0
    def nmeaplayback(self,*args):
        try:
            if self.position == len(self.logdata):
                hfoslog("[NMEA] Playback looping")
                self.position = 0
            else:
                self.position += 1

            self.fireEvent(read(self.logdata[self.position]), "nmea")
        except Exception as e:
            hfoslog("[NMEA] Error during logdata playback: ", e, type(e), lvl=error)
Exemple #7
0
def test_responses(app, data, event):
    app.reset()
    app.fire(read(data))
    while app:
        app.flush()

    e = app.events[-1]

    assert event.name == e.name
    assert event.args == e.args
    assert event.kwargs == e.kwargs
Exemple #8
0
    def __init__(self, sock=None, data=bytearray(), *args, **kwargs):
        """
        Creates a new codec.

        :param sock: the socket used in Read and write events
            (if used in a server, else None)
        """
        super(WebSocketCodec, self).__init__(*args, **kwargs)

        self._sock = sock

        self._pending_payload = bytearray()
        self._pending_type = None
        self._close_received = False
        self._close_sent = False

        messages = self._parse_messages(bytearray(data))
        for message in messages:
            if self._sock is not None:
                self.fire(read(self._sock, message))
            else:
                self.fire(read(message))
Exemple #9
0
    def __init__(self, sock=None, data=bytearray(), *args, **kwargs):
        """
        Creates a new codec.

        :param sock: the socket used in Read and write events
            (if used in a server, else None)
        """
        super(WebSocketCodec, self).__init__(*args, **kwargs)

        self._sock = sock

        self._pending_payload = bytearray()
        self._pending_type = None
        self._close_received = False
        self._close_sent = False

        messages = self._parse_messages(bytearray(data))
        for message in messages:
            if self._sock is not None:
                self.fire(read(self._sock, message))
            else:
                self.fire(read(message))
Exemple #10
0
    def nmeaplayback(self, *args):
        try:
            if self.position == len(self.logdata):
                hfoslog("[NMEA] Playback looping")
                self.position = 0
            else:
                self.position += 1

            self.fireEvent(read(self.logdata[self.position]), "nmea")
        except Exception as e:
            hfoslog("[NMEA] Error during logdata playback: ",
                    e,
                    type(e),
                    lvl=error)
Exemple #11
0
def test_auth_logout():
    return
    m.start()

    client_uuid = str(uuid4())

    data = {
        'component': 'auth',
        'action': 'logout',
        'data': {}
    }

    event = read(None, dumps(data))

    result = transmit('clientdisconnect', 'hfosweb', event, 'wsserver')

    assert result.clientuuid == client_uuid
Exemple #12
0
def test_auth_request():
    m.start()

    data = {
        'component': 'auth',
        'action': 'login',
        'data': {
            'username': '******',
            'password': '******'
        }
    }

    event = read(None, dumps(data))

    result = transmit('authenticationrequest', 'auth', event, 'wsserver')

    assert result.username == 'foo'
    assert result.password == 'bar'
Exemple #13
0
    def nmeaplayback(self, *args):
        self.log("Playback time", lvl=verbose)
        try:
            if self.position == len(self.logdata):
                self.log("Playback looping", lvl=warn)
                self.position = 0
            else:
                self.position += 1

            data = self.logdata[self.position]

            self.log("Transmitting: ", data, lvl=verbose)

            self.fireEvent(read(data), "nmea")

            if self.position % 100 == 0:
                self.log("Played back", self.position, "sentences.")

        except Exception as e:
            self.log("Error during logdata playback: ", e, type(e), lvl=error)
Exemple #14
0
    def nmeaplayback(self, *args):
        self.log("Playback time", lvl=verbose)
        try:
            if self.position == len(self.logdata):
                self.log("Playback looping", lvl=warn)
                self.position = 0
            else:
                self.position += 1

            data = self.logdata[self.position]

            self.log("Transmitting: ", data, lvl=verbose)

            self.fireEvent(read(data), "nmea")

            if self.position % 100 == 0:
                self.log("Played back", self.position, "sentences.")

        except Exception as e:
            self.log("Error during logdata playback: ", e, type(e), lvl=error)
Exemple #15
0
def test_auth_logout():

    client_uuid = std_uuid()
    user_uuid = std_uuid()

    cm._clients[client_uuid] = Client(None, '127.0.0.1', client_uuid,
                                      user_uuid, 'TESTER')

    m.start()

    cm._handle_authentication_events(None, 'logout', client_uuid, None)

    data = {'component': 'auth', 'action': 'logout', 'data': {}}

    event = read(None, dumps(data))

    result = transmit('clientdisconnect', 'isomer-web', event, 'wsserver')

    assert result.clientuuid == client_uuid
    assert isinstance(result, clientdisconnect)
Exemple #16
0
def test_auto_auth_request():
    m.start()

    client_config_uuid = str(uuid4())

    data = {
        'component': 'auth',
        'action': 'autologin',
        'data': {
            'uuid': client_config_uuid

        }
    }

    event = read(None, dumps(data))

    result = transmit('authenticationrequest', 'auth', event, 'wsserver')

    pprint(result.__dict__)
    assert result.auto is True
    assert result.requestedclientuuid['uuid'] == client_config_uuid
Exemple #17
0
def test_auto_auth_request():
    """Tests if automatic authentication requests work"""

    test_uuid = std_uuid()

    m.start()

    # TODO: Rebuild this, to actually connect a fake socket via cm.connect(socket, IP)
    class sock():
        """Mock socket"""
        @staticmethod
        def getpeername():
            """Mock function to return a fake peer name"""

            return ["localhost"]

        def clientuuid(self):
            return test_uuid

    socket = sock
    cm._sockets[socket] = socket

    client_config_uuid = std_uuid()

    data = {
        'component': 'auth',
        'action': 'autologin',
        'data': {
            'uuid': client_config_uuid
        }
    }

    event = read(socket, dumps(data))

    result = transmit('authenticationrequest', 'auth', event, 'wsserver')

    #pprint(result.__dict__)
    assert result.auto is True
    assert result.requestedclientuuid['uuid'] == client_config_uuid
Exemple #18
0
def test_auth_request():
    """Test if clientmanager fires an authentication-request on login"""

    test_uuid = std_uuid()

    m.start()

    # TODO: Rebuild this, to actually connect a fake socket via cm.connect(socket, IP)
    class sock():
        """Mock socket"""
        @staticmethod
        def getpeername():
            """Mock function to return a fake peer name"""

            return ["localhost"]

        def clientuuid(self):
            return test_uuid

    socket = sock
    cm._sockets[socket] = socket

    data = {
        'component': 'auth',
        'action': 'login',
        'data': {
            'username': '******',
            'password': '******'
        }
    }

    event = read(socket, dumps(data))

    result = transmit('authenticationrequest', 'auth', event, 'wsserver')

    assert result.username == 'foo'
    assert result.password == 'bar'
Exemple #19
0
 def read(self, data):
     self.fire(read(FakeSock(), data))
Exemple #20
0
 def read(self, data):
     self.fire(read(FakeSock(), data))