1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Upgrade fastapi and fix tests

This commit is contained in:
grossmj 2024-10-31 19:23:28 +10:00
parent 8c7c17b889
commit ce4dd17409
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD
2 changed files with 5 additions and 2 deletions

View File

@ -54,7 +54,7 @@ async def login(
) -> schemas.Token: ) -> schemas.Token:
""" """
Default user login method using forms (x-www-form-urlencoded). Default user login method using forms (x-www-form-urlencoded).
Example: curl http://host:port/v3/users/login -H "Content-Type: application/x-www-form-urlencoded" -d "username=admin&password=admin" Example: curl -X POST http://host:port/v3/access/users/login -H "Content-Type: application/x-www-form-urlencoded" -d "username=admin&password=admin"
""" """
user = await users_repo.authenticate_user(username=form_data.username, password=form_data.password) user = await users_repo.authenticate_user(username=form_data.username, password=form_data.password)
@ -76,7 +76,7 @@ async def authenticate(
) -> schemas.Token: ) -> schemas.Token:
""" """
Alternative authentication method using json. Alternative authentication method using json.
Example: curl http://host:port/v3/users/authenticate -d '{"username": "admin", "password": "admin"}' -H "Content-Type: application/json" Example: curl -X POST http://host:port/v3/access/users/authenticate -d '{"username": "admin", "password": "admin"}' -H "Content-Type: application/json"
""" """
user = await users_repo.authenticate_user(username=user_credentials.username, password=user_credentials.password) user = await users_repo.authenticate_user(username=user_credentials.username, password=user_credentials.password)

View File

@ -266,6 +266,7 @@ class TestUserLogin:
( (
("wrong_username", "user1_password", status.HTTP_401_UNAUTHORIZED), ("wrong_username", "user1_password", status.HTTP_401_UNAUTHORIZED),
("user1", "wrong_password", status.HTTP_401_UNAUTHORIZED), ("user1", "wrong_password", status.HTTP_401_UNAUTHORIZED),
("user1", "", status.HTTP_401_UNAUTHORIZED),
("user1", None, status.HTTP_422_UNPROCESSABLE_ENTITY), ("user1", None, status.HTTP_422_UNPROCESSABLE_ENTITY),
), ),
) )
@ -284,6 +285,8 @@ class TestUserLogin:
"username": username, "username": username,
"password": password, "password": password,
} }
if password is None:
del login_data["password"]
response = await unauthorized_client.post(app.url_path_for("login"), data=login_data) response = await unauthorized_client.post(app.url_path_for("login"), data=login_data)
assert response.status_code == status_code assert response.status_code == status_code
assert "access_token" not in response.json() assert "access_token" not in response.json()