From fa4ad8458225c5c801c88e1bacea7847d7cf19ba Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sun, 8 Nov 2026 23:12:18 -0700 Subject: [PATCH] Restore a kept account that never had a password (#326) Restoring a kept user replaced the password credential it had with the new password, and refused when there was none: "The kept account has no password credential." A user created without a password could be destroyed from Deleted Accounts, but never restored. The new password is now set the way setting one on a live account does: it replaces the password credential, or becomes one when there isn't one. Its expiry follows the server's default as before, and the other credentials stay. The undelete test restores a user created with no password and signs in with the new one. Reported on the forum (t/232, post 8). --- crates/jmap/src/inbuxa/deleted_account.rs | 22 ++++--------- tests/src/system/undelete.rs | 39 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/crates/jmap/src/inbuxa/deleted_account.rs b/crates/jmap/src/inbuxa/deleted_account.rs index 99894e3d..06ba0013 100644 --- a/crates/jmap/src/inbuxa/deleted_account.rs +++ b/crates/jmap/src/inbuxa/deleted_account.rs @@ -35,7 +35,7 @@ use registry::{ schema::{ enums::{AccountType, Permission}, prelude::{Object, ObjectInner, ObjectType, Property}, - structs::{Account, Credential, Task, TaskDestroyAccount, TaskStatus}, + structs::{Account, Task, TaskDestroyAccount, TaskStatus}, }, types::{EnumImpl, datetime::UTCDateTime, id::ObjectId}, }; @@ -424,21 +424,11 @@ async fn restore_account( .security .password_default_expiration .map(|expires| UTCDateTime::from_timestamp((now() + expires) as i64)); - match user - .credentials - .values_mut() - .find_map(|credential| match credential { - Credential::Password(credential) => Some(credential), - _ => None, - }) { - Some(credential) => { - credential.secret = secret; - credential.expires_at = expires_at; - } - None => { - return Ok(Err(SetError::forbidden() - .with_description("The kept account has no password credential."))); - } + // A user that never had a password gets one, the way setting a + // password on a live account does (#326) + user.set_password(secret); + if let Some(credential) = user.password_credential_mut() { + credential.expires_at = expires_at; } } diff --git a/tests/src/system/undelete.rs b/tests/src/system/undelete.rs index 176b4a90..e9985a07 100644 --- a/tests/src/system/undelete.rs +++ b/tests/src/system/undelete.rs @@ -27,7 +27,10 @@ use jmap_proto::error::set::SetErrorType; use registry::{ schema::{ prelude::{ObjectType, Property}, - structs::{DataRetention, Expression, Imap, Jmap, MtaStageAuth, MtaStageRcpt, Task}, + structs::{ + self, DataRetention, Expression, Imap, Jmap, MtaStageAuth, MtaStageRcpt, Task, + UserAccount, + }, }, types::duration::Duration, }; @@ -644,6 +647,40 @@ pub async fn test(test: &mut TestServer) { test.wait_for_tasks().await; assert!(admin.deleted_accounts().await.is_empty(), "test 14: gone"); assert!(!pending_destroy(test, gone_id).await); + + // A user created with no password comes back with the new one (#326) + let domain_id = admin.find_or_create_domain("example.org").await; + let no_password_id = admin + .registry_create_object(structs::Account::User(UserAccount { + name: "nopass".into(), + domain_id, + ..Default::default() + })) + .await; + admin + .registry_destroy(ObjectType::Account, [no_password_id]) + .await + .assert_destroyed(&[no_password_id]); + admin + .deleted_account_set(json!({"update": {no_password_id.to_string(): { + "restore": true, "password": SECRET + }}})) + .await + .updated_id(no_password_id); + let mut no_password = Account::new("nopass@example.org", SECRET, &[], "", no_password_id); + no_password.http_listener_port = admin.http_listener_port; + assert_eq!( + no_password.count_with_subject("Anything").await, + 0, + "test 14: signs in with the new password" + ); + admin.destroy_account(no_password).await; + admin + .deleted_account_set(json!({"destroy": [no_password_id.to_string()]})) + .await + .assert_destroyed(&[no_password_id]); + test.wait_for_tasks().await; + assert!(admin.deleted_accounts().await.is_empty()); admin.set_account_retention(None).await; let again = admin .create_user_account("gone@example.org", SECRET, "Gone", &[], vec![]) -- 2.54.0