pierrejeambrun commented on code in PR #70783:
URL: https://github.com/apache/airflow/pull/70783#discussion_r4338603832


##########
airflow-core/tests/unit/api_fastapi/core_api/test_app.py:
##########
@@ -384,3 +387,29 @@ def test_index_escapes_a_bundle_url(self):
         html = self._render("index.html", ['/x.js" onload="alert(1)'])
 
         assert 'onload="alert(1)"' not in html
+
+
+class TestMiddlewareInitialisation:
+    @patch("airflow.api_fastapi.app.get_auth_manager")
+    def test_jwt_refresh_middleware_init(self, mock_get_auth_manager):
+        app = FastAPI()
+        auth_manager = MagicMock(spec=BaseAuthManager)
+        mock_jwt_middleware = Mock()
+        auth_manager.get_jwt_refresh_middleware.return_value = 
[mock_jwt_middleware, {}]

Review Comment:
   This fails with `TypeError: cannot unpack non-iterable Mock object`: it 
needs to be a list of `(cls, kwargs)` tuples. Also `add_middleware` doesn't 
instantiate the class until the middleware stack is built, so 
`assert_called_once()` won't hold. Could we assert on `app.user_middleware` 
instead?
   ```suggestion
           auth_manager.get_jwt_refresh_middleware.return_value = 
[(mock_jwt_middleware, {})]
   ```
   and then `assert [m.cls for m in app.user_middleware] == 
[mock_jwt_middleware]` (same idea for the empty case).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to