Generate new config for each test. Fixes tests.

This commit is contained in:
grossmj committed 2021-04-12 19:37:59 +09:30
1 parent 30ebae207f
commit 1b5a5de4bc
9 files changed
+18 -21

No files matched your search

+5 -9
View File
@@ -36,10 +36,6 @@ DEFAULT_JWT_SECRET_KEY = "efd08eccec3bd0a1be2e086670e5efa90969c68d07e072d7354a76
class AuthService:
def __init__(self):
self._controller_config = Config.instance().settings.Controller
def hash_password(self, password: str) -> str:
return pwd_context.hash(password)
@@ -56,15 +52,15 @@ class AuthService:
) -> str:
if not expires_in:
expires_in = self._controller_config.jwt_access_token_expire_minutes
expires_in = Config.instance().settings.Controller.jwt_access_token_expire_minutes
expire = datetime.utcnow() + timedelta(minutes=expires_in)
to_encode = {"sub": username, "exp": expire}
if secret_key is None:
secret_key = self._controller_config.jwt_secret_key
secret_key = Config.instance().settings.Controller.jwt_secret_key
if secret_key is None:
secret_key = DEFAULT_JWT_SECRET_KEY
log.error("A JWT secret key must be configured to secure the server, using an unsecured default key!")
algorithm = self._controller_config.jwt_algorithm
algorithm = Config.instance().settings.Controller.jwt_algorithm
encoded_jwt = jwt.encode(to_encode, secret_key, algorithm=algorithm)
return encoded_jwt
@@ -77,11 +73,11 @@ class AuthService:
)
try:
if secret_key is None:
secret_key = self._controller_config.jwt_secret_key
secret_key = Config.instance().settings.Controller.jwt_secret_key
if secret_key is None:
secret_key = DEFAULT_JWT_SECRET_KEY
log.error("A JWT secret key must be configured to secure the server, using an unsecured default key!")
algorithm = self._controller_config.jwt_algorithm
algorithm = Config.instance().settings.Controller.jwt_algorithm
payload = jwt.decode(token, secret_key, algorithms=[algorithm])
username: str = payload.get("sub")
if username is None: