use axum::extract::FromRef; use crate::{ login::Login, name::Name, test::{fixtures, verify}, token::{ app::{Tokens, ValidateError}, extract::IdentityCookie, }, }; pub async fn valid_for_name(app: &App, identity: &IdentityCookie, name: &Name) where Tokens: FromRef, { let secret = identity .secret() .expect("identity cookie must be set to be valid"); verify::token::valid_for_name(app, &secret, name).await; } pub async fn valid_for_login(app: &App, identity: &IdentityCookie, login: &Login) where Tokens: FromRef, { let secret = identity .secret() .expect("identity cookie must be set to be valid"); verify::token::valid_for_login(app, &secret, login).await; } pub async fn invalid(app: &App, identity: &IdentityCookie) where Tokens: FromRef, { let secret = identity .secret() .expect("identity cookie must be set to be invalid"); let validate_err = Tokens::from_ref(app) .validate(&secret, &fixtures::now()) .await .expect_err("identity cookie secret must be invalid"); assert!(matches!(validate_err, ValidateError::InvalidToken)); }