Esempio n. 1
0
    def test_authextra_wampcryptosign(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"], "cryptosign")
            self.assertEqual(details["authextra"], {"foo": "bar"})
            return defer.succeed({
                "pubkey":
                'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
                "role": "some_role",
                "extra": {
                    "what": "authenticator-supplied authextra",
                }
            })

        session.call = Mock(side_effect=fake_call)
        realm = Mock()
        realm._realm.session = session
        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.authextra = extra

        pending_session_id = 1
        transport_details = types.TransportDetails()
        realm_container = MockRealmContainer("realm",
                                             ["some_role", "myauth_role"],
                                             session)

        auth = cryptosign.PendingAuthCryptosign(pending_session_id,
                                                transport_details,
                                                realm_container, config)
        val = yield auth.hello("realm", details)

        self.assertTrue(isinstance(val, types.Challenge))
        self.assertEqual("cryptosign", val.method)
        self.assertTrue("challenge" in val.extra)
        self.assertEqual(auth._authextra,
                         {"what": "authenticator-supplied authextra"})
Esempio n. 2
0
    def test_authextra_wampcryptosign(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"cryptosign")
            self.assertEqual(details[u"authextra"], {u"foo": u"bar"})
            return defer.succeed({
                u"pubkey":
                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._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.authextra = extra

        auth = cryptosign.PendingAuthCryptosign(session, config)
        reply = auth.hello(u"realm", details)

        val = reply.result
        self.assertTrue(isinstance(val, types.Challenge))
        self.assertEqual(u"cryptosign", val.method)
        self.assertTrue(u"challenge" in val.extra)
        self.assertEqual(auth._authextra,
                         {u"what": u"authenticator-supplied authextra"})