Spaces:
Running
Running
Download test/test_public_verify_routes.py from SZLHOLDINGS/a11oy: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/spaces/SZLHOLDINGS/a11oy/resolve/8c8ce77c49f475e64b7bca0a4e373db802d03700/test/test_public_verify_routes.py
- Command line
-
hf download hf://spaces/SZLHOLDINGS/a11oy@8c8ce77c49f475e64b7bca0a4e373db802d03700/test/test_public_verify_routes.py
-
curl -L -o test_public_verify_routes.py https://huggingface.co/spaces/SZLHOLDINGS/a11oy/resolve/8c8ce77c49f475e64b7bca0a4e373db802d03700/test/test_public_verify_routes.py
2.23 kB
| import base64 | |
| import json | |
| import unittest | |
| from fastapi import FastAPI | |
| from fastapi.testclient import TestClient | |
| import szl_public_verify | |
| class PublicVerifyRouteTests(unittest.TestCase): | |
| def setUp(self): | |
| self.app = FastAPI() | |
| async def proxy_catch_all(path: str): | |
| return {"caught_by": "proxy", "path": path} | |
| szl_public_verify.register(self.app, ns="a11oy") | |
| self.client = TestClient(self.app) | |
| def test_exact_routes_are_before_proxy(self): | |
| paths = [getattr(route, "path", None) for route in self.app.router.routes] | |
| self.assertLess(paths.index("/api/a11oy/v1/verify/receipt"), | |
| paths.index("/api/a11oy/{path:path}")) | |
| def test_get_exact_path_returns_manifest(self): | |
| response = self.client.get("/api/a11oy/v1/verify/receipt") | |
| self.assertEqual(response.status_code, 200) | |
| self.assertEqual(response.json()["schema"], | |
| "szl.public-receipt-verifier/manifest/v1") | |
| def test_post_exact_path_reaches_verifier(self): | |
| response = self.client.post("/api/a11oy/v1/verify/receipt", json={}) | |
| self.assertEqual(response.status_code, 400) | |
| self.assertNotIn("caught_by", response.json()) | |
| def test_in_image_receipt_uses_runtime_verifier(self): | |
| self.app.state.szl_verify_receipt = lambda envelope: { | |
| "signature_valid": True, "detail": "verified by test runtime key"} | |
| payload = base64.b64encode(json.dumps({"decision": "proposal"}).encode()).decode() | |
| envelope = { | |
| "payloadType": "application/vnd.szl.receipt+json", | |
| "payload": payload, | |
| "signatures": [{"keyid": "a11oy-inimage-ecdsa-p256", "sig": "test"}], | |
| } | |
| response = self.client.post("/api/a11oy/v1/verify/receipt", | |
| json={"envelope": envelope}) | |
| self.assertEqual(response.status_code, 200) | |
| signature = response.json()["checks"][0] | |
| self.assertEqual(signature["status"], "VERIFIED") | |
| self.assertEqual(signature["verify_key_url"], "/cosign.pub") | |
| if __name__ == "__main__": | |
| unittest.main() | |