def test_multiple_shared_works(self):
        request = RequestFactory().post(
            '/api',
            HTTP_AUTHORIZATION='mkt-shared-secret '
            '[email protected],56b6f1a3dd735d962c56'
            'ce7d8f46e02ec1d4748d2c00c407d75f0969d08bb'
            '9c68c31b3371aa8130317815c89e5072e31bb94b4'
            '121c5c165f3515838d4d6c60c4,165d631d3c3045'
            '458b4516242dad7ae')
        drf_request = Request(request)

        # Start with an AnonymousUser on the request, because that's a classic
        # situation: we already went through a middleware, it didn't find a
        # session cookie, if set request.user = AnonymousUser(), and now we
        # are going through the authentication code in the API.
        request.user = AnonymousUser()

        # Call middleware as they would normally be called.
        RedirectPrefixedURIMiddleware().process_request(request)
        RestSharedSecretMiddleware().process_request(request)
        RestOAuthMiddleware().process_request(request)

        drf_request.authenticators = (
            authentication.RestSharedSecretAuthentication(),
            authentication.RestOAuthAuthentication())

        eq_(drf_request.user, self.profile.user)
        eq_(drf_request._request.user, self.profile.user)
        eq_(drf_request.user.is_authenticated(), True)
        eq_(drf_request._request.user.is_authenticated(), True)
        eq_(drf_request.amo_user.pk, self.profile.pk)
        eq_(drf_request._request.amo_user.pk, self.profile.pk)
Beispiel #2
0
    def test_multiple_shared_works(self):
        request = RequestFactory().post(
            '/',
            HTTP_AUTHORIZATION='mkt-shared-secret '
            '[email protected],56b6f1a3dd735d962c56'
            'ce7d8f46e02ec1d4748d2c00c407d75f0969d08bb'
            '9c68c31b3371aa8130317815c89e5072e31bb94b4'
            '121c5c165f3515838d4d6c60c4,165d631d3c3045'
            '458b4516242dad7ae')
        drf_request = Request(request)

        # Start with an AnonymousUser on the request, because that's a classic
        # situation: we already went through a middleware, it didn't find a
        # session cookie, if set request.user = AnonymousUser(), and now we
        # are going through the authentication code in the API.
        request.user = AnonymousUser()
        drf_request.authenticators = (
                authentication.RestSharedSecretAuthentication(),
                authentication.RestOAuthAuthentication())

        eq_(drf_request.user, self.profile.user)
        eq_(drf_request._request.user, self.profile.user)
        eq_(drf_request.user.is_authenticated(), True)
        eq_(drf_request._request.user.is_authenticated(), True)
        eq_(drf_request.amo_user.pk, self.profile.pk)
        eq_(drf_request._request.amo_user.pk, self.profile.pk)
    def test_multiple_shared_works(self):
        request = RequestFactory().post(
            "/api",
            HTTP_AUTHORIZATION="mkt-shared-secret "
            "[email protected],56b6f1a3dd735d962c56"
            "ce7d8f46e02ec1d4748d2c00c407d75f0969d08bb"
            "9c68c31b3371aa8130317815c89e5072e31bb94b4"
            "121c5c165f3515838d4d6c60c4,165d631d3c3045"
            "458b4516242dad7ae",
        )
        drf_request = Request(request)

        # Start with an AnonymousUser on the request, because that's a classic
        # situation: we already went through a middleware, it didn't find a
        # session cookie, if set request.user = AnonymousUser(), and now we
        # are going through the authentication code in the API.
        request.user = AnonymousUser()

        # Call middleware as they would normally be called.
        RedirectPrefixedURIMiddleware().process_request(request)
        RestSharedSecretMiddleware().process_request(request)
        RestOAuthMiddleware().process_request(request)

        drf_request.authenticators = (
            authentication.RestSharedSecretAuthentication(),
            authentication.RestOAuthAuthentication(),
        )

        eq_(drf_request.user, self.profile.user)
        eq_(drf_request._request.user, self.profile.user)
        eq_(drf_request.user.is_authenticated(), True)
        eq_(drf_request._request.user.is_authenticated(), True)
        eq_(drf_request.amo_user.pk, self.profile.pk)
        eq_(drf_request._request.amo_user.pk, self.profile.pk)
Beispiel #4
0
 def __make_sub_request(request, url, resolver):
     wsgi_request = copy(request._request)
     wsgi_request.method = 'GET'
     wsgi_request.path = wsgi_request.path_info = urlsplit(url).path
     wsgi_request.resolver_match = resolver.resolve(wsgi_request.path_info)
     sub_request = Request(wsgi_request)
     sub_request.user = request.user
     sub_request.authenticators = request.authenticators
     return sub_request
Beispiel #5
0
 def _make_sub_request(self, request, url, resolver):
     wsgi_request = copy(request._request)
     wsgi_request.method = 'GET'
     wsgi_request.path = wsgi_request.path_info = urlsplit(url).path
     wsgi_request.resolver_match = resolver.resolve(wsgi_request.path_info)
     sub_request = Request(wsgi_request)
     sub_request.user = request.user
     sub_request.authenticators = request.authenticators
     return sub_request
    def test_multiple_fail(self):
        request = RequestFactory().post('/api')
        drf_request = Request(request)
        request.user = AnonymousUser()
        drf_request.authenticators = (
            authentication.RestSharedSecretAuthentication(),
            authentication.RestOAuthAuthentication())

        eq_(drf_request.user.is_authenticated(), False)
        eq_(drf_request._request.user.is_authenticated(), False)
Beispiel #7
0
    def test_multiple_fail(self):
        request = RequestFactory().post('/')
        drf_request = Request(request)
        request.user = AnonymousUser()
        drf_request.authenticators = (
                authentication.RestSharedSecretAuthentication(),
                authentication.RestOAuthAuthentication())

        eq_(drf_request.user.is_authenticated(), False)
        eq_(drf_request._request.user.is_authenticated(), False)