77 unset_jwt_cookies , unset_access_cookies , unset_refresh_cookies , jwt_optional
88)
99
10+
1011def _get_cookie_from_response (response , cookie_name ):
1112 cookie_headers = response .headers .getlist ('Set-Cookie' )
1213 for header in cookie_headers :
@@ -19,6 +20,7 @@ def _get_cookie_from_response(response, cookie_name):
1920 return cookie
2021 return None
2122
23+
2224@pytest .fixture (scope = 'function' )
2325def app ():
2426 app = Flask (__name__ )
@@ -87,7 +89,7 @@ def optional_post_protected():
8789
8890
8991@pytest .mark .parametrize ("options" , [
90- ('/refresh_token' , 'refresh_token_cookie' , '/refresh_protected' , '/delete_refresh_tokens' ),
92+ ('/refresh_token' , 'refresh_token_cookie' , '/refresh_protected' , '/delete_refresh_tokens' ), # nopep8
9193 ('/access_token' , 'access_token_cookie' , '/protected' , '/delete_access_tokens' )
9294])
9395def test_jwt_refresh_required_with_cookies (app , options ):
@@ -200,7 +202,7 @@ def test_csrf_with_custom_header_names(app, options):
200202
201203
202204@pytest .mark .parametrize ("options" , [
203- ('/refresh_token' , 'csrf_refresh_token' , '/refresh_protected' , '/post_refresh_protected' ),
205+ ('/refresh_token' , 'csrf_refresh_token' , '/refresh_protected' , '/post_refresh_protected' ), # nopep8
204206 ('/access_token' , 'csrf_access_token' , '/protected' , '/post_protected' )
205207])
206208def test_custom_csrf_methods (app , options ):
@@ -412,6 +414,7 @@ def test_cookies_without_csrf(app):
412414 refresh_cookie = _get_cookie_from_response (response , 'refresh_token_cookie' )
413415 assert refresh_cookie is not None
414416
417+
415418def test_jwt_optional_with_csrf_enabled (app ):
416419 test_client = app .test_client ()
417420
@@ -423,7 +426,8 @@ def test_jwt_optional_with_csrf_enabled(app):
423426
424427 # User with a token should still get a CSRF error if csrf not present
425428 response = test_client .get ('/access_token' )
426- csrf_token = _get_cookie_from_response (response , 'csrf_access_token' )['csrf_access_token' ]
429+ csrf_cookie = _get_cookie_from_response (response , 'csrf_access_token' )
430+ csrf_token = csrf_cookie ['csrf_access_token' ]
427431 response = test_client .post ('/optional_post_protected' )
428432 assert response .status_code == 401
429433 assert response .get_json () == {'msg' : 'Missing CSRF token in headers' }
0 commit comments