Harden self-update recovery (T-617)

This commit is contained in:
ila
2026-07-20 00:05:41 +08:00
parent ea1d6c8ee4
commit 24e9862192
12 changed files with 369 additions and 42 deletions
@@ -0,0 +1,29 @@
package main
import (
"testing"
"softbox.local/core/updater"
)
func TestAcknowledgeInternalUpdateHealthRejectsMalformedArguments(t *testing.T) {
tests := []struct {
name string
args []string
handled bool
wantErr bool
}{
{name: "ordinary launch", args: nil},
{name: "other internal-looking flag", args: []string{"--softbox-other"}},
{name: "missing request ID", args: []string{updater.InternalHealthFlag}, handled: true, wantErr: true},
{name: "extra argument", args: []string{updater.InternalHealthFlag, "update-1234", "extra"}, handled: true, wantErr: true},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
handled, err := acknowledgeInternalUpdateHealth(test.args)
if handled != test.handled || (err != nil) != test.wantErr {
t.Fatalf("acknowledgeInternalUpdateHealth(%q) = handled=%t, err=%v; want handled=%t, error=%t", test.args, handled, err, test.handled, test.wantErr)
}
})
}
}