You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux 4eb828285a59 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 GNU/Linux
Description
I'm getting a 500 error for middleware that is very similar to the example.
I thought this had worked before but now I have a pretty simple test that I can't get to pass.
cargo test middleware_runs
Body: Missing request extension: Extension of type`fs::user::CurrentUser` was not found. Perhaps you forgot to add it? See `axum::Extension`.
pubasyncfncurrent_user_middleware<B>(mutreq:Request<B>,next:Next<B>,) -> Result<Response,StatusCode>{let token = matchToken::from_request(&req){Some(t) => t,None => returnErr(StatusCode::UNAUTHORIZED),};let claims = match token.into_claims(){Ok(d) => d,Err(_e) => returnErr(StatusCode::UNAUTHORIZED),};debug!("middleware: adding user to request extensions");
req.extensions_mut().insert(CurrentUser::new(claims));Ok(next.run(req).await)}
...#[tokio::test]asyncfnmiddleware_runs(){asyncfnhandler(Extension(current_user):Extension<CurrentUser>){
serde_json::to_string(¤t_user).unwrap();}let router = Router::new().route("/",get(handler)).route_layer(middleware::from_fn(current_user_middleware));let req = Request::builder().uri("/").header("Authorization",DEV_TOKEN).body(Body::empty()).unwrap();let res = router.oneshot(req).await.unwrap();let body = res.into_body_string().await.unwrap();println!("Body: {}", body);// Body: Missing request extension: Extension of type `fs::user::CurrentUser` was not found. Perhaps you forgot to add it? See `axum::Extension`.// Fails with 500 error.// assert_eq!(res.status(), StatusCode::OK);assert!(body.contains(DEV_TOKEN_UID))}// Response extensions used above.asyncfninto_body_string(self) -> Result<String>{let bytes = self.into_body_bytes().await?;String::from_utf8(bytes.to_vec()).map_err(|e| anyhow!(e))}asyncfninto_body_bytes(self) -> Result<Bytes>{
hyper::body::to_bytes(self.into_body()).await.map_err(|e| anyhow!(e))}
The text was updated successfully, but these errors were encountered:
Bug Report
Version
Platform
Linux 4eb828285a59 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 GNU/Linux
Description
I'm getting a 500 error for middleware that is very similar to the example.
I thought this had worked before but now I have a pretty simple test that I can't get to pass.
The text was updated successfully, but these errors were encountered: