@@ -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" )
0 commit comments