File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,9 @@ async def __call__(
3838 if scope ["type" ] != "http" or path in self .exempt :
3939 return await self .app (scope , receive , send )
4040
41+ root_path = scope ["root_path" ]
4142 query_string = scope ["query_string" ]
42- url = f"{ path } ?{ decode (query_string )} " if query_string else path
43+ url = f"{ root_path } { path } ?{ decode (query_string )} " if query_string else f" { root_path } { path } "
4344 headers = {decode (k ): decode (v ) for k , v in scope ["headers" ]}
4445
4546 events , body = await self ._get_body (receive )
Original file line number Diff line number Diff line change @@ -179,3 +179,39 @@ async def ws(websocket: WebSocket):
179179 with self .client .websocket_connect ("/ws" ) as websocket :
180180 data = websocket .receive_json ()
181181 self .assertEqual (data , {"msg" : "helloes" })
182+
183+
184+ class TestMAuthASGIMiddlewareInSubApplication (unittest .TestCase ):
185+ def setUp (self ):
186+ self .app_uuid = str (uuid4 ())
187+ Config .APP_UUID = self .app_uuid
188+ Config .MAUTH_URL = "https://mauth.com"
189+ Config .MAUTH_API_VERSION = "v1"
190+ Config .PRIVATE_KEY = "key"
191+
192+ self .app = FastAPI ()
193+ sub_app = FastAPI ()
194+ sub_app .add_middleware (MAuthASGIMiddleware )
195+
196+ @sub_app .get ("/path" )
197+ async def sub_app_path ():
198+ return {"msg" : "sub app path" }
199+
200+ self .app .mount ("/sub_app" , sub_app )
201+
202+ self .client = TestClient (self .app )
203+
204+ @patch .object (LocalAuthenticator , "is_authentic" , autospec = True )
205+ def test_includes_base_application_path_in_signature_verification (self , is_authentic_mock ):
206+ request_url = None
207+
208+ def is_authentic_effect (self ):
209+ nonlocal request_url
210+ request_url = self .signable .attributes_for_signing ["request_url" ]
211+ return True , 200 , ""
212+
213+ is_authentic_mock .side_effect = is_authentic_effect
214+
215+ self .client .get ("/sub_app/path" )
216+
217+ self .assertEqual (request_url , "/sub_app/path" )
You can’t perform that action at this time.
0 commit comments