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))
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)
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)
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')
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 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)
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)
def onOpen(self, transport): # instance of Frontend self._frontend = transport._proxy_other_side self._on_connect = Deferred() return Session.onOpen(self, transport)