mirror of
https://github.com/TECHNOFAB11/jwt-authorizer.git
synced 2026-02-02 01:15:11 +01:00
fix: responses collect into bytes with BodyExt trait
This commit is contained in:
parent
41f38d8db5
commit
e1e5874347
4 changed files with 15 additions and 13 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1076,6 +1076,7 @@ dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"headers",
|
"headers",
|
||||||
"http 1.0.0",
|
"http 1.0.0",
|
||||||
|
"http-body-util",
|
||||||
"hyper 1.0.1",
|
"hyper 1.0.1",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
tonic = { version = "0.10", optional = true }
|
tonic = { version = "0.10", optional = true }
|
||||||
time = { version = "0.3", optional = true }
|
time = { version = "0.3", optional = true }
|
||||||
|
http-body-util = "0.1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hyper = { version = "1.0.1", features = ["full"] }
|
hyper = { version = "1.0.1", features = ["full"] }
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,8 @@ fn run_jwks_server() -> String {
|
||||||
.route("/jwks", get(jwks));
|
.route("/jwks", get(jwks));
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
axum::Server::from_tcp(listener)
|
let listener: tokio::net::TcpListener = tokio::net::TcpListener::from_std(listener).unwrap();
|
||||||
.unwrap()
|
axum::serve(listener, app.into_make_service()).await.unwrap();
|
||||||
.serve(app.into_make_service())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
url
|
url
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ mod tests {
|
||||||
use tower::{util::MapErrLayer, ServiceExt};
|
use tower::{util::MapErrLayer, ServiceExt};
|
||||||
|
|
||||||
use crate::common;
|
use crate::common;
|
||||||
|
use http_body_util::BodyExt;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
struct User {
|
struct User {
|
||||||
|
|
@ -102,7 +103,9 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
|
||||||
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
|
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
// ECDSA PEM
|
// ECDSA PEM
|
||||||
|
|
@ -112,14 +115,14 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
// RSA PEM
|
// RSA PEM
|
||||||
let response =
|
let response =
|
||||||
make_proteced_request(JwtAuthorizer::from_rsa_pem("../config/rsa-public2.pem"), common::JWT_RSA2_OK).await;
|
make_proteced_request(JwtAuthorizer::from_rsa_pem("../config/rsa-public2.pem"), common::JWT_RSA2_OK).await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
// JWKS
|
// JWKS
|
||||||
|
|
@ -129,7 +132,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
let response = make_proteced_request(
|
let response = make_proteced_request(
|
||||||
|
|
@ -138,7 +141,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
let response = make_proteced_request(
|
let response = make_proteced_request(
|
||||||
|
|
@ -147,7 +150,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
|
|
||||||
// JWKS TEXT
|
// JWKS TEXT
|
||||||
|
|
@ -158,7 +161,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"hello: b@b.com");
|
assert_eq!(&body[..], b"hello: b@b.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +237,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
let body = response.into_body().collect().await.unwrap().to_bytes();
|
||||||
assert_eq!(&body[..], b"option: true");
|
assert_eq!(&body[..], b"option: true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue