Skip to content

Commit 3f4e6bd

Browse files
committed
test: Fix failing frontend integration tests for flask and django
1 parent 3cef54f commit 3f4e6bd

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

tests/frontendIntegration/django2x/polls/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
path("", views.get_info, name="/"), # type: ignore
1717
path("update-jwt", views.update_jwt, name="update_jwt"), # type: ignore
1818
path("update-jwt-with-handle", views.update_jwt_with_handle, name="update_jwt_with_handle"), # type: ignore
19+
path("session-claims-error", views.session_claim_error_api, name="session_claim_error_api"), # type: ignore
1920
path("403-without-body", views.without_body_403, name="without_body_403"), # type: ignore
2021
path("testing", views.testing, name="testing"), # type: ignore
2122
path("logout", views.logout, name="logout"), # type: ignore

tests/frontendIntegration/django2x/polls/views.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
SessionRecipe,
3232
)
3333
from supertokens_python.recipe.session.framework.django.syncio import verify_session
34-
from supertokens_python.recipe.session.interfaces import APIInterface, RecipeInterface
34+
from supertokens_python.recipe.session.interfaces import (
35+
APIInterface,
36+
RecipeInterface,
37+
ClaimValidationResult,
38+
SessionClaimValidator,
39+
JSONObject,
40+
)
3541
from supertokens_python.recipe.session.syncio import (
3642
create_new_session,
3743
get_session,
@@ -440,6 +446,22 @@ def update_jwt_with_handle(request: HttpRequest):
440446
return HttpResponse("")
441447

442448

449+
def gcv_for_session_claim_err(*_): # type: ignore
450+
class CustomValidator(SessionClaimValidator):
451+
def should_refetch(self, payload: JSONObject, user_context: Dict[str, Any]):
452+
return False
453+
454+
async def validate(self, payload: JSONObject, user_context: Dict[str, Any]):
455+
return ClaimValidationResult(False, {"message": "testReason"})
456+
457+
return [CustomValidator("test-claim-failing")]
458+
459+
460+
@verify_session(override_global_claim_validators=gcv_for_session_claim_err) # type: ignore
461+
def session_claim_error_api(request: HttpRequest):
462+
return JsonResponse({})
463+
464+
443465
def without_body_403(request: HttpRequest):
444466
if request.method == "POST":
445467
return HttpResponse("", status=403)

tests/frontendIntegration/django3x/polls/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
path("", views.get_info, name="/"), # type: ignore
1717
path("update-jwt", views.update_jwt, name="update_jwt"), # type: ignore
1818
path("update-jwt-with-handle", views.update_jwt_with_handle, name="update_jwt_with_handle"), # type: ignore
19+
path("session-claims-error", views.session_claim_error_api, name="session_claim_error_api"), # type: ignore
1920
path("403-without-body", views.without_body_403, name="without_body_403"), # type: ignore
2021
path("testing", views.testing, name="testing"), # type: ignore
2122
path("logout", views.logout, name="logout"), # type: ignore

tests/frontendIntegration/django3x/polls/views.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from supertokens_python.recipe.session.interfaces import APIInterface, RecipeInterface
14+
from supertokens_python.recipe.session.interfaces import (
15+
APIInterface,
16+
RecipeInterface,
17+
ClaimValidationResult,
18+
JSONObject,
19+
SessionClaimValidator,
20+
)
1521
from typing import Dict, Union, Any
1622
import json
1723
import os
@@ -444,6 +450,22 @@ async def update_jwt_with_handle(request: HttpRequest):
444450
return HttpResponse("")
445451

446452

453+
def gcv_for_session_claim_err(*_): # type: ignore
454+
class CustomValidator(SessionClaimValidator):
455+
def should_refetch(self, payload: JSONObject, user_context: Dict[str, Any]):
456+
return False
457+
458+
async def validate(self, payload: JSONObject, user_context: Dict[str, Any]):
459+
return ClaimValidationResult(False, {"message": "testReason"})
460+
461+
return [CustomValidator("test-claim-failing")]
462+
463+
464+
@verify_session(override_global_claim_validators=gcv_for_session_claim_err) # type: ignore
465+
async def session_claim_error_api(request: HttpRequest):
466+
return JsonResponse({})
467+
468+
447469
async def without_body_403(request: HttpRequest):
448470
if request.method == "POST":
449471
return HttpResponse("", status=403)

tests/frontendIntegration/flask-server/app.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
from supertokens_python.recipe import session
2828
from supertokens_python.recipe.session import InputErrorHandlers, SessionRecipe
2929
from supertokens_python.recipe.session.framework.flask import verify_session
30-
from supertokens_python.recipe.session.interfaces import APIInterface, RecipeInterface
30+
from supertokens_python.recipe.session.interfaces import (
31+
APIInterface,
32+
RecipeInterface,
33+
JSONObject,
34+
SessionClaimValidator,
35+
ClaimValidationResult,
36+
)
3137
from supertokens_python.recipe.session.syncio import (
3238
create_new_session,
3339
SessionContainer,
@@ -384,6 +390,24 @@ def update_jwt_with_handle_post():
384390
return resp
385391

386392

393+
def gcv_for_session_claim_err(*_): # type: ignore
394+
class CustomValidator(SessionClaimValidator):
395+
def should_refetch(self, payload: JSONObject, user_context: Dict[str, Any]):
396+
return False
397+
398+
async def validate(self, payload: JSONObject, user_context: Dict[str, Any]):
399+
return ClaimValidationResult(False, {"message": "testReason"})
400+
401+
return [CustomValidator("test-claim-failing")]
402+
403+
404+
@app.route("/session-claims-error", methods=["POST"]) # type: ignore
405+
@verify_session(override_global_claim_validators=gcv_for_session_claim_err) # type: ignore
406+
def session_claim_error_api():
407+
# return empty json response
408+
return jsonify({})
409+
410+
387411
@app.route("/403-without-body", methods=["POST"]) # type: ignore
388412
def without_body_403():
389413
# send 403 without body

0 commit comments

Comments
 (0)