Ejemplo n.º 1
0
    def authenticate_credentials(self, request, token_str):
        token = SystemToken.from_request(request, token_str)
        try:
            token = (
                token
                or ApiToken.objects.filter(token=token_str)
                .select_related("user", "application")
                .get()
            )
        except ApiToken.DoesNotExist:
            raise AuthenticationFailed("Invalid token")

        if token.is_expired():
            raise AuthenticationFailed("Token expired")

        if not token.user.is_active:
            raise AuthenticationFailed("User inactive or deleted")

        if token.application and not token.application.is_active:
            raise AuthenticationFailed("UserApplication inactive or deleted")

        with configure_scope() as scope:
            scope.set_tag("api_token_type", self.token_name)
            scope.set_tag("api_token", token.id)
            scope.set_tag("api_token_is_sentry_app", getattr(token.user, "is_sentry_app", False))

        return (token.user, token)
Ejemplo n.º 2
0
    def authenticate_credentials(self, request, token_str):
        token = SystemToken.from_request(request, token_str)
        try:
            token = token or ApiToken.objects.filter(token=token_str) \
                .select_related('user', 'application') \
                .get()
        except ApiToken.DoesNotExist:
            raise AuthenticationFailed('Invalid token')

        if token.is_expired():
            raise AuthenticationFailed('Token expired')

        if not token.user.is_active:
            raise AuthenticationFailed('User inactive or deleted')

        if token.application and not token.application.is_active:
            raise AuthenticationFailed('UserApplication inactive or deleted')

        with configure_scope() as scope:
            scope.set_tag("api_token_type", self.token_name)
            scope.set_tag("api_token", token.id)

        return (token.user, token)
Ejemplo n.º 3
0
 def test_is_system_auth(self):
     token = SystemToken()
     assert is_system_auth(token)
     assert not is_system_auth({})
Ejemplo n.º 4
0
 def test_is_active_superuser_sys_token(self):
     request = self.build_request()
     request.auth = SystemToken()
     assert is_active_superuser(request)
Ejemplo n.º 5
0
 def test_system_token(self):
     self.request.auth = SystemToken()
     assert get_rate_limit_key(self.view, self.request) is None