(test_client_factory: TestClientFactory)
| 221 | |
| 222 | |
| 223 | def test_authentication_required(test_client_factory: TestClientFactory) -> None: |
| 224 | with test_client_factory(app) as client: |
| 225 | response = client.get("/dashboard") |
| 226 | assert response.status_code == 403 |
| 227 | |
| 228 | response = client.get("/dashboard", auth=("tomchristie", "example")) |
| 229 | assert response.status_code == 200 |
| 230 | assert response.json() == {"authenticated": True, "user": "tomchristie"} |
| 231 | |
| 232 | response = client.get("/dashboard/sync") |
| 233 | assert response.status_code == 403 |
| 234 | |
| 235 | response = client.get("/dashboard/sync", auth=("tomchristie", "example")) |
| 236 | assert response.status_code == 200 |
| 237 | assert response.json() == {"authenticated": True, "user": "tomchristie"} |
| 238 | |
| 239 | response = client.get("/dashboard/class") |
| 240 | assert response.status_code == 403 |
| 241 | |
| 242 | response = client.get("/dashboard/class", auth=("tomchristie", "example")) |
| 243 | assert response.status_code == 200 |
| 244 | assert response.json() == {"authenticated": True, "user": "tomchristie"} |
| 245 | |
| 246 | response = client.get("/dashboard/decorated", auth=("tomchristie", "example")) |
| 247 | assert response.status_code == 200 |
| 248 | assert response.json() == { |
| 249 | "authenticated": True, |
| 250 | "user": "tomchristie", |
| 251 | "additional": "payload", |
| 252 | } |
| 253 | |
| 254 | response = client.get("/dashboard/decorated") |
| 255 | assert response.status_code == 403 |
| 256 | |
| 257 | response = client.get("/dashboard/decorated/sync", auth=("tomchristie", "example")) |
| 258 | assert response.status_code == 200 |
| 259 | assert response.json() == { |
| 260 | "authenticated": True, |
| 261 | "user": "tomchristie", |
| 262 | "additional": "payload", |
| 263 | } |
| 264 | |
| 265 | response = client.get("/dashboard/decorated/sync") |
| 266 | assert response.status_code == 403 |
| 267 | |
| 268 | response = client.get("/dashboard", headers={"Authorization": "basic foobar"}) |
| 269 | assert response.status_code == 400 |
| 270 | assert response.text == "Invalid basic auth credentials" |
| 271 | |
| 272 | |
| 273 | def test_websocket_authentication_required( |
nothing calls this directly
no test coverage detected