diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-08-24 16:37:41 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-08-26 00:57:57 -0400 |
| commit | c52e24f17ed615b2e2dd55a285eb272014a2ccbf (patch) | |
| tree | 757fbef4a4e8236f831d859370e4774e86138bd5 /src/test/verify/login.rs | |
| parent | 6c65e97e49d1d56380aa7d71abb0394b08ff60ca (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/test/verify/login.rs')
| -rw-r--r-- | src/test/verify/login.rs | 25 |
1 files changed, 25 insertions, 0 deletions
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)); +} |
