hub + installer (unreleased): fixes after an independent review of the night's code — per-thing mail cooldown, a box's input bounded and checked, both off-site account types on a reset, a quiet first run, strict-mode installer
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
a044eb8c16
commit
f618c591eb
31 files changed
+796
-88
No files matched your search
@@ -25,6 +25,15 @@ func newEndDateFix() *endDateFix {
|
||||
func() ([]BoxCertReport, error) { return f.reps, nil },
|
||||
func(k string) time.Time { return f.state[k] },
|
||||
func(k string, t time.Time) error { f.state[k] = t; return nil },
|
||||
func(prefix string) []string {
|
||||
var out []string
|
||||
for k := range f.state {
|
||||
if strings.HasPrefix(k, prefix) {
|
||||
out = append(out, k)
|
||||
}
|
||||
}
|
||||
return out
|
||||
},
|
||||
func(cust, typ, sev, msg, details, src string) {
|
||||
f.events = append(f.events, cust+"|"+typ+"|"+sev+"|"+msg+"|"+details)
|
||||
}, log.New(io.Discard, "", 0))
|
||||
@@ -149,3 +158,53 @@ func TestEndDates_TheBoxesWordsAreChecked(t *testing.T) {
|
||||
t.Errorf("a token with a name that is not plain text must be named by its number:\n%s", all)
|
||||
}
|
||||
}
|
||||
|
||||
// Found by review, 2026-11-14. (1) The FIRST run after a deploy: a token that already ended, was replaced long ago and
|
||||
// never revoked, must not mail „ENDED” — it is marked, not told; a thing that ends within the 14 days is still told.
|
||||
// (2) The marks are the hub's settings and the names and dates are the box's: a box that sends another end date every
|
||||
// hour, or new names every hour, must not mint a mail or a mark each time.
|
||||
func TestEndDates_FirstRunAndABoxCannotMintMarks(t *testing.T) {
|
||||
day := 24 * time.Hour
|
||||
f := newEndDateFix()
|
||||
f.tokens = []EndingToken{{ID: 1, Name: "replaced", ExpiresAt: f.now.Add(-3 * day)}, {ID: 2, Name: "soon", ExpiresAt: f.now.Add(5 * day)}}
|
||||
f.reps = []BoxCertReport{{CustomerID: "old", ReportJSON: certReport(cert("gone.example.hu", f.now.Add(-2*day)))}}
|
||||
f.step(0)
|
||||
if len(f.events) != 1 || !strings.Contains(f.events[0], "„soon”") {
|
||||
t.Fatalf("the first run: %v — want only the token that ends in 5 days", f.events)
|
||||
}
|
||||
f.step(2 * time.Hour)
|
||||
f.step(2 * time.Hour)
|
||||
if len(f.events) != 1 {
|
||||
t.Fatalf("the already-ended things were told at a later run: %v", f.events[1:])
|
||||
}
|
||||
// after the first run, a token that ends is told as ended (the normal rule)
|
||||
f.tokens = append(f.tokens, EndingToken{ID: 3, Name: "third", ExpiresAt: f.now.Add(-time.Hour)})
|
||||
f.step(2 * time.Hour)
|
||||
if len(f.events) != 2 || !strings.Contains(f.events[1], "„third” ENDED") {
|
||||
t.Fatalf("a token that ended after the first run: %v", f.events[1:])
|
||||
}
|
||||
|
||||
// a box that sends ANOTHER end date at every report
|
||||
g := newEndDateFix()
|
||||
g.step(0) // the baseline run
|
||||
for i := 0; i < 48; i++ {
|
||||
g.reps = []BoxCertReport{{CustomerID: "evil", ReportJSON: certReport(cert("x.example.hu", g.now.Add(5*day+time.Duration(i)*time.Minute)))}}
|
||||
g.step(61 * time.Minute)
|
||||
}
|
||||
if len(g.events) > 3 {
|
||||
t.Fatalf("a box that moves its end date by a minute each hour got %d mails in two days (want at most a few: a new mail needs a date a day later)", len(g.events))
|
||||
}
|
||||
marksBefore := len(g.state)
|
||||
// and a box that sends eight NEW names every hour
|
||||
for i := 0; i < 24; i++ {
|
||||
var cs []string
|
||||
for n := 0; n < 8; n++ {
|
||||
cs = append(cs, cert(fmt.Sprintf("h%dn%d.example.hu", i, n), g.now.Add(6*day)))
|
||||
}
|
||||
g.reps = []BoxCertReport{{CustomerID: "evil", ReportJSON: certReport(cs...)}}
|
||||
g.step(61 * time.Minute)
|
||||
}
|
||||
if grew := len(g.state) - marksBefore; grew > webCertMaxMarks {
|
||||
t.Fatalf("192 invented names made %d marks, want at most %d for one household", grew, webCertMaxMarks)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user