33 lines
1.5 KiB
Python
33 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Регрессии ревью: не-ASCII Bearer и невалидная кодировка JSON через LB."""
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
|
|
from client import Client, arguments, check, run
|
|
|
|
|
|
def main():
|
|
args = arguments(__doc__)
|
|
client = Client(args.base_url, args.ca_file)
|
|
for path in ("/api/v1/users/me", "/api/v1/auth/sessions/current"):
|
|
method = "DELETE" if path.endswith("/current") else "GET"
|
|
result = client.call(method, path, 401,
|
|
headers={"Authorization": "Bearer é"}, schema="Error")
|
|
check(result["headers"].get("WWW-Authenticate", "").startswith("Bearer"),
|
|
"missing Bearer challenge")
|
|
check(result["json"]["error"]["code"] == "unauthorized", "wrong error code")
|
|
check(result["json"]["error"]["request_id"] == result["headers"]["X-Request-Id"],
|
|
"request IDs differ")
|
|
for raw in (b"\xff", b"{", b'{"username":'):
|
|
result = client.call("POST", "/api/v1/users", 400, raw=raw,
|
|
headers={"Content-Type": "application/json"}, schema="Error")
|
|
check(result["json"]["error"]["code"] == "invalid_request", "wrong JSON error code")
|
|
check(result["json"]["error"]["request_id"] == result["headers"]["X-Request-Id"],
|
|
"request IDs differ")
|
|
print("PASS: non-ASCII Bearer returns 401/challenge; malformed JSON returns contract Error/400")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run(main)
|