Coverage for tests / test_security_scopes_dont_propagate.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1# Ref: https://github.com/tiangolo/fastapi/issues/5623
3from typing import Annotated, Any 1abcd
5from fastapi import FastAPI, Security 1abcd
6from fastapi.security import SecurityScopes 1abcd
7from fastapi.testclient import TestClient 1abcd
10async def security1(scopes: SecurityScopes): 1abcd
11 return scopes.scopes 1efg
14async def security2(scopes: SecurityScopes): 1abcd
15 return scopes.scopes 1efg
18async def dep3( 1abcd
19 dep1: Annotated[list[str], Security(security1, scopes=["scope1"])],
20 dep2: Annotated[list[str], Security(security2, scopes=["scope2"])],
21):
22 return {"dep1": dep1, "dep2": dep2} 1efg
25app = FastAPI() 1abcd
28@app.get("/scopes") 1abcd
29def get_scopes( 1abcd
30 dep3: Annotated[dict[str, Any], Security(dep3, scopes=["scope3"])],
31):
32 return dep3 1efg
35client = TestClient(app) 1abcd
38def test_security_scopes_dont_propagate(): 1abcd
39 response = client.get("/scopes") 1efg
40 assert response.status_code == 200 1efg
41 assert response.json() == { 1efg
42 "dep1": ["scope3", "scope1"],
43 "dep2": ["scope3", "scope2"],
44 }