fix: harden maintenance operations
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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"}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user