Files
Pulse/internal/agentupdate/export_test.go
courtmanr@gmail.com 1d21be06b5 fix(agent): validate executable identity before activation
Substring version checks admitted stale agents and dependency literals, while
ARMv6 executables could select ARMv7 updates. Share compiler target and exact
release identity admission across producers, downloads and activation, and
keep validated local downloads bound to their open file descriptor.

Cover bounded runtime probes, failure atomicity, canonical executable formats,
ARM emulation and saved-state installer repair boundaries. Retain the installed
ARM fleet and physical-device gap, and leave release qualification open.
2026-11-05 18:22:58 +00:00

64 lines
2.4 KiB
Go

package agentupdate
import "context"
// PerformUpdateWithExecPathForTest runs the real update path while suppressing
// the process restart side effect so integration tests can inspect the result.
func PerformUpdateWithExecPathForTest(u *Updater, ctx context.Context, execPath string) error {
origRestart := restartProcessFn
origSelfTest := u.selfTestFn
origIdentity := u.verifyIdentityFn
restartProcessFn = func(string) error { return nil }
u.verifyIdentityFn = func(context.Context, string, string, string) error { return nil }
u.selfTestFn = func(context.Context, string) error { return nil }
defer func() {
restartProcessFn = origRestart
u.selfTestFn = origSelfTest
u.verifyIdentityFn = origIdentity
}()
return u.performUpdateWithExecPathForVersion(ctx, execPath, "6.0.0")
}
// WithExecutablePathForTest temporarily points update-info lookups at the
// supplied executable path so tests can exercise the real one-shot handoff.
func WithExecutablePathForTest(execPath string, fn func()) {
origExec := osExecutableFn
origEval := evalSymlinksFn
osExecutableFn = func() (string, error) { return execPath, nil }
evalSymlinksFn = func(string) (string, error) { return execPath, nil }
defer func() {
osExecutableFn = origExec
evalSymlinksFn = origEval
}()
fn()
}
// UseExecPathForUpdateChecksForTest wires CheckAndUpdate to the real update
// implementation while forcing a deterministic executable path.
func UseExecPathForUpdateChecksForTest(u *Updater, execPath string) func() {
origPerform := u.performUpdateFn
origExec := osExecutableFn
origEval := evalSymlinksFn
origRestart := restartProcessFn
origSelfTest := u.selfTestFn
origIdentity := u.verifyIdentityFn
osExecutableFn = func() (string, error) { return execPath, nil }
evalSymlinksFn = func(string) (string, error) { return execPath, nil }
restartProcessFn = func(string) error { return nil }
u.verifyIdentityFn = func(context.Context, string, string, string) error { return nil }
u.selfTestFn = func(context.Context, string) error { return nil }
u.performUpdateFn = func(ctx context.Context, targetVersion string) error {
return u.performUpdateWithExecPathForVersion(ctx, execPath, targetVersion)
}
return func() {
u.performUpdateFn = origPerform
u.selfTestFn = origSelfTest
u.verifyIdentityFn = origIdentity
osExecutableFn = origExec
evalSymlinksFn = origEval
restartProcessFn = origRestart
}
}