コード例 #1
0
    def test_authextra_tls(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"], "tls")
            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(
            channel_id={'tls-unique': b'anything'},
            peer_cert={'some': 'thing'})
        realm_container = MockRealmContainer("realm",
                                             ["some_role", "myauth_role"],
                                             session)

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

        self.assertTrue(isinstance(val, types.Accept))
        self.assertEqual(val.authmethod, "tls")
        self.assertEqual(val.authextra,
                         {"what": "authenticator-supplied authextra"})
コード例 #2
0
ファイル: test_authorize.py プロジェクト: yutiansut/crossbar
    def test_authextra_tls(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"tls")
            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 = tls.PendingAuthTLS(session, config)
        reply = auth.hello(u"realm", details)

        val = reply.result
        self.assertTrue(isinstance(val, types.Accept))
        self.assertEqual(val.authmethod, u"tls")
        self.assertEqual(val.authextra,
                         {u"what": u"authenticator-supplied authextra"})