From f056b026d660849070d03684dd10e66d7ed6585e Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Dec 2020 18:35:51 +0100 Subject: [PATCH] lib: test edgecase for timedelta_from_string --- authentik/lib/tests/__init__.py | 0 authentik/lib/{tests.py => tests/test_serializer_model.py} | 0 authentik/{providers/saml => lib}/tests/test_utils_time.py | 2 ++ authentik/lib/utils/time.py | 2 ++ 4 files changed, 4 insertions(+) create mode 100644 authentik/lib/tests/__init__.py rename authentik/lib/{tests.py => tests/test_serializer_model.py} (100%) rename authentik/{providers/saml => lib}/tests/test_utils_time.py (90%) diff --git a/authentik/lib/tests/__init__.py b/authentik/lib/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/authentik/lib/tests.py b/authentik/lib/tests/test_serializer_model.py similarity index 100% rename from authentik/lib/tests.py rename to authentik/lib/tests/test_serializer_model.py diff --git a/authentik/providers/saml/tests/test_utils_time.py b/authentik/lib/tests/test_utils_time.py similarity index 90% rename from authentik/providers/saml/tests/test_utils_time.py rename to authentik/lib/tests/test_utils_time.py index 419d205e9..cc16550e1 100644 --- a/authentik/providers/saml/tests/test_utils_time.py +++ b/authentik/lib/tests/test_utils_time.py @@ -20,6 +20,8 @@ class TestTimeUtils(TestCase): """Test invalid expression""" with self.assertRaises(ValueError): timedelta_from_string("foo") + with self.assertRaises(ValueError): + timedelta_from_string("bar=baz") def test_validation(self): """Test Django model field validator""" diff --git a/authentik/lib/utils/time.py b/authentik/lib/utils/time.py index 4ba41ddb5..a4109f5af 100644 --- a/authentik/lib/utils/time.py +++ b/authentik/lib/utils/time.py @@ -35,4 +35,6 @@ def timedelta_from_string(expr: str) -> datetime.timedelta: if key.lower() not in ALLOWED_KEYS: continue kwargs[key.lower()] = float(value) + if len(kwargs) < 1: + raise ValueError("No valid keys to pass to timedelta") return datetime.timedelta(**kwargs)