Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Upgrade async-graphql, fix mas-handlers & mas-axum-utils tests
Browse files Browse the repository at this point in the history
This also replaces the init_tracing test helper with a general setup
test helper, so that it also initializes the rustls crypto backend.
  • Loading branch information
sandhose committed Jul 5, 2024
1 parent e7f50a9 commit 07c9989
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 145 deletions.
83 changes: 49 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ oauth2-types = { path = "./crates/oauth2-types/", version = "=0.9.0" }

# GraphQL server
[workspace.dependencies.async-graphql]
version = "6.0.11"
version = "7.0.6"
features = ["chrono", "url", "tracing"]

# Utility to write and implement async traits
Expand Down
20 changes: 10 additions & 10 deletions crates/axum-utils/src/client_authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ where

#[cfg(test)]
mod tests {
use axum::body::{Bytes, Full};
use axum::body::Body;
use http::{Method, Request};

use super::*;
Expand All @@ -502,7 +502,7 @@ mod tests {
http::header::CONTENT_TYPE,
mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(),
)
.body(Full::<Bytes>::new("client_id=client-id&foo=bar".into()))
.body(Body::new("client_id=client-id&foo=bar".to_owned()))
.unwrap();

assert_eq!(
Expand Down Expand Up @@ -530,7 +530,7 @@ mod tests {
http::header::AUTHORIZATION,
"Basic Y2xpZW50LWlkOmNsaWVudC1zZWNyZXQ=",
)
.body(Full::<Bytes>::new("foo=bar".into()))
.body(Body::new("foo=bar".to_owned()))
.unwrap();

assert_eq!(
Expand All @@ -557,7 +557,7 @@ mod tests {
http::header::AUTHORIZATION,
"Basic Y2xpZW50LWlkOmNsaWVudC1zZWNyZXQ=",
)
.body(Full::<Bytes>::new("client_id=client-id&foo=bar".into()))
.body(Body::new("client_id=client-id&foo=bar".to_owned()))
.unwrap();

assert_eq!(
Expand All @@ -584,7 +584,7 @@ mod tests {
http::header::AUTHORIZATION,
"Basic Y2xpZW50LWlkOmNsaWVudC1zZWNyZXQ=",
)
.body(Full::<Bytes>::new("client_id=mismatch-id&foo=bar".into()))
.body(Body::new("client_id=mismatch-id&foo=bar".to_owned()))
.unwrap();

assert!(matches!(
Expand All @@ -600,7 +600,7 @@ mod tests {
mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(),
)
.header(http::header::AUTHORIZATION, "Basic invalid")
.body(Full::<Bytes>::new("foo=bar".into()))
.body(Body::new("foo=bar".to_owned()))
.unwrap();

assert!(matches!(
Expand All @@ -617,8 +617,8 @@ mod tests {
http::header::CONTENT_TYPE,
mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(),
)
.body(Full::<Bytes>::new(
"client_id=client-id&client_secret=client-secret&foo=bar".into(),
.body(Body::new(
"client_id=client-id&client_secret=client-secret&foo=bar".to_owned(),
))
.unwrap();

Expand All @@ -640,7 +640,7 @@ mod tests {
async fn client_assertion_test() {
// Signed with client_secret = "client-secret"
let jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjbGllbnQtaWQiLCJzdWIiOiJjbGllbnQtaWQiLCJhdWQiOiJodHRwczovL2V4YW1wbGUuY29tL29hdXRoMi9pbnRyb3NwZWN0IiwianRpIjoiYWFiYmNjIiwiZXhwIjoxNTE2MjM5MzIyLCJpYXQiOjE1MTYyMzkwMjJ9.XTaACG_Rww0GPecSZvkbem-AczNy9LLNBueCLCiQajU";
let body = Bytes::from(format!(
let body = Body::new(format!(
"client_assertion_type={JWT_BEARER_CLIENT_ASSERTION}&client_assertion={jwt}&foo=bar",
));

Expand All @@ -650,7 +650,7 @@ mod tests {
http::header::CONTENT_TYPE,
mime::APPLICATION_WWW_FORM_URLENCODED.as_ref(),
)
.body(Full::new(body))
.body(body)
.unwrap();

let authz = ClientAuthorization::<serde_json::Value>::from_request(req, &())
Expand Down
1 change: 1 addition & 0 deletions crates/handlers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tower-http.workspace = true
axum.workspace = true
axum-macros = "0.4.1"
axum-extra.workspace = true
rustls.workspace = true

async-graphql.workspace = true

Expand Down
15 changes: 8 additions & 7 deletions crates/handlers/src/compat/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use axum::{extract::State, response::IntoResponse, Json, TypedHeader};
use axum::{extract::State, response::IntoResponse, Json};
use axum_extra::typed_header::TypedHeader;
use chrono::Duration;
use hyper::StatusCode;
use mas_axum_utils::sentry::SentryEventID;
Expand Down Expand Up @@ -433,12 +434,12 @@ mod tests {
use sqlx::PgPool;

use super::*;
use crate::test_utils::{init_tracing, RequestBuilderExt, ResponseExt, TestState};
use crate::test_utils::{setup, RequestBuilderExt, ResponseExt, TestState};

/// Test that the server advertises the right login flows.
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_get_login(pool: PgPool) {
init_tracing();
setup();
let state = TestState::from_pool(pool).await.unwrap();

// Now let's get the login flows
Expand Down Expand Up @@ -470,7 +471,7 @@ mod tests {
/// manager is disabled
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_password_disabled(pool: PgPool) {
init_tracing();
setup();
let state = {
let mut state = TestState::from_pool(pool).await.unwrap();
state.password_manager = PasswordManager::disabled();
Expand Down Expand Up @@ -518,7 +519,7 @@ mod tests {
/// compatibility API.
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_user_password_login(pool: PgPool) {
init_tracing();
setup();
let state = TestState::from_pool(pool).await.unwrap();

// Let's provision a user and add a password to it. This part is hard to test
Expand Down Expand Up @@ -633,7 +634,7 @@ mod tests {
/// Test the response of an unsupported login flow.
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_unsupported_login(pool: PgPool) {
init_tracing();
setup();
let state = TestState::from_pool(pool).await.unwrap();

// Try to login with an unsupported login flow.
Expand All @@ -650,7 +651,7 @@ mod tests {
/// Test `m.login.token` login flow.
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]
async fn test_login_token_login(pool: PgPool) {
init_tracing();
setup();
let state = TestState::from_pool(pool).await.unwrap();

// Provision a user
Expand Down
3 changes: 2 additions & 1 deletion crates/handlers/src/compat/logout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use axum::{response::IntoResponse, Json, TypedHeader};
use axum::{response::IntoResponse, Json};
use axum_extra::typed_header::TypedHeader;
use headers::{authorization::Bearer, Authorization};
use hyper::StatusCode;
use mas_axum_utils::sentry::SentryEventID;
Expand Down
Loading

0 comments on commit 07c9989

Please sign in to comment.