diff --git a/jwt-authorizer/Cargo.toml b/jwt-authorizer/Cargo.toml index 52a5313..b8c908a 100644 --- a/jwt-authorizer/Cargo.toml +++ b/jwt-authorizer/Cargo.toml @@ -33,7 +33,7 @@ tonic = { version = "0.9.2", optional = true } hyper = { version = "0.14", features = ["full"] } lazy_static = "1.4.0" prost = "0.11.9" -tower = { version = "0.4", features = ["util"] } +tower = { version = "0.4", features = ["util", "buffer"] } wiremock = "0.5" [[test]] diff --git a/jwt-authorizer/tests/tests.rs b/jwt-authorizer/tests/tests.rs index 76d205b..37641c4 100644 --- a/jwt-authorizer/tests/tests.rs +++ b/jwt-authorizer/tests/tests.rs @@ -2,17 +2,19 @@ mod common; #[cfg(test)] mod tests { + use std::convert::Infallible; + use axum::{ body::Body, http::{Request, StatusCode}, response::Response, routing::get, - Router, + BoxError, Router, }; use http::{header, HeaderValue}; use jwt_authorizer::{layer::JwtSource, validation::Validation, JwtAuthorizer, JwtClaims}; use serde::Deserialize; - use tower::ServiceExt; + use tower::{util::MapErrLayer, ServiceExt}; use crate::common; @@ -24,8 +26,15 @@ mod tests { async fn app(jwt_auth: JwtAuthorizer) -> Router { Router::new().route("/public", get(|| async { "hello" })).route( "/protected", - get(|JwtClaims(user): JwtClaims| async move { format!("hello: {}", user.sub) }) - .layer(jwt_auth.layer().await.unwrap()), + get(|JwtClaims(user): JwtClaims| async move { format!("hello: {}", user.sub) }).layer( + tower_layer::Stack::new( + tower_layer::Stack::new( + tower::buffer::BufferLayer::new(1), + MapErrLayer::new(|e: BoxError| -> Infallible { panic!("{}", e) }), + ), + jwt_auth.layer().await.unwrap(), + ), + ), ) } diff --git a/jwt-authorizer/tests/tonic.rs b/jwt-authorizer/tests/tonic.rs index fc838fe..ac8874b 100644 --- a/jwt-authorizer/tests/tonic.rs +++ b/jwt-authorizer/tests/tonic.rs @@ -6,7 +6,7 @@ use http::header::AUTHORIZATION; use jwt_authorizer::{layer::AsyncAuthorizationService, JwtAuthorizer}; use serde::{Deserialize, Serialize}; use tonic::{server::UnaryService, transport::NamedService, IntoRequest, Status}; -use tower::Service; +use tower::{buffer::Buffer, Service}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; @@ -82,10 +82,11 @@ impl NamedService for GreeterServer { async fn app( jwt_auth: JwtAuthorizer, expected_sub: String, -) -> AsyncAuthorizationService { +) -> AsyncAuthorizationService>, User> { let layer = jwt_auth.layer().await.unwrap(); tonic::transport::Server::builder() .layer(layer) + .layer(tower::buffer::BufferLayer::new(1)) .add_service(GreeterServer { expected_sub }) .into_service() }