From c0c48913d4a1db6781c088fe197ac235e5d44152 Mon Sep 17 00:00:00 2001 From: Giovanni Savarese Date: Tue, 5 Dec 2023 09:02:04 +0100 Subject: [PATCH 1/2] Catch exceptions if not strict mode --- flaat/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flaat/__init__.py b/flaat/__init__.py index 5e01bb4..5fc9a6d 100644 --- a/flaat/__init__.py +++ b/flaat/__init__.py @@ -479,7 +479,14 @@ def _run_work_flow(self, *args, **kwargs) -> Tuple[tuple, dict]: # No error, but also do nothing else return (args, kwargs) - user_infos = self.authenticate_user(*args, **kwargs) + if self.ignore_no_authn: + try: + user_infos = self.authenticate_user(*args, **kwargs) + except FlaatException: + user_infos = None + else: + user_infos = self.authenticate_user(*args, **kwargs) + if user_infos is None: if self.ignore_no_authn: # No error, but also do nothing else From 1c83e3e1bf3a9e60870cab41d5cbc20fc7dbd218 Mon Sep 17 00:00:00 2001 From: Giovanni Savarese Date: Tue, 5 Dec 2023 10:17:15 +0100 Subject: [PATCH 2/2] Fix tests: /info_no_strict, no token, returns 200 --- flaat/flask/flask_test_cases.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flaat/flask/flask_test_cases.py b/flaat/flask/flask_test_cases.py index 381648f..48f52f0 100644 --- a/flaat/flask/flask_test_cases.py +++ b/flaat/flask/flask_test_cases.py @@ -26,6 +26,11 @@ def case_FakeToken(self, path): headers = {"Authorization": f"Bearer fake_token"} return path, headers + @parametrize("path", {"/info_no_strict"}) + def case_NoBearer(self, path): + headers = None + return path, headers + class Unauthorized: """Request should not pass.""" @@ -35,7 +40,7 @@ def case_FakeToken(self, path): headers = {"Authorization": f"Bearer fake_token"} return path, headers - @parametrize("path", example_paths) + @parametrize("path", example_paths - {"/info_no_strict"}) def case_NoBearer(self, path): headers = None return path, headers