use crate::{ app::App, name::Name, test::{fixtures, verify}, token::{app::ValidateError, extract::IdentityCookie}, user::User, }; pub async fn valid_for_name(app: &App, identity: &IdentityCookie, name: &Name) { 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_user(app: &App, identity: &IdentityCookie, user: &User) { let secret = identity .secret() .expect("identity cookie must be set to be valid"); verify::token::valid_for_user(app, &secret, user).await; } pub async fn invalid(app: &App, identity: &IdentityCookie) { let secret = identity .secret() .expect("identity cookie must be set to be invalid"); let validate_err = app .tokens() .validate(&secret, &fixtures::now()) .await .expect_err("identity cookie secret must be invalid"); assert!(matches!(validate_err, ValidateError::InvalidToken)); }