Spaces:
Running
Running
Download tests/api/test_auth_callback_body_validation.py from Arrechenash/stocks: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/Arrechenash/stocks/resolve/main/tests/api/test_auth_callback_body_validation.py
- Command line
-
hf download hf://spaces/Arrechenash/stocks/tests/api/test_auth_callback_body_validation.py
-
curl -L -o test_auth_callback_body_validation.py https://huggingface.co/spaces/Arrechenash/stocks/resolve/main/tests/api/test_auth_callback_body_validation.py
1.55 kB
| """The two OAuth-callback routes read their body with a raw `await | |
| request.json()` and then call `.get()` on it. | |
| A malformed body made `request.json()` raise `json.JSONDecodeError` and a | |
| non-object body (a JSON array, which is valid JSON) made the `.get()` raise | |
| `AttributeError`. Both escaped the handler's `except Exception` -- that only | |
| wraps the token exchange below them -- so the client got a 500 for what is | |
| plainly a bad request. Every other route in these modules turns a bad body | |
| into a 400. | |
| """ | |
| import pytest | |
| def test_malformed_json_body_is_a_400(raw_app_client, path): | |
| resp = raw_app_client.post( | |
| path, | |
| content="{not json", | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert resp.status_code == 400, resp.text | |
| def test_non_object_json_body_is_a_400(raw_app_client, path): | |
| resp = raw_app_client.post( | |
| path, | |
| content='["redirect_url"]', | |
| headers={"Content-Type": "application/json"}, | |
| ) | |
| assert resp.status_code == 400, resp.text | |
| def test_non_string_redirect_url_is_a_400(raw_app_client, path): | |
| """A JSON number is a well-formed object but still not a usable URL.""" | |
| resp = raw_app_client.post(path, json={"redirect_url": 12345}) | |
| assert resp.status_code == 400, resp.text | |