From 74551fb4797f4708295725912fb6fe100484c6b0 Mon Sep 17 00:00:00 2001 From: Paul Zinselmeyer Date: Sun, 12 Jan 2025 22:37:30 +0100 Subject: [PATCH] update dependencies --- Cargo.toml | 6 ++-- examples/basic/Cargo.toml | 20 +++++------ examples/basic/src/lib.rs | 5 +-- examples/basic/tests/integration.rs | 16 +++------ examples/basic/tests/keycloak.rs | 52 +++++++++++++++++------------ 5 files changed, 51 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 482eeec..6686a40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,13 @@ keywords = [ "axum", "oidc", "openidconnect", "authentication" ] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -thiserror = "1.0" +thiserror = "2.0" axum-core = "0.5" axum = { version = "0.8", default-features = false, features = [ "query" ] } tower-service = "0.3" tower-layer = "0.3" -tower-sessions = { version = "0.13", default-features = false, features = [ "axum-core" ] } -http = "1.1" +tower-sessions = { version = "0.14", default-features = false, features = [ "axum-core" ] } +http = "1.2" openidconnect = "3.5" serde = "1.0" futures-util = "0.3" diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml index 6d862c7..fe9028c 100644 --- a/examples/basic/Cargo.toml +++ b/examples/basic/Cargo.toml @@ -6,18 +6,18 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tokio = { version = "1.37", features = ["net", "macros", "rt-multi-thread"] } -axum = { version = "0.8", features = ["macros"] } +tokio = { version = "1.43", features = ["net", "macros", "rt-multi-thread"] } +axum = { version = "0.8", features = [ "macros" ]} axum-oidc = { path = "./../.." } -tower = "0.4" -tower-sessions = "0.13" +tower = "0.5" +tower-sessions = "0.14" dotenvy = "0.15" [dev-dependencies] -testcontainers = "0.15.0" -tokio = { version = "1.37.0", features = ["rt-multi-thread"] } -reqwest = { version = "0.12", features = ["rustls-tls"], default-features = false } -env_logger = "0.11.3" -log = "0.4.21" -headless_chrome = "1.0.9" +testcontainers = "0.23" +tokio = { version = "1.43", features = ["rt-multi-thread"] } +reqwest = { version = "0.11", features = ["rustls-tls"], default-features = false } +env_logger = "0.11" +log = "0.4" +headless_chrome = "1.0" diff --git a/examples/basic/src/lib.rs b/examples/basic/src/lib.rs index df77766..389d742 100644 --- a/examples/basic/src/lib.rs +++ b/examples/basic/src/lib.rs @@ -64,10 +64,11 @@ async fn authenticated(claims: OidcClaims) -> impl IntoRe format!("Hello {}", claims.subject().as_str()) } +#[axum::debug_handler] async fn maybe_authenticated( - claims: Option>, + claims: Result, axum_oidc::error::ExtractorError>, ) -> impl IntoResponse { - if let Some(claims) = claims { + if let Ok(claims) = claims { format!( "Hello {}! You are already logged in from another Handler.", claims.subject().as_str() diff --git a/examples/basic/tests/integration.rs b/examples/basic/tests/integration.rs index e4a014c..2d8b89b 100644 --- a/examples/basic/tests/integration.rs +++ b/examples/basic/tests/integration.rs @@ -2,7 +2,6 @@ mod keycloak; use headless_chrome::Browser; use log::info; -use testcontainers::*; use crate::keycloak::{Client, Keycloak, Realm, User}; @@ -10,8 +9,6 @@ use crate::keycloak::{Client, Keycloak, Realm, User}; async fn first() { env_logger::init(); - let docker = clients::Cli::default(); - let alice = User { username: "alice".to_string(), email: "alice@example.com".to_string(), @@ -25,14 +22,11 @@ async fn first() { client_secret: Some("123456".to_string()), }; - let keycloak = Keycloak::start( - vec![Realm { - name: "test".to_string(), - users: vec![alice.clone()], - clients: vec![basic_client.clone()], - }], - &docker, - ) + let keycloak = Keycloak::start(vec![Realm { + name: "test".to_string(), + users: vec![alice.clone()], + clients: vec![basic_client.clone()], + }]) .await; info!("starting basic example app"); diff --git a/examples/basic/tests/keycloak.rs b/examples/basic/tests/keycloak.rs index 961d544..d06a5d6 100644 --- a/examples/basic/tests/keycloak.rs +++ b/examples/basic/tests/keycloak.rs @@ -1,21 +1,20 @@ use log::info; use std::time::Duration; -use testcontainers::*; +use testcontainers::runners::AsyncRunner; +use testcontainers::ContainerAsync; use testcontainers::core::ExecCommand; -use testcontainers::{core::WaitFor, Container, Image, RunnableImage}; +use testcontainers::{core::WaitFor, Image, ImageExt}; struct KeycloakImage; impl Image for KeycloakImage { - type Args = Vec; - - fn name(&self) -> String { - "quay.io/keycloak/keycloak".to_string() + fn name(&self) -> &str { + "quay.io/keycloak/keycloak" } - fn tag(&self) -> String { - "latest".to_string() + fn tag(&self) -> &str { + "latest" } fn ready_conditions(&self) -> Vec { @@ -23,8 +22,8 @@ impl Image for KeycloakImage { } } -pub struct Keycloak<'a> { - container: Container<'a, KeycloakImage>, +pub struct Keycloak { + container: ContainerAsync, realms: Vec, url: String, } @@ -51,24 +50,28 @@ pub struct User { pub password: String, } -impl<'a> Keycloak<'a> { - pub async fn start(realms: Vec, docker: &'a clients::Cli) -> Keycloak<'a> { +impl Keycloak { + pub async fn start(realms: Vec) -> Keycloak { info!("starting keycloak"); - let keycloak_image = RunnableImage::from((KeycloakImage, vec!["start-dev".to_string()])) - .with_env_var(("KEYCLOAK_ADMIN", "admin")) - .with_env_var(("KEYCLOAK_ADMIN_PASSWORD", "admin")); - let container = docker.run(keycloak_image); + let keycloak_image = KeycloakImage + .with_cmd(["start-dev".to_string()]) + .with_env_var("KEYCLOAK_ADMIN", "admin") + .with_env_var("KEYCLOAK_ADMIN_PASSWORD", "admin"); + let container = keycloak_image.start().await.unwrap(); let keycloak = Self { - url: format!("http://127.0.0.1:{}", container.get_host_port_ipv4(8080),), + url: format!( + "http://127.0.0.1:{}", + container.get_host_port_ipv4(8080).await.unwrap() + ), container, realms, }; let issuer = format!( "http://127.0.0.1:{}/realms/{}", - keycloak.container.get_host_port_ipv4(8080), + keycloak.container.get_host_port_ipv4(8080).await.unwrap(), "test" ); @@ -172,9 +175,14 @@ impl<'a> Keycloak<'a> { } async fn execute(&self, cmd: String) { - self.container.exec(ExecCommand { - cmd, - ready_conditions: vec![], - }); + let mut result = self + .container + .exec(ExecCommand::new( + ["/bin/sh", "-c", cmd.as_str()].iter().copied(), + )) + .await + .unwrap(); + // collect stdout to wait until command completion + let _output = String::from_utf8(result.stdout_to_vec().await.unwrap()); } }