Add microservices, web UI, and replay tooling
Some checks failed
ci / tests (push) Has been cancelled
Some checks failed
ci / tests (push) Has been cancelled
This commit is contained in:
24
tests/unit/test_api_auth.py
Normal file
24
tests/unit/test_api_auth.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from services.api.app import app
|
||||
|
||||
|
||||
def test_register_and_login() -> None:
|
||||
with TestClient(app) as client:
|
||||
response = client.post("/api/auth/register", json={"username": "alice", "password": "secret"})
|
||||
assert response.status_code == 200
|
||||
token = response.json().get("token")
|
||||
assert token
|
||||
|
||||
response = client.post("/api/auth/login", json={"username": "alice", "password": "secret"})
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_register_duplicate() -> None:
|
||||
with TestClient(app) as client:
|
||||
response = client.post("/api/auth/register", json={"username": "bob", "password": "secret"})
|
||||
assert response.status_code == 200
|
||||
response = client.post("/api/auth/register", json={"username": "bob", "password": "secret"})
|
||||
assert response.status_code == 400
|
||||
17
tests/unit/test_auth.py
Normal file
17
tests/unit/test_auth.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from services.common.auth import create_token, decode_token, hash_password, verify_password
|
||||
|
||||
|
||||
def test_password_hash_roundtrip() -> None:
|
||||
secret = "dragon"
|
||||
hashed = hash_password(secret)
|
||||
assert verify_password(secret, hashed)
|
||||
assert not verify_password("wrong", hashed)
|
||||
|
||||
|
||||
def test_token_roundtrip() -> None:
|
||||
token = create_token(42, "alice")
|
||||
payload = decode_token(token)
|
||||
assert payload["sub"] == "42"
|
||||
assert payload["username"] == "alice"
|
||||
Reference in New Issue
Block a user