mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Generate new config for each test. Fixes tests.
This commit is contained in:
1 parent
30ebae207f
commit
1b5a5de4bc
9 files changed
+18
-21
No files matched your search
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user