Exemplo n.º 1
0
 def test_ctor_empty(self):
     td = TransportDetails()
     data = td.marshal()
     self.assertEqual(
         data, {
             'channel_type': None,
             'channel_framing': None,
             'channel_serializer': None,
             'own': None,
             'peer': None,
             'is_server': None,
             'own_pid': None,
             'own_tid': None,
             'own_fd': None,
             'is_secure': None,
             'channel_id': None,
             'peer_cert': None,
             'websocket_protocol': None,
             'websocket_extensions_in_use': None,
             'http_headers_received': None,
             'http_headers_sent': None,
             'http_cbtid': None,
         })
     td2 = TransportDetails.parse(td.marshal())
     self.assertEqual(td2, td)
 def test_attributes(self):
     sd1 = SessionDetails()
     td1 = TransportDetails.parse(TRANSPORT_DETAILS_1)
     sd1.realm = 'realm1'
     sd1.session = 666
     sd1.authid = 'homer'
     sd1.authrole = 'user'
     sd1.authmethod = 'wampcra'
     sd1.authprovider = 'static'
     sd1.authextra = {'foo': 'bar', 'baz': [1, 2, 3]}
     sd1.serializer = 'json'
     sd1.transport = td1
     sd1.resumed = False
     sd1.resumable = True
     sd1.resume_token = '8713e25a-d4f5-48b7-9d6d-eda66603a1ab'
     data = sd1.marshal()
     self.assertEqual(
         data, {
             'realm': sd1.realm,
             'session': sd1.session,
             'authid': sd1.authid,
             'authrole': sd1.authrole,
             'authmethod': sd1.authmethod,
             'authprovider': sd1.authprovider,
             'authextra': sd1.authextra,
             'serializer': sd1.serializer,
             'transport': sd1.transport.marshal(),
             'resumed': sd1.resumed,
             'resumable': sd1.resumable,
             'resume_token': sd1.resume_token,
         })
     sd2 = SessionDetails.parse(data)
     self.assertEqual(sd2, sd1)
Exemplo n.º 3
0
    def get_session_by_session_id(self,
                                  session_id: int,
                                  joined_before: Optional[int] = None) -> Optional[Dict[str, Any]]:
        """
        Implements :meth:`crossbar._interfaces.IRealmStore.get_session_by_session_id`
        """
        if joined_before:
            _joined_before = np.datetime64(joined_before, 'ns')
        else:
            _joined_before = np.datetime64(time_ns(), 'ns')
        _from_key = (session_id, np.datetime64(0, 'ns'))
        _to_key = (session_id, _joined_before)

        # check if we have a record store for the session
        session: Optional[cfxdb.realmstore.Session] = None
        with self._db.begin() as txn:
            # lookup session by WAMP session ID and find the most recent session
            # according to joined_at timestamp
            for session_oid in self._schema.idx_sessions_by_session_id.select(txn,
                                                                              from_key=_from_key,
                                                                              to_key=_to_key,
                                                                              reverse=True,
                                                                              return_keys=False,
                                                                              return_values=True):
                session = self._schema.sessions[txn, session_oid]

                # if we have an index, that index must always resolve to an indexed record
                assert session

                # we only want the most recent session
                break

        if session:
            # extract info from database table to construct session details and return
            td = TransportDetails.parse(session.transport)
            sd = SessionDetails(
                realm=session.realm,
                session=session.session,
                authid=session.authid,
                authrole=session.authrole,
                authmethod=session.authmethod,
                authprovider=session.authprovider,
                authextra=session.authextra,
                # FIXME
                serializer=None,
                resumed=False,
                resumable=False,
                resume_token=None,
                transport=td)
            res = sd.marshal()
            return res
        else:
            return None
Exemplo n.º 4
0
 def test_parse(self):
     td = TransportDetails.parse(TRANSPORT_DETAILS_1)
     data2 = td.marshal()
     self.maxDiff = None
     self.assertEqual(data2, TRANSPORT_DETAILS_1)