fix: harden read-only target diagnostics
This commit is contained in:
@@ -108,6 +108,49 @@ func active() *profile.Profile {
|
||||
return &profile.Profile{Name: "office", Mode: profile.AdvancedMode, HTTPURL: "http://proxy.example:8080", HTTPSURL: "http://secure.example:8443", AllURL: "socks5://socks.example:1080", Bypass: []string{"localhost", ".example.com", "10.0.0.0/8", "2001:db8::1"}}
|
||||
}
|
||||
|
||||
func TestDiagnosticsSuppressSensitiveGSettingsOutputAndRunnerErrors(t *testing.T) {
|
||||
const secret = "GNOME-DIAGNOSTIC-SECRET-7f3a"
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
value string
|
||||
fail bool
|
||||
}{
|
||||
{name: "malformed value", value: "unterminated-" + secret},
|
||||
{name: "runner error", value: secret, fail: true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
r := newRunner()
|
||||
key := "org.gnome.system.proxy.http authentication-password"
|
||||
r.values[key] = test.value
|
||||
if test.fail {
|
||||
r.fail = func(c gnome.Command) error {
|
||||
if reflect.DeepEqual(c.Args, []string{"get", "org.gnome.system.proxy.http", "authentication-password"}) {
|
||||
return errors.New("runner exposed " + secret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
a := adapter(r, &memoryState{})
|
||||
checks := a.DiagnosticChecks(context.Background(), active())
|
||||
for _, check := range checks {
|
||||
if strings.Contains(check.Evidence, secret) {
|
||||
t.Fatalf("diagnostic evidence exposed password: %#v", checks)
|
||||
}
|
||||
}
|
||||
result := a.SetDesired(context.Background(), true, active())
|
||||
operationError := ""
|
||||
if result.Err != nil {
|
||||
operationError = result.Err.Error()
|
||||
}
|
||||
for _, evidence := range []string{a.Availability(context.Background()).Evidence, a.Inspect(context.Background(), active()).Evidence, operationError} {
|
||||
if strings.Contains(evidence, secret) {
|
||||
t.Fatalf("Target evidence or loggable operation error exposed password: %q", evidence)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiagnosticChecksCoverCommandSchemasSessionAndAuthorityWithoutMutation(t *testing.T) {
|
||||
r, state := newRunner(), &memoryState{}
|
||||
a := adapter(r, state)
|
||||
|
||||
Reference in New Issue
Block a user