예제 #1
0
    def process_request(self, request: Request):
        request.user_from_signed_request = False

        # If there is a valid signature on the request we override the
        # user with the user contained within the signature.
        user = process_signature(request)
        auth = get_authorization_header(request).split()

        if user is not None:
            request.user = user
            request.user_from_signed_request = True
        elif auth and auth[0].lower() == TokenAuthentication.token_name:
            try:
                result = TokenAuthentication().authenticate(request=request)
            except AuthenticationFailed:
                result = None
            if result:
                request.user, request.auth = result
            else:
                # default to anonymous user and use IP ratelimit
                request.user = SimpleLazyObject(lambda: get_user(request))
        elif auth and auth[0].lower() == ApiKeyAuthentication.token_name:
            try:
                result = ApiKeyAuthentication().authenticate(request=request)
            except AuthenticationFailed:
                result = None
            if result:
                request.user, request.auth = result
            else:
                # default to anonymous user and use IP ratelimit
                request.user = SimpleLazyObject(lambda: get_user(request))
        else:
            request.user = SimpleLazyObject(lambda: get_user(request))
예제 #2
0
    def process_request(self, request):
        middleware.AuthenticationMiddleware.process_request(self, request)
        request.user_from_signed_request = False

        # If there is a valid signature on the request we override the
        # user with the user contained within the signature.
        user = process_signature(request)
        if user is not None:
            request.user = user
            request.user_from_signed_request = True
예제 #3
0
파일: auth.py 프로젝트: sugusbs/sentry
    def process_request(self, request):
        request.user_from_signed_request = False

        # If there is a valid signature on the request we override the
        # user with the user contained within the signature.
        user = process_signature(request)
        if user is not None:
            request.user = user
            request.user_from_signed_request = True
        else:
            request.user = SimpleLazyObject(lambda: get_user(request))
예제 #4
0
    def process_request(self, request):
        request.user_from_signed_request = False

        # If there is a valid signature on the request we override the
        # user with the user contained within the signature.
        user = process_signature(request)
        if user is not None:
            request.user = user
            request.user_from_signed_request = True
        else:
            request.user = SimpleLazyObject(lambda: get_user(request))
예제 #5
0
    def test_link_signing(self):
        rf = RequestFactory()

        url = linksign.generate_signed_link(self.user, "sentry")
        assert url.startswith("http://")

        req = rf.get("/" + url.split("/", 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user
        assert signed_user.id == self.user.id

        req = rf.get("/what" + url.split("/", 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        req = rf.get("/" + url.split("/", 3)[-1] + "garbage")
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        rf.defaults["SERVER_NAME"] = "something-else"
        req = rf.get("/" + url.split("/", 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None
예제 #6
0
    def test_link_signing(self):
        rf = RequestFactory()

        url = linksign.generate_signed_link(self.user, 'sentry')
        assert url.startswith('http://')

        req = rf.get('/' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user
        assert signed_user.id == self.user.id

        req = rf.get('/what' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        req = rf.get('/' + url.split('/', 3)[-1] + 'garbage')
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        rf.defaults['SERVER_NAME'] = 'something-else'
        req = rf.get('/' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None
    def test_link_signing(self):
        rf = RequestFactory()

        url = linksign.generate_signed_link(self.user, 'sentry')
        assert url.startswith('http://')

        req = rf.get('/' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user
        assert signed_user.id == self.user.id

        req = rf.get('/what' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        req = rf.get('/' + url.split('/', 3)[-1] + 'garbage')
        signed_user = linksign.process_signature(req)
        assert signed_user is None

        rf.defaults['SERVER_NAME'] = 'something-else'
        req = rf.get('/' + url.split('/', 3)[-1])
        signed_user = linksign.process_signature(req)
        assert signed_user is None