forked from mtusi2026/mtusi2026lab2
выполнение лр2 на 4
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Sessions: wrong password, Basic/Bearer separation, X-User-Id ignored, logout, expiry.
|
||||
|
||||
Expiry runs against the api-short-ttl service (SESSION_TTL_SECONDS=2):
|
||||
docker compose --profile ttl-test up -d --wait api-short-ttl
|
||||
"""
|
||||
import base64
|
||||
import time
|
||||
import uuid
|
||||
@@ -20,7 +15,6 @@ def main():
|
||||
alice = c.user("auth")
|
||||
reg = alice["registration"]
|
||||
|
||||
# Wrong password and unknown user: the same 401 with a Basic challenge.
|
||||
r1 = c.call("POST", "/api/v1/auth/sessions", 401, headers=basic(reg["username"], "wrong-password-123"))
|
||||
r2 = c.call("POST", "/api/v1/auth/sessions", 401, headers=basic("nobody_" + uuid.uuid4().hex[:8], "wrong-password-123"))
|
||||
check(r1["json"]["error"]["message"] == r2["json"]["error"]["message"], "unknown user must look like a wrong password")
|
||||
@@ -31,7 +25,6 @@ def main():
|
||||
c.call("POST", "/api/v1/auth/sessions", 401, headers={"Authorization": "Bearer " + alice["token"]})
|
||||
ok("missing / malformed / non-Basic login -> 401")
|
||||
|
||||
# A password with ':' and non-ASCII characters survives Basic encoding.
|
||||
tricky = "пароль:с:двоеточием-" + uuid.uuid4().hex[:6]
|
||||
user = c.call("POST", "/api/v1/users", 201, body={"username": "u_colon_" + uuid.uuid4().hex[:8], "display_name": "Двоеточие", "password": tricky}, schema="User")["json"]
|
||||
c.call("POST", "/api/v1/auth/sessions", 201, headers=basic(user["username"], tricky), schema="Session")
|
||||
@@ -56,7 +49,6 @@ def main():
|
||||
c.call("GET", "/api/v1/users/me", 200, actor=second, schema="User")
|
||||
ok("logout revokes only the current token; repeat logout -> 401")
|
||||
|
||||
# Expiry: separate instance of the same image with SESSION_TTL_SECONDS=2.
|
||||
s = Client(SHORT_TTL_URL)
|
||||
bob = s.user("ttl")
|
||||
s.call("GET", "/api/v1/users/me", 200, actor=bob, schema="User")
|
||||
|
||||
Reference in New Issue
Block a user