From c52e24f17ed615b2e2dd55a285eb272014a2ccbf Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sun, 24 Aug 2025 16:37:41 -0400 Subject: Factor out common authentication test verification steps into helpers. These checks tended to be wordy, and were prone to being done subtly differently in different locations for no good reason. Centralizing them cleans this up and makes the tests easier to follow, at the expense of making it somewhat harder to follow what the test is specifically checking. --- src/invite/handlers/accept/test.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/invite/handlers/accept/test.rs') diff --git a/src/invite/handlers/accept/test.rs b/src/invite/handlers/accept/test.rs index 5140e3f..4e4a09d 100644 --- a/src/invite/handlers/accept/test.rs +++ b/src/invite/handlers/accept/test.rs @@ -1,6 +1,11 @@ use axum::extract::{Json, Path, State}; -use crate::{empty::Empty, invite::app::AcceptError, name::Name, test::fixtures}; +use crate::{ + empty::Empty, + invite::app::AcceptError, + name::Name, + test::{fixtures, verify}, +}; #[tokio::test] async fn valid_invite() { @@ -34,15 +39,7 @@ async fn valid_invite() { // Verify that the issued token is valid - let secret = identity - .secret() - .expect("newly-issued identity has a token secret"); - let identity = app - .tokens() - .validate(&secret, &fixtures::now()) - .await - .expect("newly-issued identity cookie is valid"); - assert_eq!(name, identity.user.name); + verify::identity::valid_for_name(&app, &identity, &name).await; // Verify that the given credentials can log in @@ -51,12 +48,7 @@ async fn valid_invite() { .login(&name, &password, &fixtures::now()) .await .expect("credentials given on signup are valid"); - let identity = app - .tokens() - .validate(&secret, &fixtures::now()) - .await - .expect("validating a newly-issued token secret succeeds"); - assert_eq!(name, identity.user.name); + verify::token::valid_for_name(&app, &secret, &name).await; } #[tokio::test] -- cgit v1.2.3