From 2c3a50197dad555e91dc0e9f898579655d6b6198 Mon Sep 17 00:00:00 2001 From: Matteo Bitussi Date: Fri, 1 Mar 2024 17:14:45 +0000 Subject: [PATCH] fixed problems in previous revision --- .../tests/test_02_trust_anchor_intermediary.py | 6 +++--- spid_cie_oidc/authority/views.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/spid_cie_oidc/authority/tests/test_02_trust_anchor_intermediary.py b/spid_cie_oidc/authority/tests/test_02_trust_anchor_intermediary.py index caff098e..5062782d 100644 --- a/spid_cie_oidc/authority/tests/test_02_trust_anchor_intermediary.py +++ b/spid_cie_oidc/authority/tests/test_02_trust_anchor_intermediary.py @@ -268,7 +268,7 @@ def test_trust_mark_status_endpoint(self): res = c.post( url, data={ - "id": self.rp_assigned_profile.profile.profile_id, + "trust_mark_id": self.rp_assigned_profile.profile.profile_id, "sub": self.rp_assigned_profile.descendant.sub, }, ) @@ -278,7 +278,7 @@ def test_trust_mark_status_endpoint(self): res = c.get( url, data={ - "id": self.rp_assigned_profile.profile.profile_id, + "trust_mark_id": self.rp_assigned_profile.profile.profile_id, "sub": self.rp_assigned_profile.descendant.sub, } ) @@ -313,7 +313,7 @@ def test_trust_mark_status_endpoint(self): res = c.get( url, data={ - "id": self.rp_assigned_profile.profile.profile_id, + "trust_mark_id": self.rp_assigned_profile.profile.profile_id, }, ) self.assertTrue(res.status_code == 200) diff --git a/spid_cie_oidc/authority/views.py b/spid_cie_oidc/authority/views.py index 80462b27..7a8197bb 100644 --- a/spid_cie_oidc/authority/views.py +++ b/spid_cie_oidc/authority/views.py @@ -217,19 +217,22 @@ def trust_mark_status(request): failed_data = {"active": False} sub = request.POST.get("sub") or request.GET.get("sub", None) - _id = request.POST.get("trust_mark_id) or request.GET.get("trust_mark_id", None) - if not request.GET or request.POST: - return JsonResponse({"error": "Method not allowed"}, status=400) + _id = request.POST.get("trust_mark_id") or request.GET.get("trust_mark_id", None) + trust_mark = request.POST.get("trust_mark") or request.GET.get("trust_mark", None) + if request.method not in ['GET', 'POST']: + return JsonResponse({"error": "Method not allowed"}, status=400) - if request.POST.get("trust_mark", ""): + if trust_mark: try: - unpad_jwt_head(params["trust_mark"]) - payload = unpad_jwt_payload(params["trust_mark"]) + unpad_jwt_head(trust_mark) + payload = unpad_jwt_payload(trust_mark) sub = payload.get("sub", "") _id = payload.get("id", "") except Exception: return JsonResponse(failed_data) + elif sub and _id: + pass else: return JsonResponse(failed_data)