Пример #1
0
    def test_unauthenticated_userid_valid_macaroon(self, monkeypatch):
        _extract_http_macaroon = pretend.call_recorder(lambda r: b"not a real macaroon")
        monkeypatch.setattr(
            auth_policy, "_extract_http_macaroon", _extract_http_macaroon
        )

        policy = auth_policy.MacaroonAuthenticationPolicy()

        vary_cb = pretend.stub()
        add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
        monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)

        userid = uuid.uuid4()
        user_service = pretend.stub(
            find_userid=pretend.call_recorder(lambda username: userid)
        )
        request = pretend.stub(
            find_service=pretend.call_recorder(lambda interface, **kw: user_service),
            add_response_callback=pretend.call_recorder(lambda cb: None),
        )

        assert policy.unauthenticated_userid(request) == str(userid)
        assert _extract_http_macaroon.calls == [pretend.call(request)]
        assert request.find_service.calls == [
            pretend.call(IMacaroonService, context=None)
        ]
        assert user_service.find_userid.calls == [pretend.call(b"not a real macaroon")]
        assert add_vary_cb.calls == [pretend.call("Authorization")]
        assert request.add_response_callback.calls == [pretend.call(vary_cb)]
Пример #2
0
    def test_unauthenticated_userid_invalid_macaroon(self, monkeypatch):
        _extract_http_macaroon = pretend.call_recorder(lambda r: None)
        monkeypatch.setattr(auth_policy, "_extract_http_macaroon",
                            _extract_http_macaroon)

        policy = auth_policy.MacaroonAuthenticationPolicy()

        vary_cb = pretend.stub()
        add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
        monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)

        request = pretend.stub(
            add_response_callback=pretend.call_recorder(lambda cb: None))

        assert policy.unauthenticated_userid(request) is None
        assert _extract_http_macaroon.calls == [pretend.call(request)]
        assert add_vary_cb.calls == [pretend.call("Authorization")]
        assert request.add_response_callback.calls == [pretend.call(vary_cb)]
Пример #3
0
 def test_forget(self):
     policy = auth_policy.MacaroonAuthenticationPolicy()
     assert policy.forget(pretend.stub()) == []
Пример #4
0
 def test_remember(self):
     policy = auth_policy.MacaroonAuthenticationPolicy()
     assert policy.remember(pretend.stub(), pretend.stub()) == []