From cc58b5f96b0a3b3b0956aa1777bec7390b29c51a Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 00:20:07 +0100 Subject: [PATCH 1/2] fix(admin): a dashboard change posted without a reason is refused on its page The handle reservation, the account's settings tabs, and the handle and display name pages failed to decode a form without a reason field, so the dashboard answered a bare 400. Their reason now defaults to empty, as the other forms' do, and the page asks for it again. --- apps/auth-service/src/web/admin/handles.rs | 1 + apps/auth-service/src/web/admin/settings.rs | 3 ++ .../src/web/admin/tests/operations.rs | 38 +++++++++++++++++++ docs/dev/architecture/surfaces.md | 17 +++++---- docs/dev/extending/admin-operation.md | 4 +- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/apps/auth-service/src/web/admin/handles.rs b/apps/auth-service/src/web/admin/handles.rs index 044270df0..7137141f3 100644 --- a/apps/auth-service/src/web/admin/handles.rs +++ b/apps/auth-service/src/web/admin/handles.rs @@ -31,6 +31,7 @@ struct Reservation { /// The handle to reserve. handle: String, /// Who or what it is kept for. + #[serde(default)] reason: String, } diff --git a/apps/auth-service/src/web/admin/settings.rs b/apps/auth-service/src/web/admin/settings.rs index 4a3237420..6b300f3a8 100644 --- a/apps/auth-service/src/web/admin/settings.rs +++ b/apps/auth-service/src/web/admin/settings.rs @@ -49,6 +49,7 @@ struct Administered { #[serde(flatten)] change: C, /// Why, recorded with the change and shown to the owner in their history. + #[serde(default)] reason: String, } @@ -58,6 +59,7 @@ struct NewHandle { /// The handle. handle: String, /// Why, recorded with the change and shown to the owner in their history. + #[serde(default)] reason: String, /// Whether a reserved handle, or one that looks like another, is allowed. #[serde(default)] @@ -70,6 +72,7 @@ struct NewDisplayName { /// The name. display_name: String, /// Why, recorded with the change and shown to the owner in their history. + #[serde(default)] reason: String, } diff --git a/apps/auth-service/src/web/admin/tests/operations.rs b/apps/auth-service/src/web/admin/tests/operations.rs index b7c0cc039..88f900fff 100644 --- a/apps/auth-service/src/web/admin/tests/operations.rs +++ b/apps/auth-service/src/web/admin/tests/operations.rs @@ -285,6 +285,44 @@ async fn handles_are_reserved_given_released_and_unreserved() { ); } +/// A change posted without a reason is refused on its page, which asks for one +/// again, whatever else its form takes: reserving a handle, whose form also takes +/// the handle, answers as unreserving one, whose form asks only why. Neither +/// fails to decode, and neither changes anything. +#[tokio::test] +#[ignore = "requires TEST_DATABASE_URL"] +async fn a_change_without_a_reason_is_refused_on_its_page() { + let harness = Harness::new().await; + let admin = harness.admin().await; + let dashboard = harness + .confirmed(&admin, "/handles/reserve", Utc::now()) + .await; + let kept = format!("unreasoned-{}", &admin.user_id.to_string()[24..]); + let post = async |path: &str, fields: &[(&str, &str)]| { + let url = format!("{DASHBOARD}{path}"); + dashboard + .submit(&harness.dashboard, &url, fields, OWN_PAGE) + .await + }; + let unreserve = format!("/handles/unreserve?handle={kept}"); + for (path, fields) in [ + ("/handles/reserve", [("handle", kept.as_str())].as_slice()), + (&unreserve, &[]), + ] { + let refused = post(path, fields).await; + assert_eq!(refused.status(), StatusCode::BAD_REQUEST, "{path}"); + let page = html(refused).await; + assert!( + page.contains("Give a reason of 1 to 500 characters"), + "{path}: {page}" + ); + assert!(page.contains(r#"name="reason""#), "{path}: {page}"); + assert!(page.contains(&kept), "still names the handle: {page}"); + } + let page = html(harness.visit(&dashboard, "/handles").await).await; + assert!(!page.contains(&kept), "nothing reserved: {page}"); +} + /// The Alerts page shows an open alert as needing attention, with posting an /// update on it, and the overview's banner leads there. An update is recorded /// as the administrator's, and the alert then shows its status and note. The diff --git a/docs/dev/architecture/surfaces.md b/docs/dev/architecture/surfaces.md index 8a27b3623..dc5840af3 100644 --- a/docs/dev/architecture/surfaces.md +++ b/docs/dev/architecture/surfaces.md @@ -291,14 +291,15 @@ When an administrator or operator acts: - Every change needs their reason, on the dashboard and at the terminal alike: changes to accounts, and to clients, keys, invitations, handles, deliveries, alerts and the audit history too. `AdminService` takes it by type, so no - change records an event without one. It is stored with each event as - personal data, and the owner of an account it changes sees it in their - security history, next to "By a SourceOrigin administrator". The owner never - sees who that administrator is, or the IP address and device of their - request: only the dashboard's event lists and `audit list` show them. Announcements - and messages to one account ask for none: their text says why, so sending - one records "See message contents", and a draft's own changes record - nothing. + change records an event without one. A dashboard change posted without one, + or with a blank one, is refused on its page, which asks for it again. It is + stored with each event as personal data, and the owner of an account it + changes sees it in their security history, next to "By a SourceOrigin + administrator". The owner never sees who that administrator is, or the IP + address and device of their request: only the dashboard's event lists and + `audit list` show them. Announcements and messages to one account ask for + none: their text says why, so sending one records "See message contents", + and a draft's own changes record nothing. - Events record the administrator or operator as their actor. Their reads are recorded as a view of the account, as `user show` is, once an hour per administrator session or operator. The owner's history leaves views out: it diff --git a/docs/dev/extending/admin-operation.md b/docs/dev/extending/admin-operation.md index e3f20eefa..5c11452af 100644 --- a/docs/dev/extending/admin-operation.md +++ b/docs/dev/extending/admin-operation.md @@ -174,7 +174,9 @@ pub(super) async fn reserve(cx: &Cx, form: Option>) -> Result< - `App::submit` makes the change, goes back to `back` once it is made, and otherwise returns the refusal, which the form shows with what was typed. A change whose form posts only its reason uses `App::submit_reason` and - `ReasonForm`, which parse the reason first. + `ReasonForm`, which parse the reason first. Every form's `reason` field is + `#[serde(default)]`, so a form posted without one decodes, and `Reason::parse` + refuses it on the page as it refuses a blank one. The page's words are a `Change` variant in `crates/ui/src/admin/mod.rs`: its title, description, button, label, whether it takes something away, and the From 561987b26dbfc111ec38d5a326fd0c0b191abf4a Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 14:44:46 +0100 Subject: [PATCH 2/2] test(admin): every form that failed to decode without a reason is covered The test now posts without a reason to the account's handle and display name pages and its emails tab, and unreserves a handle that is reserved, checking that nothing changes. The surfaces page says what is stored. --- .../src/web/admin/tests/operations.rs | 61 ++++++++++++++++--- docs/dev/architecture/surfaces.md | 8 +-- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/apps/auth-service/src/web/admin/tests/operations.rs b/apps/auth-service/src/web/admin/tests/operations.rs index 88f900fff..9bc3451f7 100644 --- a/apps/auth-service/src/web/admin/tests/operations.rs +++ b/apps/auth-service/src/web/admin/tests/operations.rs @@ -285,29 +285,64 @@ async fn handles_are_reserved_given_released_and_unreserved() { ); } -/// A change posted without a reason is refused on its page, which asks for one -/// again, whatever else its form takes: reserving a handle, whose form also takes -/// the handle, answers as unreserving one, whose form asks only why. Neither -/// fails to decode, and neither changes anything. +/// A change posted without a reason is refused on its page, which asks for one, +/// whatever else its form takes and however the page decodes it: reserving and +/// unreserving a handle, changing an account's handle and display name, and the +/// settings tabs, which read their form from the body themselves. None fails to +/// decode, and none changes anything. #[tokio::test] #[ignore = "requires TEST_DATABASE_URL"] async fn a_change_without_a_reason_is_refused_on_its_page() { let harness = Harness::new().await; let admin = harness.admin().await; + let owner = Browser::new_account(&harness.database).await; + let user = owner.user_id; + let suffix = &user.to_string()[24..]; + let (kept, fresh) = (format!("kept-{suffix}"), format!("fresh-{suffix}")); + let primary = format!("primary-{user}@example.com"); + crate::tests::verified_address(&harness.database, user, &primary, true).await; + let address = format!("other-{user}@example.com"); + let other = crate::tests::verified_address(&harness.database, user, &address, false) + .await + .to_string(); + let stored = async || { + harness + .database + .users() + .find_by_id(user) + .await + .expect("lookup") + .expect("user") + }; + let before = stored().await; let dashboard = harness .confirmed(&admin, "/handles/reserve", Utc::now()) .await; - let kept = format!("unreasoned-{}", &admin.user_id.to_string()[24..]); let post = async |path: &str, fields: &[(&str, &str)]| { let url = format!("{DASHBOARD}{path}"); dashboard .submit(&harness.dashboard, &url, fields, OWN_PAGE) .await }; + let reserve = [("handle", kept.as_str()), REASON]; + assert_eq!( + redirect(&post("/handles/reserve", &reserve).await), + "/handles" + ); + let unreserve = format!("/handles/unreserve?handle={kept}"); + let (handle, name, emails) = ( + format!("/users/{user}/handle"), + format!("/users/{user}/name"), + format!("/users/{user}/emails"), + ); + let remove = [("action", "remove"), ("id", other.as_str())]; for (path, fields) in [ - ("/handles/reserve", [("handle", kept.as_str())].as_slice()), + ("/handles/reserve", [("handle", fresh.as_str())].as_slice()), (&unreserve, &[]), + (&handle, &[("handle", fresh.as_str())]), + (&name, &[("display_name", "Renamed by support")]), + (&emails, &remove), ] { let refused = post(path, fields).await; assert_eq!(refused.status(), StatusCode::BAD_REQUEST, "{path}"); @@ -316,11 +351,19 @@ async fn a_change_without_a_reason_is_refused_on_its_page() { page.contains("Give a reason of 1 to 500 characters"), "{path}: {page}" ); - assert!(page.contains(r#"name="reason""#), "{path}: {page}"); - assert!(page.contains(&kept), "still names the handle: {page}"); } + let page = html(harness.visit(&dashboard, "/handles").await).await; - assert!(!page.contains(&kept), "nothing reserved: {page}"); + assert!(page.contains(&unreserve), "still reserved: {page}"); + assert!(!page.contains(&fresh), "nothing reserved: {page}"); + let after = stored().await; + assert_eq!(after.handle, before.handle); + assert_eq!(after.display_name, before.display_name); + let addresses = harness.database.emails().list(user).await.expect("emails"); + assert!( + addresses.iter().any(|email| email.id.to_string() == other), + "the address stays" + ); } /// The Alerts page shows an open alert as needing attention, with posting an diff --git a/docs/dev/architecture/surfaces.md b/docs/dev/architecture/surfaces.md index dc5840af3..bc6ee8df8 100644 --- a/docs/dev/architecture/surfaces.md +++ b/docs/dev/architecture/surfaces.md @@ -292,10 +292,10 @@ When an administrator or operator acts: changes to accounts, and to clients, keys, invitations, handles, deliveries, alerts and the audit history too. `AdminService` takes it by type, so no change records an event without one. A dashboard change posted without one, - or with a blank one, is refused on its page, which asks for it again. It is - stored with each event as personal data, and the owner of an account it - changes sees it in their security history, next to "By a SourceOrigin - administrator". The owner never sees who that administrator is, or the IP + or with a blank one, is refused on its page, which asks for it again. The + reason is stored with each event as personal data, and the owner of an + account it changes sees it in their security history, next to "By a + SourceOrigin administrator". The owner never sees who that administrator is, or the IP address and device of their request: only the dashboard's event lists and `audit list` show them. Announcements and messages to one account ask for none: their text says why, so sending one records "See message contents",