From 7fdd91526bad9ae131e3f89f165c114ba20310d2 Mon Sep 17 00:00:00 2001 From: Brian Stearns Date: Wed, 5 Jun 2024 21:59:01 -0400 Subject: [PATCH] Update tests for nulled reset tokens. --- examples/demo/tests/requests/auth.rs | 5 ++++- starters/rest-api/tests/requests/auth.rs | 5 ++++- starters/saas/src/models/users.rs | 2 ++ starters/saas/tests/requests/auth.rs | 5 ++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/demo/tests/requests/auth.rs b/examples/demo/tests/requests/auth.rs index 7ec736f7a..d04672f09 100644 --- a/examples/demo/tests/requests/auth.rs +++ b/examples/demo/tests/requests/auth.rs @@ -150,6 +150,7 @@ async fn can_reset_password() { .await .unwrap(); assert!(user.reset_token.is_some()); + assert!(user.reset_sent_at.is_some()); let new_password = "new-password"; let reset_payload = serde_json::json!({ @@ -162,7 +163,9 @@ async fn can_reset_password() { let user = users::Model::find_by_email(&ctx.db, &user.email) .await .unwrap(); - assert!(user.reset_sent_at.is_some()); + + assert!(user.reset_token.is_none()); + assert!(user.reset_sent_at.is_none()); assert_debug_snapshot!((reset_response.status_code(), reset_response.text())); diff --git a/starters/rest-api/tests/requests/auth.rs b/starters/rest-api/tests/requests/auth.rs index 110e410b0..5a996c899 100644 --- a/starters/rest-api/tests/requests/auth.rs +++ b/starters/rest-api/tests/requests/auth.rs @@ -156,6 +156,7 @@ async fn can_reset_password() { .await .unwrap(); assert!(user.reset_token.is_some()); + assert!(user.reset_sent_at.is_some()); let new_password = "new-password"; let reset_payload = serde_json::json!({ @@ -168,7 +169,9 @@ async fn can_reset_password() { let user = users::Model::find_by_email(&ctx.db, &user.email) .await .unwrap(); - assert!(user.reset_sent_at.is_some()); + + assert!(user.reset_token.is_none()); + assert!(user.reset_sent_at.is_none()); assert_debug_snapshot!((reset_response.status_code(), reset_response.text())); diff --git a/starters/saas/src/models/users.rs b/starters/saas/src/models/users.rs index fb5785201..3453957cf 100644 --- a/starters/saas/src/models/users.rs +++ b/starters/saas/src/models/users.rs @@ -290,6 +290,8 @@ impl super::_entities::users::ActiveModel { ) -> ModelResult { self.password = ActiveValue::set(hash::hash_password(password).map_err(|e| ModelError::Any(e.into()))?); + self.reset_token = ActiveValue::Set(None); + self.reset_sent_at = ActiveValue::Set(None); Ok(self.update(db).await?) } } diff --git a/starters/saas/tests/requests/auth.rs b/starters/saas/tests/requests/auth.rs index 110e410b0..5a996c899 100644 --- a/starters/saas/tests/requests/auth.rs +++ b/starters/saas/tests/requests/auth.rs @@ -156,6 +156,7 @@ async fn can_reset_password() { .await .unwrap(); assert!(user.reset_token.is_some()); + assert!(user.reset_sent_at.is_some()); let new_password = "new-password"; let reset_payload = serde_json::json!({ @@ -168,7 +169,9 @@ async fn can_reset_password() { let user = users::Model::find_by_email(&ctx.db, &user.email) .await .unwrap(); - assert!(user.reset_sent_at.is_some()); + + assert!(user.reset_token.is_none()); + assert!(user.reset_sent_at.is_none()); assert_debug_snapshot!((reset_response.status_code(), reset_response.text()));