Skip to content

Commit bddf57c

Browse files
author
IndominusByte
committed
fix message error to lowercase
1 parent aac44e2 commit bddf57c

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

fastapi_jwt_auth/auth_jwt.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _get_secret_key(self, algorithm: str, process: str) -> str:
9292
if algorithm in symmetric_algorithms:
9393
if not self._secret_key:
9494
raise RuntimeError(
95-
"AUTHJWT_SECRET_KEY must be set when using symmetric algorithm {}".format(algorithm)
95+
"authjwt_secret_key must be set when using symmetric algorithm {}".format(algorithm)
9696
)
9797

9898
return self._secret_key
@@ -105,15 +105,15 @@ def _get_secret_key(self, algorithm: str, process: str) -> str:
105105
if process == "encode":
106106
if not self._private_key:
107107
raise RuntimeError(
108-
"AUTHJWT_PRIVATE_KEY must be set when using asymmetric algorithm {}".format(algorithm)
108+
"authjwt_private_key must be set when using asymmetric algorithm {}".format(algorithm)
109109
)
110110

111111
return self._private_key
112112

113113
if process == "decode":
114114
if not self._public_key:
115115
raise RuntimeError(
116-
"AUTHJWT_PUBLIC_KEY must be set when using asymmetric algorithm {}".format(algorithm)
116+
"authjwt_public_key must be set when using asymmetric algorithm {}".format(algorithm)
117117
)
118118

119119
return self._public_key
@@ -209,7 +209,7 @@ def _check_token_is_revoked(self, raw_token: Dict[str,Union[str,int,bool]]) -> N
209209
if not self._has_token_in_denylist_callback():
210210
raise RuntimeError("A token_in_denylist_callback must be provided via "
211211
"the '@AuthJWT.token_in_denylist_loader' if "
212-
"AUTHJWT_DENYLIST_ENABLED is 'True'")
212+
"authjwt_denylist_enabled is 'True'")
213213

214214
if self._token_in_denylist_callback.__func__(raw_token):
215215
raise RevokedTokenError(status_code=401,message="Token has been revoked")
@@ -317,7 +317,7 @@ def set_access_cookies(self,encoded_access_token: str, max_age: Optional[int] =
317317
"""
318318
if not self.jwt_in_cookies:
319319
raise RuntimeWarning(
320-
"set_access_cookies() called without 'AUTHJWT_TOKEN_LOCATION' configured to use cookies"
320+
"set_access_cookies() called without 'authjwt_token_location' configured to use cookies"
321321
)
322322

323323
if max_age and not isinstance(max_age,int):
@@ -358,7 +358,7 @@ def set_refresh_cookies(self, encoded_refresh_token: str, max_age: Optional[int]
358358
"""
359359
if not self.jwt_in_cookies:
360360
raise RuntimeWarning(
361-
"set_refresh_cookies() called without 'AUTHJWT_TOKEN_LOCATION' configured to use cookies"
361+
"set_refresh_cookies() called without 'authjwt_token_location' configured to use cookies"
362362
)
363363

364364
if max_age and not isinstance(max_age,int):
@@ -402,7 +402,7 @@ def unset_access_cookies(self) -> None:
402402
"""
403403
if not self.jwt_in_cookies:
404404
raise RuntimeWarning(
405-
"unset_access_cookies() called without 'AUTHJWT_TOKEN_LOCATION' configured to use cookies"
405+
"unset_access_cookies() called without 'authjwt_token_location' configured to use cookies"
406406
)
407407

408408
self._response.delete_cookie(
@@ -424,7 +424,7 @@ def unset_refresh_cookies(self) -> None:
424424
"""
425425
if not self.jwt_in_cookies:
426426
raise RuntimeWarning(
427-
"unset_refresh_cookies() called without 'AUTHJWT_TOKEN_LOCATION' configured to use cookies"
427+
"unset_refresh_cookies() called without 'authjwt_token_location' configured to use cookies"
428428
)
429429

430430
self._response.delete_cookie(

fastapi_jwt_auth/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def validate_cookie_samesite(cls, v):
7676

7777
@validator('authjwt_csrf_methods', each_item=True)
7878
def validate_csrf_methods(cls, v):
79+
if v.upper() not in {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"}:
80+
raise ValueError("The 'authjwt_csrf_methods' must be between http request methods")
7981
return v.upper()
8082

8183
class Config:

tests/test_config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ def get_expired_false():
8080
def test_secret_key_not_exist(client,Authorize):
8181
AuthJWT._secret_key = None
8282

83-
with pytest.raises(RuntimeError,match=r"AUTHJWT_SECRET_KEY"):
83+
with pytest.raises(RuntimeError,match=r"authjwt_secret_key"):
8484
Authorize.create_access_token(subject='test')
8585

8686
Authorize._secret_key = "secret"
8787
token = Authorize.create_access_token(subject=1)
8888
Authorize._secret_key = None
8989

90-
with pytest.raises(RuntimeError,match=r"AUTHJWT_SECRET_KEY"):
90+
with pytest.raises(RuntimeError,match=r"authjwt_secret_key"):
9191
client.get('/protected',headers={"Authorization":f"Bearer {token}"})
9292

9393
def test_denylist_enabled_without_callback(client):
@@ -398,3 +398,8 @@ def get_invalid_refresh_csrf_header_name():
398398
@AuthJWT.load_config
399399
def get_invalid_csrf_methods():
400400
return [("authjwt_csrf_methods",[1,2,3])]
401+
402+
with pytest.raises(ValidationError,match=r"authjwt_csrf_methods"):
403+
@AuthJWT.load_config
404+
def get_invalid_csrf_methods_value():
405+
return [("authjwt_csrf_methods",['posts'])]

tests/test_decode_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class SettingsAsymmetricOne(BaseSettings):
241241
def get_settings_asymmetric_one():
242242
return SettingsAsymmetricOne()
243243

244-
with pytest.raises(RuntimeError,match=r"AUTHJWT_PRIVATE_KEY"):
244+
with pytest.raises(RuntimeError,match=r"authjwt_private_key"):
245245
Authorize.create_access_token(subject=1)
246246

247247
DIR = os.path.abspath(os.path.dirname(__file__))
@@ -259,7 +259,7 @@ def get_settings_asymmetric_two():
259259
return SettingsAsymmetricTwo()
260260

261261
token = Authorize.create_access_token(subject=1)
262-
with pytest.raises(RuntimeError,match=r"AUTHJWT_PUBLIC_KEY"):
262+
with pytest.raises(RuntimeError,match=r"authjwt_public_key"):
263263
client.get('/protected',headers={'Authorization':f"Bearer {token}"})
264264

265265
AuthJWT._private_key = None

0 commit comments

Comments
 (0)