core: consider never consider expiring models with self.expiring set to false expired
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
5522c94b65
commit
32d88c3a49
|
@ -322,6 +322,8 @@ class ExpiringModel(models.Model):
|
|||
@property
|
||||
def is_expired(self) -> bool:
|
||||
"""Check if token is expired yet."""
|
||||
if not self.expiring:
|
||||
return False
|
||||
return now() > self.expires
|
||||
|
||||
class Meta:
|
||||
|
|
26
authentik/core/tests/test_models.py
Normal file
26
authentik/core/tests/test_models.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
"""authentik core models tests"""
|
||||
from time import sleep
|
||||
|
||||
from django.test import TestCase
|
||||
from django.utils.timezone import now
|
||||
from guardian.shortcuts import get_anonymous_user
|
||||
|
||||
from authentik.core.models import Token
|
||||
|
||||
|
||||
class TestModels(TestCase):
|
||||
"""Test Models"""
|
||||
|
||||
def test_token_expire(self):
|
||||
"""Test token expiring"""
|
||||
token = Token.objects.create(expires=now(), user=get_anonymous_user())
|
||||
sleep(0.5)
|
||||
self.assertTrue(token.is_expired)
|
||||
|
||||
def test_token_expire_no_expire(self):
|
||||
"""Test token expiring with "expiring" set """
|
||||
token = Token.objects.create(
|
||||
expires=now(), user=get_anonymous_user(), expiring=False
|
||||
)
|
||||
sleep(0.5)
|
||||
self.assertFalse(token.is_expired)
|
|
@ -1,4 +1,6 @@
|
|||
"""authentik sentry integration"""
|
||||
from typing import Optional
|
||||
|
||||
from aioredis.errors import ConnectionClosedError, ReplyError
|
||||
from billiard.exceptions import WorkerLostError
|
||||
from botocore.client import ClientError
|
||||
|
@ -22,7 +24,7 @@ class SentryIgnoredException(Exception):
|
|||
"""Base Class for all errors that are suppressed, and not sent to sentry."""
|
||||
|
||||
|
||||
def before_send(event: dict, hint: dict) -> dict:
|
||||
def before_send(event: dict, hint: dict) -> Optional[dict]:
|
||||
"""Check if error is database error, and ignore if so"""
|
||||
ignored_classes = (
|
||||
# Inbuilt types
|
||||
|
|
|
@ -10,9 +10,9 @@ class TestSentry(TestCase):
|
|||
def test_error_not_sent(self):
|
||||
"""Test SentryIgnoredError not sent"""
|
||||
self.assertIsNone(
|
||||
before_send(None, {"exc_info": (0, SentryIgnoredException(), 0)})
|
||||
before_send({}, {"exc_info": (0, SentryIgnoredException(), 0)})
|
||||
)
|
||||
|
||||
def test_error_sent(self):
|
||||
"""Test error sent"""
|
||||
self.assertIsNone(before_send(None, {"exc_info": (0, ValueError(), 0)}))
|
||||
self.assertEqual({}, before_send({}, {"exc_info": (0, ValueError(), 0)}))
|
||||
|
|
Reference in a new issue