| index b275e06b7..4a4dc3dfa 100644 |
| --- a/internal/console/submission_sim_test.go |
| +++ b/internal/console/submission_sim_test.go |
| @@ -17,6 +17,7 @@ import ( |
| "testing" |
| "time" |
| |
| + "github.com/carlosframework/platform/internal/activator" |
| "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/mail" |
| "github.com/carlosframework/platform/internal/mailwire" |
| @@ -287,7 +288,6 @@ type channelSim struct { |
| envs []string // owned environments: "team" and the made ones |
| reported map[string]string |
| dry bool // a dry pass: no bookkeeping, no honesty checks |
| - liveKeys bool // check also checks that a switch-off's SMTP keys work |
| nextID int |
| steps []string |
| } |
| @@ -451,12 +451,14 @@ func (sim *channelSim) declared(version string) bool { |
| } |
| |
| // check asserts the invariant after a step. wasSwitched is the switch |
| -// before it: a step that turned it off must leave every instance on SMTP. |
| -// With liveKeys set, each of those SMTP keys must also be one AWS still |
| -// holds, active, for a user it still has (P2-3 of Fable's final review: a |
| -// reap that ran around a switch-off deleted the user the switch-off had |
| -// just delivered). liveKeys is set for that step only: the other steps' |
| -// faults can leave a key that is not live (reported with P2-3). |
| +// before it: a step that turned it off must leave every instance on SMTP, |
| +// with a key AWS still holds, active, for a user it still has (P2-3 of |
| +// Fable's final review; and Paul's ruling of 2026-11-14, switch-off checks |
| +// keys). While switched, an instance the agent starts without being able |
| +// to read the switch decides its channel from its bundle |
| +// (activator.MailUnknownSubmits); where that is SMTP, the key must be live |
| +// too (Astra's census review of 76f4f582c; ruled 2026-11-14, switch-on |
| +// removes SMTP settings before deleting the user). |
| // While switched, every instance resolves to a declared build (and a box |
| // that has not adopted yet serves a declared one too), and its bundle |
| // holds a From the box's mailer sends. |
| @@ -487,13 +489,22 @@ func (sim *channelSim) check(wasSwitched bool) { |
| if got := vars[mf]; got.Kind != "env" || !sim.sendable(sn, got.Value) { |
| bad = append(bad, fmt.Sprintf("%s (environment %q) has no %s the mailer sends (%q)", rec.Host, rec.Environment, mf, got.Value)) |
| } |
| + plain := map[string]string{} |
| + for k, v := range vars { |
| + plain[k] = v.Value |
| + } |
| + if !activator.MailUnknownSubmits(plain) { |
| + if key := vars[user].Value; key == "" || !sim.keyLive(key) { |
| + bad = append(bad, fmt.Sprintf("%s (environment %q), started with the switch unreadable, takes SMTP from its bundle, and key %q is not live", rec.Host, rec.Environment, key)) |
| + } |
| + } |
| case wasSwitched: |
| for _, k := range []string{host, port, user, pass, from} { |
| if _, ok := vars[k]; !ok { |
| bad = append(bad, fmt.Sprintf("%s (environment %q) was switched off without %s", rec.Host, rec.Environment, k)) |
| } |
| } |
| - if key := vars[user].Value; sim.liveKeys && key != "" && !sim.keyLive(key) { |
| + if key := vars[user].Value; key != "" && !sim.keyLive(key) { |
| bad = append(bad, fmt.Sprintf("%s (environment %q) was switched off onto key %s, which no user holds active", rec.Host, rec.Environment, key)) |
| } |
| } |
| @@ -973,16 +984,15 @@ func (sim *channelSim) scripted() { |
| // P2-3 of Fable's final review: a switch-off started inside a reap |
| // paused before its deletes. |
| reached := false |
| - sim.liveKeys = true |
| sim.do("the hourly reap, a switch-off started inside it", false, func() string { |
| out, r := sim.reapAroundSwitchOff() |
| reached = r |
| return out |
| }) |
| - sim.liveKeys = false |
| if !reached { |
| sim.t.Fatalf("the reap never reached the app user's keys, so the step proved nothing\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| } |
| + sim.keysChecked() |
| sim.do("switch on", false, sim.switchOn) |
| for _, env := range slices.Clone(sim.envs) { |
| if env != "team" { |
| @@ -991,6 +1001,54 @@ func (sim *channelSim) scripted() { |
| } |
| } |
| |
| +// switchOnLeavingTheFive is a switch-on whose last write to the default |
| +// bundle (the five out) fails: the app is switched, and the default bundle |
| +// still holds the five, naming the app user's live key, beside its From. |
| +func (sim *channelSim) switchOnLeavingTheFive() { |
| + sim.t.Helper() |
| + sim.ready() |
| + sim.faults.armMatching("config.json", 2) |
| + sim.do("switch on, the default bundle's last write failing", false, sim.switchOn) |
| + if !sim.switched() || sim.bundleVars("")["TITO_SMTP_HOST"].Value == "" { |
| + sim.t.Fatalf("the switch-on did not stop with the five in the default bundle, so the steps after it prove nothing\nsteps:\n %s", strings.Join(sim.steps, "\n ")) |
| + } |
| +} |
| + |
| +// keysChecked are the steps for Paul's ruling of 2026-11-14 (switch-off |
| +// checks keys): a switch-off that finds a bundle holding the recorded key |
| +// asks AWS whether that key is still live before it skips the mint. |
| +func (sim *channelSim) keysChecked() { |
| + sim.t.Helper() |
| + ctx := context.Background() |
| + user := mail.UserName("bab", "titogo") |
| + // The key the default bundle names goes, in AWS, before a switch-off. |
| + // Read as delivered, it would switch every default-bundle instance |
| + // onto a key no user holds. |
| + sim.switchOnLeavingTheFive() |
| + sim.do("AWS loses the app user's key, then switch off", false, func() string { |
| + key := sim.bundleVars("")["TITO_SMTP_USER"].Value |
| + if err := sim.prov.DeleteKey(ctx, user, key); err != nil { |
| + return "setup: " + err.Error() |
| + } |
| + return sim.switchOff() |
| + }) |
| + // A key whose state cannot be read is neither live nor missing: the |
| + // switch-off stops before it writes the switch, and the app keeps |
| + // submitting. |
| + sim.switchOnLeavingTheFive() |
| + sim.prov.FailNext = map[string]error{"KeyState": errors.New("simulated AWS failure")} |
| + var st int |
| + sim.do("switch off, the key's state unreadable", false, func() string { |
| + var out string |
| + st, out = sim.w.submit(sim.t, false) |
| + return short(st, out) |
| + }) |
| + if st/100 == 2 || !sim.switched() { |
| + sim.t.Fatalf("a switch-off that could not read a key's state answered %d (switched %v), want a refusal with the switch still on\nsteps:\n %s", st, sim.switched(), strings.Join(sim.steps, "\n ")) |
| + } |
| + sim.do("switch off", false, sim.switchOff) |
| +} |
| + |
| // random runs n random steps. |
| func (sim *channelSim) random(n int) { |
| sim.t.Helper() |