forge
Explore
Log in

Don't you dare go Hollow

Send a test mail to yourself and keep the result

Browse files at this commit

08366ca895393c4e84cb7d351a2466fc7c4b30f9Ahmet Kaan GümüşParent: 3836ec3
  • feat
    • send a test mail to yourself and keep the result
Show full message
✨ feat(settings): send a test mail to yourself and keep the result

The sender panel could be filled in and saved, but nothing told an admin
whether what they saved actually works. The artboard answers that with a
row under the fields — `delivered in 1.2 s — Aug 25 10:41` — so the result
has to survive a reload, not live in a signal that a refresh throws away.

- `send_test_mail` is admin-only in the handler, refuses when no sender is
  saved rather than burning a send, and mails only the caller's own address:
  a test pointable at a typed address would be a way to make Dizey mail a
  stranger on demand.
- The outcome is stored on the workspace (migration 0009) and cleared by
  `set_sender`, so a green line never sits under settings nobody has tried.
- Forms cannot nest, so the test form sits beside the settings form in a
  split foot and Save reaches back with `form="sender-settings"` — which
  works with and without script.
- `.panel-foot` now sets `flex-direction: row`: a foot inside a `.panel-body`
  was inheriting that column and stacking the sign-out row centred.

Verified in a headless browser: pressing the button with no sender saved
says so; with a sender pointed at a closed port the row reads
`not delivered, Aug 26 13:25 — Connection error: Connection refused (os
error 111)` and is still there after a reload. The `delivered in 1.2 s`
formatting is gated by a unit test, not by a live send.
crates/dizey-core/migrations/0009_sender_test.sqladded+14 -0
@@ -0,0 +1,14 @@
1+-- The result of the last "send test mail to myself", kept on the workspace.
2+--
3+-- It is kept rather than shown once because of what the panel is for: an admin
4+-- fills the sender in, presses the button, and comes back tomorrow wondering
5+-- whether it ever worked. A result that vanished on reload would answer that
6+-- question with silence, and silence is what the whole mail ledger exists to
7+-- avoid.
8+--
9+-- `smtp_test_error` is the mail server's own words, kept so the admin can act
10+-- on them. Nothing writes the password into it: the mailer builds its errors
11+-- from what the server said, never from the credentials it sent.
12+ALTER TABLE workspace ADD COLUMN smtp_test_at INTEGER;
13+ALTER TABLE workspace ADD COLUMN smtp_test_ms INTEGER;
14+ALTER TABLE workspace ADD COLUMN smtp_test_error TEXT;
crates/dizey-core/src/mail.rsmodified+23 -0
@@ -137,6 +137,29 @@ impl Engine {
137 }137 }
138 }138 }
139 139
140+ /// Sends one mail to the address given, right now, and says how long the
141+ /// mail server took to accept it.
142+ ///
143+ /// This is the only send that does not go through the ledger, and that is
144+ /// deliberate: a test mail is owed to nobody. If it fails there is nothing
145+ /// to retry and nothing to abandon — the person who pressed the button is
146+ /// watching, and the answer is for them.
147+ pub async fn send_test(&self, to: &str) -> std::result::Result<Duration, MailError> {
148+ let mail = Outgoing {
149+ to: to.to_string(),
150+ subject: "Dizey test mail".to_string(),
151+ body: "Somebody pressed the test button in Dizey's settings, and this \
152+ is what came out. Nothing else was sent, and nobody else was \
153+ written to.\n"
154+ .to_string(),
155+ };
156+ let started = std::time::Instant::now();
157+ self.mailer.send(&mail).await?;
158+ Ok(Duration::milliseconds(
159+ started.elapsed().as_millis().min(i64::MAX as u128) as i64,
160+ ))
161+ }
162+
140 /// Everything one crossing owes. Called after the move has committed, never163 /// Everything one crossing owes. Called after the move has committed, never
141 /// inside it.164 /// inside it.
142 pub async fn on_transition(&self, transition: &Transition) -> crate::store::Result<Report> {165 pub async fn on_transition(&self, transition: &Transition) -> crate::store::Result<Report> {
crates/dizey-core/src/store/mod.rsmodified+20 -0
@@ -56,6 +56,9 @@ pub struct Workspace {
56 /// Whether a password is stored, never the password. Derived in the query56 /// Whether a password is stored, never the password. Derived in the query
57 /// so that the value itself does not travel even this far.57 /// so that the value itself does not travel even this far.
58 pub smtp_password_set: bool,58 pub smtp_password_set: bool,
59+ /// How the last "send test mail to myself" went, if one has been pressed
60+ /// since the sender was last edited.
61+ pub sender_test: Option<SenderTest>,
59 pub attachment_limit_bytes: u64,62 pub attachment_limit_bytes: u64,
60 pub photo_limit_bytes: u64,63 pub photo_limit_bytes: u64,
61 pub allowed_file_types: Vec<String>,64 pub allowed_file_types: Vec<String>,
@@ -67,6 +70,19 @@ pub struct Workspace {
67 /// the screen sends when a password is already stored: the field is write-only,70 /// the screen sends when a password is already stored: the field is write-only,
68 /// so an edit to the port must not blank the password just because the form had71 /// so an edit to the port must not blank the password just because the form had
69 /// nothing to put in it.72 /// nothing to put in it.
73+/// What came of pressing the test button: when, how long the mail server took,
74+/// and what it said if it refused.
75+///
76+/// `error` is `None` for a mail that was accepted. It holds the mail server's
77+/// own words otherwise, because "it did not work" is not something an admin can
78+/// act on and "535 authentication failed" is.
79+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80+pub struct SenderTest {
81+ pub at: OffsetDateTime,
82+ pub took_ms: u64,
83+ pub error: Option<String>,
84+}
85+
70 #[derive(Debug, Clone, PartialEq)]86 #[derive(Debug, Clone, PartialEq)]
71 pub struct NewSender {87 pub struct NewSender {
72 pub host: String,88 pub host: String,
@@ -322,6 +338,10 @@ pub trait Store: BoardReads + DetailReads + 'static {
322 /// screen was never allowed to show them.338 /// screen was never allowed to show them.
323 async fn set_sender(&self, workspace_id: &str, sender: NewSender) -> Result<()>;339 async fn set_sender(&self, workspace_id: &str, sender: NewSender) -> Result<()>;
324 340
341+ /// Writes down how the last test send went. Editing the sender clears it,
342+ /// so what is stored is always about the settings that are stored.
343+ async fn record_sender_test(&self, workspace_id: &str, test: SenderTest) -> Result<()>;
344+
325 /// Reads the sender's password. Only the mailer calls this, and nothing it345 /// Reads the sender's password. Only the mailer calls this, and nothing it
326 /// returns reaches a response body.346 /// returns reaches a response body.
327 async fn smtp_password(&self, workspace_id: &str) -> Result<Option<String>>;347 async fn smtp_password(&self, workspace_id: &str) -> Result<Option<String>>;
crates/dizey-core/src/store/turso_store.rsmodified+35 -3
@@ -15,7 +15,7 @@ use uuid::Uuid;
15 use super::{15 use super::{
16 Audience, Deletion, Event, Freeing, MailRule, MailSend, NewSender, NewTask, NewUser, Recipient,16 Audience, Deletion, Event, Freeing, MailRule, MailSend, NewSender, NewTask, NewUser, Recipient,
17 Result,17 Result,
18- SendState, Session, SigninLink, Store, StoreError, Trigger, User, Workspace,18+ SendState, SenderTest, Session, SigninLink, Store, StoreError, Trigger, User, Workspace,
19 };19 };
20 use crate::Role;20 use crate::Role;
21 use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition};21 use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition};
@@ -36,6 +36,7 @@ const MIGRATIONS: &[(i64, &str)] = &[
36 (6, include_str!("../../migrations/0006_sender_is_config.sql")),36 (6, include_str!("../../migrations/0006_sender_is_config.sql")),
37 (7, include_str!("../../migrations/0007_who_invited.sql")),37 (7, include_str!("../../migrations/0007_who_invited.sql")),
38 (8, include_str!("../../migrations/0008_sender_is_settings.sql")),38 (8, include_str!("../../migrations/0008_sender_is_settings.sql")),
39+ (9, include_str!("../../migrations/0009_sender_test.sql")),
39 ];40 ];
40 41
41 /// The board a fresh workspace gets, and its columns. `Done` is the column42 /// The board a fresh workspace gets, and its columns. `Done` is the column
@@ -351,6 +352,14 @@ fn workspace_from(row: &Row) -> Result<Workspace> {
351 smtp_from_name: opt_text(row, 9)?,352 smtp_from_name: opt_text(row, 9)?,
352 smtp_from_address: opt_text(row, 10)?,353 smtp_from_address: opt_text(row, 10)?,
353 smtp_password_set: row.get::<i64>(11).map_err(backend)? != 0,354 smtp_password_set: row.get::<i64>(11).map_err(backend)? != 0,
355+ sender_test: match opt_stamp(row, 12)? {
356+ Some(at) => Some(SenderTest {
357+ at,
358+ took_ms: row.get::<i64>(13).map_err(backend)?.max(0) as u64,
359+ error: opt_text(row, 14)?,
360+ }),
361+ None => None,
362+ },
354 })363 })
355 }364 }
356 365
@@ -360,7 +369,8 @@ fn workspace_from(row: &Row) -> Result<Workspace> {
360 const WORKSPACE_COLUMNS: &str = "id, name, created_at, attachment_limit_bytes, \369 const WORKSPACE_COLUMNS: &str = "id, name, created_at, attachment_limit_bytes, \
361 allowed_file_types, photo_limit_bytes, smtp_host, smtp_port, smtp_username, \370 allowed_file_types, photo_limit_bytes, smtp_host, smtp_port, smtp_username, \
362 smtp_from_name, smtp_from_address, \371 smtp_from_name, smtp_from_address, \
363- (smtp_password IS NOT NULL AND smtp_password <> '')";372+ (smtp_password IS NOT NULL AND smtp_password <> ''), \
373+ smtp_test_at, smtp_test_ms, smtp_test_error";
364 374
365 fn user_from(row: &Row) -> Result<User> {375 fn user_from(row: &Row) -> Result<User> {
366 Ok(User {376 Ok(User {
@@ -535,11 +545,16 @@ impl Store for TursoStore {
535 // screen sends no password when the admin did not type one, and the545 // screen sends no password when the admin did not type one, and the
536 // stored secret survives an edit to the port. Passing an empty string546 // stored secret survives an edit to the port. Passing an empty string
537 // is not a way to blank it either — the form sends `None` for empty.547 // is not a way to blank it either — the form sends `None` for empty.
548+ //
549+ // The last test result is cleared by the same statement. It was about
550+ // the settings that have just been replaced, and a green "delivered"
551+ // line under a host nobody has tried yet is worse than no line at all.
538 self.conn552 self.conn
539 .execute(553 .execute(
540 "UPDATE workspace SET smtp_host = ?1, smtp_port = ?2, smtp_username = ?3, \554 "UPDATE workspace SET smtp_host = ?1, smtp_port = ?2, smtp_username = ?3, \
541 smtp_password = COALESCE(?4, smtp_password), smtp_from_name = ?5, \555 smtp_password = COALESCE(?4, smtp_password), smtp_from_name = ?5, \
542- smtp_from_address = ?6 WHERE id = ?7",556+ smtp_from_address = ?6, smtp_test_at = NULL, smtp_test_ms = NULL, \
557+ smtp_test_error = NULL WHERE id = ?7",
543 params![558 params![
544 sender.host,559 sender.host,
545 sender.port as i64,560 sender.port as i64,
@@ -555,6 +570,23 @@ impl Store for TursoStore {
555 Ok(())570 Ok(())
556 }571 }
557 572
573+ async fn record_sender_test(&self, workspace_id: &str, test: SenderTest) -> Result<()> {
574+ self.conn
575+ .execute(
576+ "UPDATE workspace SET smtp_test_at = ?1, smtp_test_ms = ?2, \
577+ smtp_test_error = ?3 WHERE id = ?4",
578+ params![
579+ stamp(test.at)?,
580+ test.took_ms as i64,
581+ test.error,
582+ workspace_id
583+ ],
584+ )
585+ .await
586+ .map_err(backend)?;
587+ Ok(())
588+ }
589+
558 async fn smtp_password(&self, workspace_id: &str) -> Result<Option<String>> {590 async fn smtp_password(&self, workspace_id: &str) -> Result<Option<String>> {
559 match self591 match self
560 .one_row(592 .one_row(
crates/dizey-core/tests/store.rsmodified+2 -2
@@ -89,14 +89,14 @@ async fn migrations_apply_once_and_survive_reopen() {
89 let path = dir.join("dizey.db").to_string_lossy().into_owned();89 let path = dir.join("dizey.db").to_string_lossy().into_owned();
90 90
91 let first = TursoStore::open(&path).await.unwrap();91 let first = TursoStore::open(&path).await.unwrap();
92- assert_eq!(first.schema_version().await.unwrap(), 8);92+ assert_eq!(first.schema_version().await.unwrap(), 9);
93 claim(&first).await;93 claim(&first).await;
94 drop(first);94 drop(first);
95 95
96 // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and96 // Re-opening must not re-run 0001 (which would fail on CREATE TABLE) and
97 // must not lose what the first open wrote.97 // must not lose what the first open wrote.
98 let second = TursoStore::open(&path).await.unwrap();98 let second = TursoStore::open(&path).await.unwrap();
99- assert_eq!(second.schema_version().await.unwrap(), 8);99+ assert_eq!(second.schema_version().await.unwrap(), 9);
100 assert_eq!(second.workspace().await.unwrap().unwrap().name, "Dizey");100 assert_eq!(second.workspace().await.unwrap().unwrap().name, "Dizey");
101 drop(second);101 drop(second);
102 let _ = std::fs::remove_dir_all(&dir);102 let _ = std::fs::remove_dir_all(&dir);
crates/dizey-web/src/server.rsmodified+8 -0
@@ -73,6 +73,14 @@ impl Mail {
73 });73 });
74 }74 }
75 75
76+ /// Sends one test mail and waits for the answer, because the answer is the
77+ /// whole point of pressing the button. `None` means this process has no
78+ /// engine at all, which happens only in tests.
79+ pub async fn test(&self, to: &str) -> Option<Result<time::Duration, dizey_core::MailError>> {
80+ let engine = self.0.clone()?;
81+ Some(engine.send_test(to).await)
82+ }
83+
76 fn log(report: dizey_core::store::Result<dizey_core::mail::Report>) {84 fn log(report: dizey_core::store::Result<dizey_core::mail::Report>) {
77 match report {85 match report {
78 Ok(report) if report.sent + report.failed + report.abandoned > 0 => {86 Ok(report) if report.sent + report.failed + report.abandoned > 0 => {
crates/dizey-web/src/settings.rsmodified+172 -4
@@ -26,6 +26,20 @@ pub struct Sender {
26 pub from_name: String,26 pub from_name: String,
27 pub from_address: String,27 pub from_address: String,
28 pub password_set: bool,28 pub password_set: bool,
29+ /// The last test result, as the panel prints it, or nothing when the button
30+ /// has not been pressed since the sender was last edited.
31+ pub test: Option<TestResult>,
32+}
33+
34+/// What the row under the test button says.
35+#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
36+pub struct TestResult {
37+ /// `Aug 25 10:41`, in UTC, the same stamp the activity strip uses.
38+ pub moment: String,
39+ /// `1.2 s`, or nothing when the send never got as far as being timed.
40+ pub took: Option<String>,
41+ /// What the mail server said, if it refused.
42+ pub error: Option<String>,
29 }43 }
30 44
31 impl Sender {45 impl Sender {
@@ -52,10 +66,27 @@ impl Sender {
52 from_name: workspace.smtp_from_name.clone().unwrap_or_default(),66 from_name: workspace.smtp_from_name.clone().unwrap_or_default(),
53 from_address: workspace.smtp_from_address.clone().unwrap_or_default(),67 from_address: workspace.smtp_from_address.clone().unwrap_or_default(),
54 password_set: workspace.smtp_password_set,68 password_set: workspace.smtp_password_set,
69+ test: workspace.sender_test.as_ref().map(|test| TestResult {
70+ moment: dizey_core::detail::moment_label(test.at),
71+ took: test.error.is_none().then(|| took_label(test.took_ms)),
72+ error: test.error.clone(),
73+ }),
55 }74 }
56 }75 }
57 }76 }
58 77
78+/// `1.2 s` for anything over a second, `840 ms` below it. A mail server that
79+/// answered in under a second is worth saying so precisely; one that took eight
80+/// is worth a number somebody can compare to the last one.
81+#[cfg(feature = "ssr")]
82+fn took_label(ms: u64) -> String {
83+ if ms >= 1000 {
84+ format!("{:.1} s", ms as f64 / 1000.0)
85+ } else {
86+ format!("{ms} ms")
87+ }
88+}
89+
59 /// The workspace's limits, as the panel edits them. Megabytes here and bytes90 /// The workspace's limits, as the panel edits them. Megabytes here and bytes
60 /// in the store: the field says "25 MB per file" and a person typing 25 into91 /// in the store: the field says "25 MB per file" and a person typing 25 into
61 /// it should not have to know what that is in bytes.92 /// it should not have to know what that is in bytes.
@@ -352,6 +383,62 @@ pub async fn save_sender(
352 }383 }
353 }384 }
354 385
386+/// Sends one mail to the admin who pressed the button, and writes down how it
387+/// went so the answer survives a reload.
388+///
389+/// It goes to their own address and nowhere else. A test that could be pointed
390+/// at an address somebody typed would be a way to make Dizey mail a stranger
391+/// on demand, which is a thing worth not building.
392+#[server]
393+pub async fn send_test_mail() -> Result<Option<Refusal>, ServerFnError> {
394+ use crate::server::{accounts, mail, require_admin};
395+ use dizey_core::store::SenderTest;
396+
397+ let admin = match require_admin().await {
398+ Ok(admin) => admin,
399+ Err(refusal) => return Ok(Some(refusal)),
400+ };
401+
402+ let store = accounts().store().clone();
403+ let configured = store
404+ .workspace()
405+ .await
406+ .map_err(|e| ServerFnError::new(e.to_string()))?
407+ .is_some_and(|ws| ws.smtp_password_set && ws.smtp_host.is_some());
408+ if !configured {
409+ return Ok(Some(Refusal::BadSender(
410+ "Fill the sender in and save it first — there is nothing to test yet.".to_string(),
411+ )));
412+ }
413+
414+ let Some(outcome) = mail().test(&admin.email).await else {
415+ // No engine in this process at all. Nothing sends here, and saying so
416+ // beats writing down a failure the settings did not cause.
417+ return Ok(Some(Refusal::Unavailable));
418+ };
419+
420+ let at = time::OffsetDateTime::now_utc();
421+ let test = match outcome {
422+ Ok(took) => SenderTest {
423+ at,
424+ took_ms: took.whole_milliseconds().max(0) as u64,
425+ error: None,
426+ },
427+ Err(problem) => SenderTest {
428+ at,
429+ took_ms: 0,
430+ // The mailer builds this from what the server said, never from the
431+ // credentials it sent, so it is safe to store and to show.
432+ error: Some(problem.message.clone()),
433+ },
434+ };
435+ if let Err(problem) = store.record_sender_test(&admin.workspace_id, test).await {
436+ eprintln!("store error: {problem}");
437+ return Ok(Some(Refusal::Unavailable));
438+ }
439+ Ok(None)
440+}
441+
355 /// The shallowest check that catches a typo without rejecting a real address.442 /// The shallowest check that catches a typo without rejecting a real address.
356 /// Nothing here is trying to decide what RFC 5322 permits — the mail server443 /// Nothing here is trying to decide what RFC 5322 permits — the mail server
357 /// settles that, and a refusal from it lands in the ledger with its own words.444 /// settles that, and a refusal from it lands in the ledger with its own words.
@@ -632,8 +719,53 @@ fn SenderPanel(sender: Sender, on_change: Callback<()>) -> impl IntoView {
632 }719 }
633 });720 });
634 721
722+ // The test writes down what happened, so the panel is refetched after it
723+ // for the same reason it is after a save: what is on screen should be the
724+ // stored answer, not this browser's memory of one.
725+ let test = ServerAction::<SendTestMail>::new();
726+ let tested = test.value();
727+ Effect::new(move |_| {
728+ if matches!(tested.get(), Some(Ok(None))) {
729+ on_change.run(());
730+ }
731+ });
732+ let test_refusal = move || match tested.get() {
733+ Some(Ok(Some(refusal))) => Some(refusal.message()),
734+ Some(Err(_)) => Some(Refusal::Unavailable.message()),
735+ _ => None,
736+ };
737+
635 let connected = sender.is_connected();738 let connected = sender.is_connected();
636 let password_set = sender.password_set;739 let password_set = sender.password_set;
740+ // What the row says: a refusal from the call itself if there was one, and
741+ // otherwise the stored result of the last test — which outlives the reload,
742+ // because "did this ever work" is a question asked the next morning.
743+ let last = sender.test.clone();
744+ let test_line = move || match (test_refusal(), last.clone()) {
745+ (Some(message), _) => {
746+ view! { <span class="field-error">{message}</span> }.into_any()
747+ }
748+ (None, Some(result)) => match (result.error, result.took) {
749+ (Some(problem), _) => {
750+ view! {
751+ <span class="field-error">
752+ {format!("not delivered, {} — {problem}", result.moment)}
753+ </span>
754+ }
755+ .into_any()
756+ }
757+ (None, Some(took)) => {
758+ view! {
759+ <span class="field-note">
760+ {format!("delivered in {took} — {}", result.moment)}
761+ </span>
762+ }
763+ .into_any()
764+ }
765+ (None, None) => ().into_any(),
766+ },
767+ (None, None) => ().into_any(),
768+ };
637 769
638 view! {770 view! {
639 <section class="panel">771 <section class="panel">
@@ -657,7 +789,7 @@ fn SenderPanel(sender: Sender, on_change: Callback<()>) -> impl IntoView {
657 </p>789 </p>
658 }790 }
659 })}791 })}
660- <ActionForm action=action>792+ <ActionForm action=action attr:id="sender-settings">
661 <div class="field-row">793 <div class="field-row">
662 <label class="field">794 <label class="field">
663 <span class="field-label">"SMTP HOST"</span>795 <span class="field-label">"SMTP HOST"</span>
@@ -726,16 +858,37 @@ fn SenderPanel(sender: Sender, on_change: Callback<()>) -> impl IntoView {
726 />858 />
727 </label>859 </label>
728 </div>860 </div>
729- <div class="panel-foot">861+ </ActionForm>
862+ // The test lives outside the settings form because it is its
863+ // own call, and a form cannot hold another. Save reaches back
864+ // into that form by name, which is what the `form` attribute is
865+ // for, and works in a browser with no script as well as one
866+ // with.
867+ <div class="panel-foot panel-foot-split">
868+ <div class="foot-side">
869+ <ActionForm action=test>
870+ <button
871+ class="quiet"
872+ type="submit"
873+ disabled=move || test.pending().get()
874+ >
875+ "Send test mail to myself"
876+ </button>
877+ </ActionForm>
878+ {test_line}
879+ </div>
880+ <div class="foot-side">
730 <Show when=move || refusal().is_some()>881 <Show when=move || refusal().is_some()>
731 <span class="field-error">{move || refusal()}</span>882 <span class="field-error">{move || refusal()}</span>
732 </Show>883 </Show>
733 <Show when=saved>884 <Show when=saved>
734 <span class="field-note">"Saved."</span>885 <span class="field-note">"Saved."</span>
735 </Show>886 </Show>
736- <button class="primary" type="submit">"Save"</button>887+ <button class="primary" type="submit" form="sender-settings">
888+ "Save"
889+ </button>
737 </div>890 </div>
738- </ActionForm>891+ </div>
739 </div>892 </div>
740 </section>893 </section>
741 }894 }
@@ -1032,3 +1185,18 @@ fn MembersPanel(
1032 </section>1185 </section>
1033 }1186 }
1034 }1187 }
1188+
1189+#[cfg(all(test, feature = "ssr"))]
1190+mod tests {
1191+ use super::took_label;
1192+
1193+ #[test]
1194+ fn a_send_is_timed_the_way_the_artboard_writes_it() {
1195+ // The artboard's own line reads `delivered in 1.2 s`.
1196+ assert_eq!(took_label(1234), "1.2 s");
1197+ assert_eq!(took_label(1000), "1.0 s");
1198+ // Under a second the seconds reading would be all zeroes, so say milliseconds.
1199+ assert_eq!(took_label(999), "999 ms");
1200+ assert_eq!(took_label(0), "0 ms");
1201+ }
1202+}
crates/dizey-web/tests/http.rsmodified+78 -1
@@ -901,7 +901,8 @@ async fn an_admin_sees_the_sender_and_never_a_password() {
901 answer.body.contains(901 answer.body.contains(
902 "\"sender\":{\"host\":\"smtp.fastmail.com\",\"port\":465,\902 "\"sender\":{\"host\":\"smtp.fastmail.com\",\"port\":465,\
903 \"username\":\"dizey\",\"from_name\":\"Dizey\",\903 \"username\":\"dizey\",\"from_name\":\"Dizey\",\
904- \"from_address\":\"dizey@dizey.sh\",\"password_set\":true}"904+ \"from_address\":\"dizey@dizey.sh\",\"password_set\":true,\
905+ \"test\":null}"
905 ),906 ),
906 "{}",907 "{}",
907 answer.body908 answer.body
@@ -1566,3 +1567,79 @@ async fn signing_out_leaves_every_other_session_alone() {
1566 .await;1567 .await;
1567 assert!(still.body.contains("administers"), "{}", still.body);1568 assert!(still.body.contains("administers"), "{}", still.body);
1568 }1569 }
1570+
1571+#[tokio::test]
1572+async fn a_member_may_not_press_the_test_button() {
1573+ let app = App::open().await;
1574+ let admin_cookie = admin(&app).await;
1575+ let member = invited(&app, &admin_cookie, "emre@dizey.sh", "Emre", Role::Member).await;
1576+
1577+ let answer = app
1578+ .post(
1579+ path::<dizey_web::settings::SendTestMail>(),
1580+ Some(&member),
1581+ &[],
1582+ )
1583+ .await;
1584+
1585+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
1586+ assert!(answer.body.contains("Forbidden"), "{}", answer.body);
1587+}
1588+
1589+#[tokio::test]
1590+async fn a_viewer_may_not_press_the_test_button() {
1591+ let app = App::open().await;
1592+ let admin_cookie = admin(&app).await;
1593+ let viewer = invited(&app, &admin_cookie, "pinar@dizey.sh", "Pinar", Role::Viewer).await;
1594+
1595+ let answer = app
1596+ .post(
1597+ path::<dizey_web::settings::SendTestMail>(),
1598+ Some(&viewer),
1599+ &[],
1600+ )
1601+ .await;
1602+
1603+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
1604+ assert!(answer.body.contains("Forbidden"), "{}", answer.body);
1605+}
1606+
1607+#[tokio::test]
1608+async fn a_signed_out_browser_may_not_press_the_test_button() {
1609+ let app = App::open().await;
1610+
1611+ let answer = app
1612+ .post(path::<dizey_web::settings::SendTestMail>(), None, &[])
1613+ .await;
1614+
1615+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
1616+ assert!(answer.body.contains("SignInFirst"), "{}", answer.body);
1617+}
1618+
1619+#[tokio::test]
1620+async fn testing_a_sender_that_was_never_filled_in_says_so_rather_than_sending() {
1621+ let app = App::open().await;
1622+ let admin_cookie = admin(&app).await;
1623+
1624+ let answer = app
1625+ .post(
1626+ path::<dizey_web::settings::SendTestMail>(),
1627+ Some(&admin_cookie),
1628+ &[],
1629+ )
1630+ .await;
1631+
1632+ assert_eq!(answer.status, StatusCode::OK, "{}", answer.body);
1633+ assert!(answer.body.contains("BadSender"), "{}", answer.body);
1634+ assert!(answer.body.contains("save it first"), "{}", answer.body);
1635+
1636+ // Nothing was recorded either: the panel still has no test line to show.
1637+ let seen = app
1638+ .post(
1639+ path::<dizey_web::settings::CurrentSettings>(),
1640+ Some(&admin_cookie),
1641+ &[],
1642+ )
1643+ .await;
1644+ assert!(!seen.body.contains("\"test\":{"), "{}", seen.body);
1645+}
style/main.scssmodified+11 -0
@@ -1572,12 +1572,23 @@ a {
1572 1572
1573 .panel-foot {1573 .panel-foot {
1574 display: flex;1574 display: flex;
1575+ // A foot inside a `.panel-body` would inherit that column, and a foot is a row.
1576+ flex-direction: row;
1575 align-items: center;1577 align-items: center;
1576 gap: 12px;1578 gap: 12px;
1577 justify-content: flex-end;1579 justify-content: flex-end;
1578 1580
1579 // A foot with something to say on the left and the button on the right.1581 // A foot with something to say on the left and the button on the right.
1580 &-split { justify-content: space-between; }1582 &-split { justify-content: space-between; }
1583+
1584+}
1585+
1586+// One end of a split foot: its own controls, kept together.
1587+.foot-side {
1588+ display: flex;
1589+ align-items: center;
1590+ gap: 12px;
1591+ min-width: 0;
1581 }1592 }
1582 1593
1583 // The quiet counterpart of `.primary`, for an action that is real but is not1594 // The quiet counterpart of `.primary`, for an action that is real but is not