two lists for the release of release 4: every reader of a host report in the hub (R-1396 gap 2); how --accept-small-disk reaches a public-image install (the bind form has no such field)

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 16:03:37 +01:00
1 parent c3fa43a486
commit b8cf6c2417
4 files changed
+118 -297

No files matched your search

@@ -1,170 +0,0 @@
package notify
import (
"fmt"
"strings"
"testing"
"time"
)
// Review of 2026-11-15, finding 4: `offsite_end_scheduled` let a box mail its household without limit and with its
// own words — 50 subjects gave 50 mails, and the subject and body were the box's sentence. A receipt is now built by
// the HUB alone, from a checked app name and parsed dates; a household gets at most receiptsPerDay of them a day.
// RED-PROOF: documentation/audits/build-release-4-2026-11-15/A/redproof-review-4.txt.
func receiptDet(app string, removed time.Time) string {
return fmt.Sprintf(`{"stack_name":%q,"removed_at":%q,"ends_at":%q,"subject":"whatever the box says"}`,
app, removed.UTC().Format(time.RFC3339), removed.Add(30*24*time.Hour).UTC().Format(time.RFC3339))
}
// A box that posts free words under many subjects: no mail carries its words, and the household gets at most the
// daily limit — whatever the subjects, the app names or the times it invents.
func TestD84_Receipt_ABoxCannotFloodOrWordTheHouseholdsMail(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", []string{})
evil := "ANY WORDS THE BOX CHOOSES: pay at http://evil.example"
now := time.Now().UTC()
// 50 subjects with no app at all (the review's reproduction): not one mail
for i := 0; i < 50; i++ {
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", evil, evil, fmt.Sprintf(`{"subject":"x%d"}`, i), "controller")
}
if len(*mails) != 0 {
t.Fatalf("%d mail(s) for receipts that name no app; subject=%q", len(*mails), (*mails)[0].subject)
}
// 50 valid-looking presses, each another app and another time, each with the box's own words
for i := 0; i < 50; i++ {
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", evil, evil, receiptDet(fmt.Sprintf("app-%d", i), now.Add(-time.Duration(i)*time.Minute)), "controller")
}
if len(*mails) != receiptsPerDay {
t.Fatalf("50 presses in one burst gave %d mails, want the daily limit %d", len(*mails), receiptsPerDay)
}
for _, m := range *mails {
if strings.Contains(m.subject, "evil") || strings.Contains(m.body, "evil") || strings.Contains(m.body, "ANY WORDS") {
t.Fatalf("the box's own words reached the household:\n%s\n%s", m.subject, m.body)
}
if !strings.Contains(m.subject, "a távoli másolatok törlésre kijelölve") || !strings.Contains(m.body, "Mégis megtartom") {
t.Fatalf("not the hub's own receipt:\n%s\n%s", m.subject, m.body)
}
}
// the cooldown map did not grow with the box's inventions
d.mu.Lock()
n := 0
for k := range d.custCooldowns {
if strings.HasPrefix(k, "c1:offsite_end_scheduled") {
n++
}
}
d.mu.Unlock()
if n > receiptsPerDay {
t.Fatalf("the cooldown map holds %d receipt keys for one household, want at most %d", n, receiptsPerDay)
}
}
// What the mail says comes from the details the hub CHECKED: the app name's shape, the dates as times.
func TestD84_Receipt_IsBuiltFromCheckedDetailsOnly(t *testing.T) {
now := time.Now().UTC()
good := func(app string) string { return receiptDet(app, now) }
for name, det := range map[string]string{
"no stack_name": `{"removed_at":"2026-11-15T10:00:00Z","ends_at":"2026-12-15T10:00:00Z"}`,
"a sentence as the app name": strings.Replace(good("x"), `"x"`, `"pay now at evil.example"`, 1),
"markup as the app name": strings.Replace(good("x"), `"x"`, `"<b>x</b>"`, 1),
"a reserved name": good("traefik"),
"the shares": good("_shares"),
"removed_at is not a time": `{"stack_name":"vikunja","removed_at":"yesterday","ends_at":"2026-12-15T10:00:00Z"}`,
"ends_at is not a time": `{"stack_name":"vikunja","removed_at":"2026-11-15T10:00:00Z","ends_at":"soon; click evil.example"}`,
"ends before it was removed": `{"stack_name":"vikunja","removed_at":"2026-11-15T10:00:00Z","ends_at":"2026-11-01T10:00:00Z"}`,
"details are not JSON": `not json`,
"no details": ``,
} {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "box words", "box words", det, "controller")
if len(*mails) != 0 {
t.Errorf("%s: a mail went out: %q", name, (*mails)[0].subject)
}
}
// the date in the mail is the PARSED ends_at, in the household's date form — not text from the box
d, mails := receiptDispatcher(t, "customer@example.com", nil)
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "Törlésük napja: 1999. 01. 01.", "",
`{"stack_name":"vikunja","removed_at":"2026-11-15T10:00:00Z","ends_at":"2026-12-15T10:00:00Z"}`, "controller")
if len(*mails) != 1 || !strings.Contains((*mails)[0].body, "2026. 12. 15.") || strings.Contains((*mails)[0].body, "1999") {
t.Fatalf("the mail must carry the parsed end date and none of the box's text: %+v", *mails)
}
// the press's key is the checked app + the parsed time: the same press again, with another `subject` and the time
// written in another zone, is NOT a second mail
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "",
`{"stack_name":"vikunja","removed_at":"2026-11-15T11:00:00+01:00","ends_at":"2026-12-15T10:00:00Z","subject":"another"}`, "controller")
if len(*mails) != 1 {
t.Fatalf("one press sent twice with a changed subject gave %d mails", len(*mails))
}
}
// A blocked household gets no receipt.
func TestD84_Receipt_ABlockedHouseholdGetsNone(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
if err := d.store.SetCustomerConfigStatus("c1", "blocked"); err != nil {
t.Fatal(err)
}
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "", receiptDet("vikunja", time.Now()), "controller")
if len(*mails) != 0 {
t.Fatalf("a blocked household was mailed: %+v", *mails)
}
if err := d.store.SetCustomerConfigStatus("c1", "active"); err != nil {
t.Fatal(err)
}
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "", receiptDet("vikunja", time.Now()), "controller")
if len(*mails) != 1 {
t.Fatalf("positive control: an unblocked household must get the receipt, got %d", len(*mails))
}
}
// The map of mailed presses does not grow for ever: a household's receipt keys older than a day go at its next
// receipt; another household's keys and other event types' keys are not touched.
func TestD84_Receipt_OldPressesLeaveTheCooldownMap(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
old := time.Now().Add(-25 * time.Hour)
d.mu.Lock()
for i := 0; i < 30; i++ {
d.custCooldowns[fmt.Sprintf("c1:offsite_end_scheduled:old-%d|x", i)] = old
}
d.custCooldowns["c2:offsite_end_scheduled:other|x"] = old
d.custCooldowns["c1:app_update_undone:vikunja"] = old
d.mu.Unlock()
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "", receiptDet("vikunja", time.Now()), "controller")
if len(*mails) != 1 {
t.Fatalf("30 presses of yesterday must not count against today's limit: %d mail(s)", len(*mails))
}
d.mu.Lock()
defer d.mu.Unlock()
n := 0
for k := range d.custCooldowns {
if strings.HasPrefix(k, "c1:offsite_end_scheduled:") {
n++
}
}
if n != 1 {
t.Fatalf("the household's receipt keys: %d, want only today's one", n)
}
if _, ok := d.custCooldowns["c2:offsite_end_scheduled:other|x"]; !ok {
t.Fatal("another household's key was removed")
}
if _, ok := d.custCooldowns["c1:app_update_undone:vikunja"]; !ok {
t.Fatal("another event type's key was removed")
}
}
// The daily limit is the hub's own SENT LOG, so a hub restart (an empty map) does not give a box five more.
func TestD84_Receipt_TheDailyLimitSurvivesARestart(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
for i := 0; i < receiptsPerDay; i++ {
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "", receiptDet(fmt.Sprintf("app-%d", i), time.Now()), "controller")
}
if len(*mails) != receiptsPerDay {
t.Fatalf("fixture: %d mails", len(*mails))
}
d.mu.Lock()
d.custCooldowns = map[string]time.Time{} // the restart
d.mu.Unlock()
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x", "", receiptDet("one-more", time.Now()), "controller")
if len(*mails) != receiptsPerDay {
t.Fatalf("after a restart the household got mail number %d of the day (limit %d)", len(*mails), receiptsPerDay)
}
}
-127
View File
@@ -1,127 +0,0 @@
package notify
import (
"strings"
"testing"
)
// D84 (`09` §3 decision 309; `07-backup-architecture.md` §8.2f): the household gets ONE mail at the moment it presses
// „delete backup data”, naming the app, the end date and how to take it back.
// RED-PROOFS: documentation/audits/build-release-4-2026-11-15/A/redproof-hub-mail.txt.
type receiptMail struct{ to, subject, body string }
func receiptDispatcher(t *testing.T, prefsEmail string, enabled []string) (*Dispatcher, *[]receiptMail) {
t.Helper()
st := opOnlyStore(t)
if prefsEmail != "" || enabled != nil {
if err := st.SaveNotificationPrefs("c1", prefsEmail, enabled, 6); err != nil {
t.Fatal(err)
}
}
d := opOnlyDispatcher(t, st, &sentTo{})
var mails []receiptMail
d.sendEmailFn = func(to, subject, body string, _ map[string]string) error {
mails = append(mails, receiptMail{to, subject, body})
return nil
}
return d, &mails
}
const (
receiptHU = "vikunja: az alkalmazás távoli másolatai törlésre vannak kijelölve. Törlésük napja: 2026. 12. 15. Addig a Mentések oldalon a „Mégis megtartom” gombbal visszavonhatod."
receiptEN = "vikunja: the off-site copies of this app are marked for deletion. They are deleted on: 2026-12-15. Until then you can take this back on the Backups page with the “Keep it after all” button."
receiptDetails = `{"stack_name":"vikunja","removed_at":"2026-11-15T10:00:00Z","ends_at":"2026-12-15T10:00:00Z","subject":"vikunja|2026-11-15T10:00:00Z"}`
)
// The mail reaches the household's own address although EVERY group switch is off, names the app in the subject, and
// carries the box's sentence (the day, the way back). The operator is not mailed.
func TestD84_Receipt_ReachesTheHouseholdWhateverItsSwitches(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", []string{})
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", receiptHU, "", receiptDetails, "controller")
if len(*mails) != 1 {
t.Fatalf("mails = %d, want exactly one (to the household): %+v", len(*mails), *mails)
}
m := (*mails)[0]
if m.to != "customer@example.com" {
t.Fatalf("the receipt went to %q, not to the household's own address", m.to)
}
if !strings.Contains(m.subject, "vikunja: a távoli másolatok törlésre kijelölve") {
t.Fatalf("the subject does not name the app: %q", m.subject)
}
for _, want := range []string{"2026. 12. 15.", "Mégis megtartom", "Mentések oldalon"} {
if !strings.Contains(m.body, want) {
t.Fatalf("the body lacks %q:\n%s", want, m.body)
}
}
if strings.Contains(m.body, "removed_at") || strings.Contains(m.body, "{") {
t.Fatalf("the body carries the raw details:\n%s", m.body)
}
}
// An English household reads it in English (the box's own second sentence, R-558).
func TestD84_Receipt_FollowsTheHouseholdsLanguage(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
if err := d.store.SaveReport("c1", []byte(`{"customer_id":"c1","language":"en"}`)); err != nil {
t.Fatal(err)
}
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", receiptHU, receiptEN, receiptDetails, "controller")
if len(*mails) != 1 {
t.Fatalf("mails = %d: %+v", len(*mails), *mails)
}
m := (*mails)[0]
if !strings.Contains(m.subject, "vikunja: the off-site copies are marked for deletion") || !strings.Contains(m.body, "Keep it after all") || !strings.Contains(m.body, "2026-12-15") {
t.Fatalf("not the English receipt:\n%s\n%s", m.subject, m.body)
}
if strings.Contains(m.body, "Mégis megtartom") {
t.Fatalf("Hungarian in an English household's mail:\n%s", m.body)
}
}
// Once per press: the same press delivered twice is one mail; a second app, or the same app removed again later, is
// its own mail — also inside the household's cooldown.
func TestD84_Receipt_OncePerPress(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", nil)
send := func(app, removedAt string) {
det := `{"stack_name":"` + app + `","removed_at":"` + removedAt + `","ends_at":"2026-12-15T10:00:00Z","subject":"` + app + `|` + removedAt + `"}`
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", "x "+app, "", det, "controller")
}
send("vikunja", "2026-11-15T10:00:00Z")
send("vikunja", "2026-11-15T10:00:00Z") // the same press, delivered again
if len(*mails) != 1 {
t.Fatalf("one press gave %d mails", len(*mails))
}
send("immich", "2026-11-15T10:05:00Z") // another app, five minutes later
send("vikunja", "2026-11-15T11:00:00Z") // installed again, removed again
if len(*mails) != 3 {
t.Fatalf("three presses gave %d mails, want 3: %+v", len(*mails), *mails)
}
}
// A household with no address gets no mail (the page is all it has), and nobody else is mailed in its place.
func TestD84_Receipt_NoAddressNoMail(t *testing.T) {
d, mails := receiptDispatcher(t, "", nil)
d.ProcessBoxEvent("c1", "offsite_end_scheduled", "info", receiptHU, "", receiptDetails, "controller")
if len(*mails) != 0 {
t.Fatalf("a household with no address: %d mail(s) went out: %+v", len(*mails), *mails)
}
}
// The receipt register does not open any other type: an ordinary info event still mails nobody, and a type the
// household switched off still stays off.
func TestD84_Receipt_OpensNothingElse(t *testing.T) {
d, mails := receiptDispatcher(t, "customer@example.com", []string{})
d.ProcessBoxEvent("c1", "app_removed", "info", "Alkalmazás eltávolítva.", "", `{"stack_name":"vikunja"}`, "controller")
d.ProcessBoxEvent("c1", "app_stopped_unhealthy", "error", "x", "", `{"stack_name":"vikunja"}`, "controller")
for _, m := range *mails {
if m.to == "customer@example.com" {
t.Fatalf("the household was mailed a type it switched off / an info event: %+v", m)
}
}
if len(householdReceiptEvents) != 1 || !householdReceiptEvents["offsite_end_scheduled"] {
t.Fatalf("the receipt register changed: %v — every entry bypasses the household's switches and needs its own ruling", householdReceiptEvents)
}
if operatorOnlyEvents["offsite_end_scheduled"] {
t.Fatal("a receipt cannot be operator-only")
}
}