Mask padded credentials as sent to providers
This commit is contained in:
@@ -122,6 +122,11 @@ func (p *fixtureProvider) serve(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
content := `{"corrections":[{"id":1,"original_text":"hello world","corrected_text":"Hello world","confidence":0.99}]}`
|
||||
if p.mode == "invalid-credential-echo" {
|
||||
sent := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
|
||||
raw, _ := json.Marshal(map[string]string{"unexpected": sent + "|" + p.secret})
|
||||
content = string(raw)
|
||||
}
|
||||
if p.mode == "repair-filter-later-failure" && !validation {
|
||||
if proposalCall == 1 {
|
||||
content = `{"wrong":true}`
|
||||
@@ -231,6 +236,9 @@ func newProcessFixture(t *testing.T, mode, modules string) processFixture {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
p := &fixtureProvider{mode: mode, secret: `selected-secret-"\-123`, entered: make(chan struct{}, 1)}
|
||||
if mode == "invalid-credential-echo" {
|
||||
p.secret = " synthetic-echo-credential\t "
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(p.serve))
|
||||
t.Cleanup(server.Close)
|
||||
resources := fmt.Sprintf("backends:\n - id: local\n endpoint: %s/v1\n api_key_env: AUDITA_TEST_PROVIDER_KEY\nprofiles:\n - id: proposal\n backend: local\n model: local\n - id: validation\n backend: local\n model: local\n", server.URL)
|
||||
@@ -944,6 +952,38 @@ func TestSubprocessAllModelFailureStillCompletes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessMasksPaddedCredentialInProviderResponse(t *testing.T) {
|
||||
f := newProcessFixture(t, "invalid-credential-echo", "[grammar]")
|
||||
effective := strings.TrimSpace(f.provider.secret)
|
||||
code, stdout, stderr := f.run(t, true, "--debug")
|
||||
if code != 0 || f.provider.callCount() != 1 || !strings.Contains(stderr, "1 work units with errors") {
|
||||
t.Fatalf("code=%d calls=%d stdout=%q stderr=%q", code, f.provider.callCount(), stdout, stderr)
|
||||
}
|
||||
if strings.Contains(stderr, effective) || strings.Contains(stdout, effective) {
|
||||
t.Fatal("credential escaped redaction in command output")
|
||||
}
|
||||
responseCaptured := false
|
||||
err := filepath.WalkDir(f.dir, func(path string, entry os.DirEntry, err error) error {
|
||||
if err != nil || entry.IsDir() {
|
||||
return err
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if bytes.Contains(data, []byte(effective)) {
|
||||
t.Errorf("credential escaped redaction in %s", entry.Name())
|
||||
}
|
||||
if strings.HasSuffix(entry.Name(), "-response-payload.json") && bytes.Contains(data, []byte("[REDACTED]|[REDACTED]")) {
|
||||
responseCaptured = true
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil || !responseCaptured {
|
||||
t.Fatalf("missing redacted provider echo: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessAllValidationFailureStillCompletes(t *testing.T) {
|
||||
f := newProcessFixture(t, "all-validation-failure", "[grammar, grammar]")
|
||||
code, stdout, stderr := f.run(t, true, "--verbose")
|
||||
|
||||
Reference in New Issue
Block a user