25 lines
963 B
Python
25 lines
963 B
Python
"""Validate restored-session fixtures and rejection cases against Draft 2020-12."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from jsonschema import Draft202012Validator
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
schema = json.loads((root / "contracts/v1/auth-session-response.json").read_text())
|
|
Draft202012Validator.check_schema(schema)
|
|
validator = Draft202012Validator(schema)
|
|
|
|
for name in ["auth-session.authenticated.json", "auth-session.bootstrap.json"]:
|
|
validator.validate(json.loads((root / "fixtures/v1" / name).read_text()))
|
|
|
|
for invalid in [
|
|
{"authenticated": True},
|
|
{"authenticated": False, "must_replace_credentials": False},
|
|
{"authenticated": True, "must_replace_credentials": "false"},
|
|
{"authenticated": True, "must_replace_credentials": False, "unexpected": True},
|
|
]:
|
|
assert not validator.is_valid(invalid), "Invalid session response was accepted"
|
|
|
|
print("Session schema: two valid fixtures and four rejection cases passed")
|