summaryrefslogtreecommitdiff
path: root/src/user/handlers/login
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-08-24 16:37:41 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-08-26 00:57:57 -0400
commitc52e24f17ed615b2e2dd55a285eb272014a2ccbf (patch)
tree757fbef4a4e8236f831d859370e4774e86138bd5 /src/user/handlers/login
parent6c65e97e49d1d56380aa7d71abb0394b08ff60ca (diff)
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.
Diffstat (limited to 'src/user/handlers/login')
-rw-r--r--src/user/handlers/login/test.rs29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/user/handlers/login/test.rs b/src/user/handlers/login/test.rs
index cb387ad..56fc2c4 100644
--- a/src/user/handlers/login/test.rs
+++ b/src/user/handlers/login/test.rs
@@ -1,6 +1,10 @@
use axum::extract::{Json, State};
-use crate::{empty::Empty, test::fixtures, token::app};
+use crate::{
+ empty::Empty,
+ test::{fixtures, verify},
+ token::app,
+};
#[tokio::test]
async fn correct_credentials() {
@@ -24,19 +28,7 @@ async fn correct_credentials() {
// Verify the return value's basic structure
- let secret = identity
- .secret()
- .expect("logged in with valid credentials issues an identity cookie");
-
- // Verify the semantics
-
- let validated = app
- .tokens()
- .validate(&secret, &fixtures::now())
- .await
- .expect("identity secret is valid");
-
- assert_eq!(name, validated.user.name);
+ verify::identity::valid_for_name(&app, &identity, &name).await;
}
#[tokio::test]
@@ -114,12 +106,5 @@ async fn token_expires() {
.await
.expect("expiring tokens never fails");
- let verified_at = fixtures::now();
- let error = app
- .tokens()
- .validate(&secret, &verified_at)
- .await
- .expect_err("validating an expired token");
-
- assert!(matches!(error, app::ValidateError::InvalidToken));
+ verify::token::invalid(&app, &secret).await;
}