1+ from base64 import b64encode
12from unittest .mock import call
23
34from flask import url_for
@@ -51,17 +52,6 @@ def test_positive_redirect_to_allowed_host(app):
5152 assert response .status_code == 200
5253
5354
54- def test_positive_redirect_for_a_json_resquest (app ):
55- app .config ["ALLOWED_HOSTS" ] = ["myothersite.com" ]
56- with app .test_client () as client :
57- response = client .get (
58- url_for ("simplelogin.login" , next = "https://myothersite.com/page" ),
59- headers = {"Content-Type" : "application/json" },
60- follow_redirects = True ,
61- )
62- assert response .status_code == 200
63-
64-
6555def test_is_logged_in (app , client , csrf_token_for ):
6656 client .get (url_for ("simplelogin.login" ))
6757 assert not is_logged_in ()
@@ -77,6 +67,18 @@ def test_is_logged_in(app, client, csrf_token_for):
7767 assert is_logged_in ()
7868
7969
70+ def test_is_logged_in_from_json_request (app , client ):
71+ client .get (url_for ("simplelogin.login" ))
72+ assert not is_logged_in ()
73+ auth = b64encode (b"admin:secret" ).decode ("utf-8" )
74+ response = client .post (
75+ url_for ("simplelogin.login" ),
76+ headers = {"Authorization" : f"Basic { auth } " , "Content-Type" : "application/json" },
77+ )
78+ assert response .status_code == 302
79+ assert is_logged_in ()
80+
81+
8082def test_logout (app , client , csrf_token_for ):
8183 client .get (url_for ("simplelogin.login" ))
8284 assert not is_logged_in ()
0 commit comments