def test_authextra_wampcra(self): """ We pass along the authextra to a dynamic authenticator """ session = Mock() session._transport.transport_details = types.TransportDetails() def fake_call(method, *args, **kw): realm, authid, details = args self.assertEqual("foo.auth_a_doodle", method) self.assertEqual("realm", realm) self.assertEqual(details["authmethod"], "wampcra") self.assertEqual(details["authextra"], {"foo": "bar"}) return defer.succeed({ "secret": 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', "role": "some_role", "extra": { "what": "authenticator-supplied authextra", } }) session.call = Mock(side_effect=fake_call) realm = Mock() realm._realm.session = session session._pending_session_id = 'pending session id' session._router_factory = { "realm": realm, } config = { "type": "dynamic", "authenticator": "foo.auth_a_doodle", "authenticator-realm": "realm", "authenticator-role": "myauth_role" } extra = { "foo": "bar", } details = Mock() details.authid = 'alice' details.authextra = extra pending_session_id = 1 transport_details = types.TransportDetails() realm_container = MockRealmContainer("realm", ["some_role", "myauth_role"], session) auth = wampcra.PendingAuthWampCra(pending_session_id, transport_details, realm_container, config) val = yield auth.hello("realm", details) self.assertTrue(isinstance(val, types.Challenge)) self.assertEqual("wampcra", val.method) self.assertTrue("challenge" in val.extra) self.assertEqual(auth._authextra, {"what": "authenticator-supplied authextra"})
def test_authextra_wampcra(self): """ We pass along the authextra to a dynamic authenticator """ session = Mock() session._transport._transport_info = {} def fake_call(method, *args, **kw): realm, authid, details = args self.assertEqual(u"foo.auth_a_doodle", method) self.assertEqual(u"realm", realm) self.assertEqual(details[u"authmethod"], u"wampcra") self.assertEqual(details[u"authextra"], {u"foo": u"bar"}) return defer.succeed({ u"secret": u'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', u"role": u"some_role", u"extra": { u"what": u"authenticator-supplied authextra", } }) session.call = Mock(side_effect=fake_call) realm = Mock() realm._realm.session = session session._pending_session_id = u'pending session id' session._router_factory = { u"realm": realm, } config = { u"type": u"dynamic", u"authenticator": u"foo.auth_a_doodle", } extra = { u"foo": u"bar", } details = Mock() details.authid = u'alice' details.authextra = extra auth = wampcra.PendingAuthWampCra(session, config) reply = auth.hello(u"realm", details) val = reply.result self.assertTrue(isinstance(val, types.Challenge)) self.assertEqual(u"wampcra", val.method) self.assertTrue(u"challenge" in val.extra) self.assertEqual(auth._authextra, {u"what": u"authenticator-supplied authextra"})