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/test/verify/login.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/verify/login.rs (limited to 'src/test/verify/login.rs') diff --git a/src/test/verify/login.rs b/src/test/verify/login.rs new file mode 100644 index 0000000..3f291a3 --- /dev/null +++ b/src/test/verify/login.rs @@ -0,0 +1,25 @@ +use crate::{ + app::App, + name::Name, + password::Password, + test::{fixtures, verify}, + token::app::LoginError, +}; + +pub async fn valid_login(app: &App, name: &Name, password: &Password) { + let secret = app + .tokens() + .login(&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 + .tokens() + .login(name, password, &fixtures::now()) + .await + .expect_err("login credentials expected not to be valid"); + assert!(matches!(error, LoginError::Rejected)); +} -- cgit v1.2.3