From 0b17080f1f2da134e7571c6827d64fc6a1f177c1 Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Sat, 18 Apr 2026 20:52:36 +0200 Subject: [PATCH] Bootstrap fixes --- crates/common/src/manager/defaults.rs | 17 +++++++++++------ crates/jmap/src/registry/mapping/bootstrap.rs | 16 ++++++++++++++-- crates/registry/src/schema/structs_impl.rs | 2 +- tests/resources/scripts/create_test_users.sh | 18 ------------------ 4 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 tests/resources/scripts/create_test_users.sh diff --git a/crates/common/src/manager/defaults.rs b/crates/common/src/manager/defaults.rs index 3b44b212..6e27256c 100644 --- a/crates/common/src/manager/defaults.rs +++ b/crates/common/src/manager/defaults.rs @@ -47,13 +47,13 @@ impl BootstrapDefaults for Bootstrap { } async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> { - if bp.registry.is_recovery_mode() { - return Ok(()); - } + let is_recovery_mode = bp.registry.is_recovery_mode(); + let is_bootstrap_mode = bp.registry.is_bootstrap_mode(); #[cfg(not(feature = "test_mode"))] - if bp.registry.count_object(ObjectType::Application).await? == 0 { - bp.registry + if !is_recovery_mode || is_bootstrap_mode { + if bp.registry.count_object(ObjectType::Application).await? == 0 { + bp.registry .write(RegistryWrite::insert( &Application { auto_update_frequency: Duration::from_millis(30 * 24 * 60 * 60 * 1000), @@ -71,9 +71,10 @@ async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> { .into(), )) .await?; + } } - if bp.registry.is_bootstrap_mode() { + if is_bootstrap_mode { #[cfg(not(any(feature = "dev_mode", feature = "test_mode")))] if bp.registry.count_object(ObjectType::SystemSettings).await? == 0 { bp.registry @@ -90,6 +91,10 @@ async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> { return Ok(()); } + if is_recovery_mode { + return Ok(()); + } + if bp.registry.count_object(ObjectType::MtaQueueQuota).await? == 0 { bp.registry .write(RegistryWrite::insert( diff --git a/crates/jmap/src/registry/mapping/bootstrap.rs b/crates/jmap/src/registry/mapping/bootstrap.rs index 3708db39..2308b9c3 100644 --- a/crates/jmap/src/registry/mapping/bootstrap.rs +++ b/crates/jmap/src/registry/mapping/bootstrap.rs @@ -5,10 +5,13 @@ */ use crate::registry::{ - mapping::{RegistryGetResponse, RegistrySetResponse}, + mapping::{RegistryGetResponse, RegistrySetResponse, map_bootstrap_error}, set::map_write_error, }; -use common::{DATABASE_SCHEMA_VERSION, Server, network::acme::account::acme_create_account, psl}; +use common::{ + DATABASE_SCHEMA_VERSION, Server, config::storage::Storage, + network::acme::account::acme_create_account, psl, +}; use directory::core::secret::hash_secret; use jmap_proto::error::set::{SetError, SetErrorType}; use jmap_tools::{JsonPointer, JsonPointerItem, Key}; @@ -244,6 +247,15 @@ pub(crate) async fn bootstrap_set( } } } + let mut bp_check = + store::registry::bootstrap::Bootstrap::new_uninitialized(tmp_registry.clone()); + let _ = Storage::parse(&mut bp_check).await; + if !bp_check.errors.is_empty() { + set.response + .not_updated + .append(id, map_bootstrap_error(bp_check.errors)); + break 'outer; + } // Create inner store let registry = diff --git a/crates/registry/src/schema/structs_impl.rs b/crates/registry/src/schema/structs_impl.rs index 74f09f5a..2243dd35 100644 --- a/crates/registry/src/schema/structs_impl.rs +++ b/crates/registry/src/schema/structs_impl.rs @@ -37939,7 +37939,7 @@ impl Default for TracerLog { path: Default::default(), prefix: "stalwart".to_string(), rotate: LogRotateFrequency::Daily, - ansi: false, + ansi: true, multiline: false, enable: true, level: TracingLevel::Info, diff --git a/tests/resources/scripts/create_test_users.sh b/tests/resources/scripts/create_test_users.sh deleted file mode 100644 index 4d0094d5..00000000 --- a/tests/resources/scripts/create_test_users.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -export URL="https://127.0.0.1:443" CREDENTIALS="admin:secret" - -cargo run -p stalwart-cli -- domain create example.org -cargo run -p stalwart-cli -- account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org -cargo run -p stalwart-cli -- account create jane abcde -d "Jane Doe" -a jane@example.org -cargo run -p stalwart-cli -- account create bill xyz12 -d "Bill Foobar" -a bill@example.org -cargo run -p stalwart-cli -- group create sales -d "Sales Department" -cargo run -p stalwart-cli -- group create support -d "Technical Support" -cargo run -p stalwart-cli -- account add-to-group john sales support -cargo run -p stalwart-cli -- account remove-from-group john support -cargo run -p stalwart-cli -- account add-email jane jane.doe@example.org -cargo run -p stalwart-cli -- list create everyone everyone@example.org -cargo run -p stalwart-cli -- list add-members everyone jane john bill -cargo run -p stalwart-cli -- account list -cargo run -p stalwart-cli -- import messages --format mbox john _ignore/dovecot-crlf -cargo run -p stalwart-cli -- import messages --format maildir john /var/mail/john