This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PostgreSQL integrity: registration race, rollback of chat creation, repeatable migrations,
|
||||
password storage. Needs the compose stack (reads tables via `docker compose exec postgres`)."""
|
||||
import concurrent.futures
|
||||
import uuid
|
||||
|
||||
@@ -10,7 +8,6 @@ from stack import BASE_URL, Client, check, compose, main_wrapper, ok, psql
|
||||
def main():
|
||||
c = Client(BASE_URL)
|
||||
|
||||
# 1. Registration race: 20 parallel requests for one username.
|
||||
username = "u_race_" + uuid.uuid4().hex[:10]
|
||||
body = {"username": username, "display_name": "Гонка", "password": "Race-password-123"}
|
||||
|
||||
@@ -24,7 +21,6 @@ def main():
|
||||
check(psql("SELECT count(*) FROM users WHERE username = '%s'" % username) == "1", "exactly one row expected")
|
||||
ok("20 concurrent registrations of one username -> 1x201, 19x409, 1 row")
|
||||
|
||||
# 2. Rollback: the chat row is inserted, then the member insert hits the FK.
|
||||
alice = c.user("rb")
|
||||
title = "rollback-" + uuid.uuid4().hex
|
||||
c.call("POST", "/api/v1/chats", 400, actor=alice, body={"title": title, "member_ids": [alice["id"], str(uuid.uuid4())]})
|
||||
@@ -33,14 +29,12 @@ def main():
|
||||
"chat without members exists")
|
||||
ok("chat with unknown member -> 400 and transaction rolled back (no orphan chat)")
|
||||
|
||||
# 3. Passwords are stored as Argon2id hashes, never plaintext.
|
||||
stored = psql("SELECT password_hash FROM users WHERE username = '%s'" % username)
|
||||
check(stored.startswith("$argon2id$") and "Race-password-123" not in stored, "password must be an Argon2id hash")
|
||||
check(psql("SELECT count(*) FROM information_schema.columns WHERE table_name = 'sessions' AND column_name = 'token'") == "0",
|
||||
"raw tokens must not be stored")
|
||||
ok("password stored as $argon2id$..., sessions keep only sha256(token)")
|
||||
|
||||
# 4. Migrations re-run without duplicates or data changes.
|
||||
before = psql("SELECT (SELECT count(*) FROM schema_migrations) || ':' || (SELECT count(*) FROM users)")
|
||||
compose("run", "--rm", "--no-deps", "migrate")
|
||||
compose("run", "--rm", "--no-deps", "migrate")
|
||||
|
||||
Reference in New Issue
Block a user