Пример #1
0
        def test_inconsistent_authextra(self):
            session = Session(mock.Mock())

            class TestAuthenticator(IAuthenticator):

                name = "test"

                def on_challenge(self, session, challenge):
                    raise NotImplementedError

                def on_welcome(self, authextra):
                    raise NotImplementedError

            auth0 = TestAuthenticator()
            auth0.authextra = {
                "foo": "value0",
                "bar": "value1",
            }
            auth0._args = {}

            auth1 = TestAuthenticator()
            auth1.authextra = {
                "foo": "value1",
            }
            auth1._args = {}

            session.add_authenticator(auth0)
            with self.assertRaises(ValueError) as ctx:
                session.add_authenticator(auth1)
            self.assertIn("Inconsistent authextra", str(ctx.exception))
Пример #2
0
def create_session(config):
    session = Session(config)
    session.add_authenticator(
        create_authenticator(
            "cryptosign",
            authid="foo",
            authrole="role0",
            privkey="a" * 64,
        ))

    def joined(session, details):
        print("joined: {} {}".format(session, details))
        session.config.extra['running'].callback(session)

    session.on('join', joined)

    def left(session, details):
        if "no_such_procedure" in str(details.reason):
            session.config.extra['running'].errback(Exception(details.reason))

    session.on('leave', left)

    def disconnected(*args, **kw):
        print("disconnect: {} {}".format(args, kw))

    session.on('disconnect', disconnected)

    return session
        def test_two_authenticators(self):
            session = Session(mock.Mock())

            class TestAuthenticator(IAuthenticator):

                name = "test"

                def on_challenge(self, session, challenge):
                    raise NotImplementedError

                def on_welcome(self, authextra):
                    raise NotImplementedError

            auth0 = TestAuthenticator()
            auth0.authextra = {
                "foo": "value0",
                "bar": "value1",
            }
            auth0._args = {}

            auth1 = TestAuthenticator()
            auth1.authextra = {
                "bar": "value1",
                "qux": "what",
            }
            auth1._args = {}

            session.add_authenticator(auth0)
            session.add_authenticator(auth1)
Пример #4
0
        def test_two_authenticators(self):
            session = Session(mock.Mock())

            class TestAuthenticator(IAuthenticator):

                name = "test"

                def on_challenge(self, session, challenge):
                    raise NotImplementedError

                def on_welcome(self, authextra):
                    raise NotImplementedError

            auth0 = TestAuthenticator()
            auth0.authextra = {
                "foo": "value0",
                "bar": "value1",
            }
            auth0._args = {}

            auth1 = TestAuthenticator()
            auth1.authextra = {
                "bar": "value1",
                "qux": "what",
            }
            auth1._args = {}

            session.add_authenticator(auth0)
            session.add_authenticator(auth1)
Пример #5
0
        def test_inconsistent_authids(self):
            session = Session(mock.Mock())
            auth0 = create_authenticator(
                "wampcra",
                authid=u"alice",
                secret=u"p4ssw0rd",
            )
            auth1 = create_authenticator(
                "wampcra",
                authid=u"bob",
                secret=u"password42",
            )

            session.add_authenticator(auth0)
            with self.assertRaises(ValueError) as ctx:
                session.add_authenticator(auth1)
            assert "authids" in str(ctx.exception)
Пример #6
0
 def on_join(session: Session, session_details: SessionDetails):
     component.session = session
     component.session_details = session_details
     session.subscribe(component.on_heartbeat_rate,
                       TOPIC_HEARTBEAT_RATE,
                       options=SubscribeOptions(get_retained=True))
     session.register(component.rpc_healthcheck,
                      f'py.ms.{component.name}.healthcheck')
     session.register(component.on_restart,
                      f'py.ms.{component.name}.restart')
     session.register(component.on_stop, f'py.ms.{component.name}.stop')
Пример #7
0
def make_session(config):
    @coroutine
    def on_join(session, details):
        print("on_join: {}".format(details))

        def add2(a, b):
            return a + b

        yield session.register(add2, u"com.example.add2")

        try:
            res = yield session.call(u"com.example.add2", 2, 3)
            print("result: {}".format(res))
        except Exception as e:
            print("error: {}".format(e))
        finally:
            session.leave()

    session = Session(config=config)
    session.on("join", on_join)
    return session
        def test_inconsistent_authextra(self):
            session = Session(mock.Mock())

            class TestAuthenticator(IAuthenticator):

                name = "test"

                def on_challenge(self, session, challenge):
                    raise NotImplementedError

                def on_welcome(self, authextra):
                    raise NotImplementedError

            auth0 = TestAuthenticator()
            auth0.authextra = {
                "foo": "value0",
                "bar": "value1",
            }
            auth0._args = {}

            auth1 = TestAuthenticator()
            auth1.authextra = {
                "foo": "value1",
            }
            auth1._args = {}

            session.add_authenticator(auth0)
            with self.assertRaises(ValueError) as ctx:
                session.add_authenticator(auth1)
            self.assertIn("Inconsistent authextra", str(ctx.exception))
Пример #9
0
def make_session(config):

    @coroutine
    def on_join(session, details):
        print("on_join: {}".format(details))

        def add2(a, b):
            return a + b

        yield session.register(add2, 'com.example.add2')

        try:
            res = yield session.call('com.example.add2', 2, 3)
            print("result: {}".format(res))
        except Exception as e:
            print("error: {}".format(e))
        finally:
            session.leave()

    session = Session(config=config)
    session.on('join', on_join)
    return session
        def test_inconsistent_authids(self):
            session = Session(mock.Mock())
            auth0 = create_authenticator(
                "wampcra",
                authid="alice",
                secret="p4ssw0rd",
            )
            auth1 = create_authenticator(
                "wampcra",
                authid="bob",
                secret="password42",
            )

            session.add_authenticator(auth0)
            with self.assertRaises(ValueError) as ctx:
                session.add_authenticator(auth1)
            assert "authids" in str(ctx.exception)
Пример #11
0
 def on_join(session: Session, session_details: SessionDetails):
     component.session = session
     component.session_details = session_details
     session.subscribe(component.on_heartbeat, TOPIC_HEARTBEAT)
     component.publish_heartbeat_rate(HEARTBEAT_RATE)
     component.dead_service_check_loop.start(HEARTBEAT_RATE)
Пример #12
0
 def onOpen(self, transport):
     # instance of Frontend
     self._frontend = transport._proxy_other_side
     self._on_connect = Deferred()
     return Session.onOpen(self, transport)