test(server): add client-facing endpoint tests (20 tests), fix pack contract assertions
- Add test_client.py with comprehensive client-server contract tests:
- TestAuthFlowClient: full register → login → refresh → validate → /admin/me → logout lifecycle
- TestPacksClientContract: /packs response fields matching ServerPack.java
- TestPackManifestClientContract: /pack/{name} fields matching PackManifest.java
- TestPackDiffClientContract: /pack/{name}/diff matching DiffResponse/FileInfo.java
(all-new, no-changes, outdated-file, extra-local-file scenarios)
- TestPackFileDownload: file serving, 404, path traversal security
- TestPackPermissions: auth/pass requirements for /packs and /diff
- TestLauncherVersion: /launcher/version endpoint
- TestProxyEndpoints: /proxy/status, /proxy/fabric/versions/loader
- Add logged_in_user_with_pass fixture (role=1) for pack-related tests
- Add pack_fixture: creates temp pack with mod file, scans it, cleans up
- Fix manifest test: files don't have 'url' field (only in diff response)
- Fix /pack/{name} test: endpoint is public, no auth required
Total: 67 tests passing (47 existing + 20 new)
This commit is contained in:
@@ -71,6 +71,31 @@ def logged_in_user(client, registered_user):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logged_in_user_with_pass(client, registered_user):
|
||||
"""Login user and give them role 1 (pass holder)."""
|
||||
# Promote to pass holder
|
||||
import sqlite3
|
||||
import auth
|
||||
conn = sqlite3.connect(str(auth.AUTH_DB))
|
||||
conn.execute("UPDATE users SET role = 1 WHERE username = ?", (registered_user["username"],))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
resp = client.post("/auth/login", json=registered_user)
|
||||
assert resp.status_code == 200, f"Login failed: {resp.text}"
|
||||
data = resp.json()
|
||||
return {
|
||||
"username": registered_user["username"],
|
||||
"password": registered_user["password"],
|
||||
"access_token": data["access_token"],
|
||||
"refresh_token": data["refresh_token"],
|
||||
"expires_in": data["expires_in"],
|
||||
"uuid": data["uuid"],
|
||||
"role": data["role"],
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin_user(client):
|
||||
"""Create and login a creator/admin user."""
|
||||
|
||||
Reference in New Issue
Block a user