fix: harden maintenance operations

This commit is contained in:
proxyctl coordinator
2026-07-17 03:50:18 +08:00
parent d4c76e4b3c
commit b28ebca2d7
9 changed files with 273 additions and 83 deletions
+3 -1
View File
@@ -256,7 +256,9 @@ func (a *Adapter) Inspect(_ context.Context, active *profile.Profile) target.Ins
}
func (a *Adapter) SetDesired(ctx context.Context, enabled bool, active *profile.Profile) target.OperationResult {
if !a.Availability(ctx).Available {
// Enabling requires a supported current Shell, but disabling must remain
// available so reset can remove managed state after the user's Shell changes.
if enabled && !a.Availability(ctx).Available {
return target.OperationResult{Inspection: a.Inspect(ctx, active), Err: errors.New("Shell Target is unavailable: Bash or Zsh was not detected")}
}
if enabled && active == nil {
+15
View File
@@ -472,6 +472,21 @@ func TestRecoveryAndGeneratedFilesAreAtomicOwnerOnly(t *testing.T) {
}
}
func TestDisableManagedShellAfterCurrentShellBecomesUnsupported(t *testing.T) {
root := t.TempDir()
configuration := shell.Configuration{Shell: "/bin/bash", StartupFile: filepath.Join(root, ".bashrc"), EnvironmentFile: filepath.Join(root, "config", "shell.env"), RecoveryFile: filepath.Join(root, "state", "shell.json")}
enabled := shell.New(configuration, shell.OSFileSystem{}, shell.MapEnvironment{})
if result := enabled.SetDesired(context.Background(), true, activeProfile()); result.Err != nil {
t.Fatal(result.Err)
}
configuration.Shell = "/bin/fish"
unsupported := shell.New(configuration, shell.OSFileSystem{}, shell.MapEnvironment{})
result := unsupported.SetDesired(context.Background(), false, nil)
if result.Err != nil || result.Inspection.State != target.Disabled {
t.Fatalf("disable from unsupported Shell = %#v", result)
}
}
func activeProfile() *profile.Profile {
return &profile.Profile{Name: "office", Mode: profile.AdvancedMode, HTTPURL: "http://alice:secret@proxy.example:8080", HTTPSURL: "https://proxy.example:8443", AllURL: "socks5h://proxy.example:1080", Bypass: []string{"localhost", ".example.com", "10.0.0.0/8"}}
}