Skip to content

Commit

Permalink
Update tests for nulled reset tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
BWStearns committed Jun 6, 2024
1 parent 28c36b8 commit 7fdd915
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion examples/demo/tests/requests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand All @@ -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()));

Expand Down
5 changes: 4 additions & 1 deletion starters/rest-api/tests/requests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand All @@ -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()));

Expand Down
2 changes: 2 additions & 0 deletions starters/saas/src/models/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ impl super::_entities::users::ActiveModel {
) -> ModelResult<Model> {
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?)
}
}
5 changes: 4 additions & 1 deletion starters/saas/tests/requests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand All @@ -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()));

Expand Down

0 comments on commit 7fdd915

Please sign in to comment.