diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-10-28 01:41:13 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-10-28 02:08:45 -0400 |
| commit | dc7074bbf39aff895ba52abd5e7b7e9bb643cf27 (patch) | |
| tree | a6eea3af13f237393057aac1d80f024bc1b40b10 | |
| parent | 9bd5ea4b4292761b0b2f823c887f114459c80d8f (diff) | |
Convert the last stray tests to be generic over components deriveable from an App.
There are a few places in the test fixtures that still call `App` methods directly, as they call `app.users()` (which, as per previous commits, has no `FromRef` impl).
| -rw-r--r-- | src/test/fixtures/identity.rs | 21 | ||||
| -rw-r--r-- | src/test/verify/login.rs | 23 |
2 files changed, 31 insertions, 13 deletions
diff --git a/src/test/fixtures/identity.rs b/src/test/fixtures/identity.rs index 93e4a38..20929f9 100644 --- a/src/test/fixtures/identity.rs +++ b/src/test/fixtures/identity.rs @@ -1,11 +1,15 @@ +use axum::extract::FromRef; + use crate::{ app::App, clock::RequestedAt, + login::app::Logins, name::Name, password::Password, test::fixtures, token::{ Token, + app::Tokens, extract::{Identity, IdentityCookie}, }, }; @@ -15,23 +19,30 @@ pub async fn create(app: &App, created_at: &RequestedAt) -> Identity { logged_in(app, &credentials, created_at).await } -pub async fn from_cookie( +pub async fn from_cookie<App>( app: &App, cookie: &IdentityCookie, validated_at: &RequestedAt, -) -> Identity { +) -> Identity +where + Tokens: FromRef<App>, +{ let secret = cookie.secret().expect("identity token has a secret"); - app.tokens() + Tokens::from_ref(app) .validate(&secret, validated_at) .await .expect("always validates newly-issued secret") } -pub async fn logged_in( +pub async fn logged_in<App>( app: &App, credentials: &(Name, Password), issued_at: &RequestedAt, -) -> Identity { +) -> Identity +where + Tokens: FromRef<App>, + Logins: FromRef<App>, +{ let secret = fixtures::cookie::logged_in(app, credentials, issued_at).await; from_cookie(app, &secret, issued_at).await } diff --git a/src/test/verify/login.rs b/src/test/verify/login.rs index ae2e91e..aad01bc 100644 --- a/src/test/verify/login.rs +++ b/src/test/verify/login.rs @@ -1,23 +1,30 @@ +use axum::extract::FromRef; + use crate::{ - app::App, - login::app::LoginError, + login::app::{LoginError, Logins}, name::Name, password::Password, test::{fixtures, verify}, + token::app::Tokens, }; -pub async fn valid_login(app: &App, name: &Name, password: &Password) { - let secret = app - .logins() +pub async fn valid_login<App>(app: &App, name: &Name, password: &Password) +where + Logins: FromRef<App>, + Tokens: FromRef<App>, +{ + let secret = Logins::from_ref(app) .with_password(name, password, &fixtures::now()) .await .expect("login credentials expected to be valid"); verify::token::valid_for_name(&app, &secret, &name).await; } -pub async fn invalid_login(app: &App, name: &Name, password: &Password) { - let error = app - .logins() +pub async fn invalid_login<App>(app: &App, name: &Name, password: &Password) +where + Logins: FromRef<App>, +{ + let error = Logins::from_ref(app) .with_password(name, password, &fixtures::now()) .await .expect_err("login credentials expected not to be valid"); |
