Remove application credential substitution
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -118,14 +119,12 @@ func (p *fixtureProvider) serve(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if p.mode == "all-model-failure" || (p.mode == "all-validation-failure" && validation) || (p.mode == "partial-validation" && validation && validationCall == 1) || (p.mode == "repair-filter-later-failure" && !validation && proposalCall == 3) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = fmt.Fprintf(w, `{"error":{"message":"provider echoed %s"}}`, p.secret)
|
||||
_, _ = io.WriteString(w, `{"error":{"message":"provider unavailable"}}`)
|
||||
return
|
||||
}
|
||||
content := `{"corrections":[{"id":1,"original_text":"hello world","corrected_text":"Hello world"}]}`
|
||||
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 == "malformed-response" {
|
||||
content = `{"corrections": [`
|
||||
}
|
||||
if p.mode == "repair-filter-later-failure" && !validation {
|
||||
if proposalCall == 1 {
|
||||
@@ -246,9 +245,6 @@ 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)
|
||||
@@ -957,40 +953,37 @@ func TestSubprocessAllModelFailureStillCompletes(t *testing.T) {
|
||||
if document.Status != reporting.StatusCompleted || len(document.Errors) != 2 || document.Errors[0].Scope != "work_unit" || *document.Summary.WorkUnitsWithErrors != 2 || document.Errors[0].ModuleInstance == document.Errors[1].ModuleInstance || f.provider.callCount() != 2 {
|
||||
t.Fatalf("model failure report: %+v", document)
|
||||
}
|
||||
if strings.Contains(stderr, f.provider.secret) {
|
||||
t.Fatal("secret leaked in stderr")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessMasksPaddedCredentialInProviderResponse(t *testing.T) {
|
||||
f := newProcessFixture(t, "invalid-credential-echo", "[grammar]")
|
||||
effective := strings.TrimSpace(f.provider.secret)
|
||||
func TestSubprocessCapturesMalformedProviderResponse(t *testing.T) {
|
||||
f := newProcessFixture(t, "malformed-response", "[grammar]")
|
||||
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() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if entry.IsDir() || !strings.HasSuffix(entry.Name(), "-response-payload.json") {
|
||||
return nil
|
||||
}
|
||||
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())
|
||||
var response struct {
|
||||
FinalContent string `json:"final_content"`
|
||||
}
|
||||
if strings.HasSuffix(entry.Name(), "-response-payload.json") && bytes.Contains(data, []byte("[REDACTED]|[REDACTED]")) {
|
||||
responseCaptured = true
|
||||
if err := json.Unmarshal(data, &response); err != nil {
|
||||
return err
|
||||
}
|
||||
responseCaptured = responseCaptured || response.FinalContent == `{"corrections": [`
|
||||
return nil
|
||||
})
|
||||
if err != nil || !responseCaptured {
|
||||
t.Fatalf("missing redacted provider echo: %v", err)
|
||||
t.Fatalf("missing malformed provider response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1246,27 +1239,16 @@ func TestSubprocessWhitespaceOutputIsALiteralFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessPathAnnouncementsAreRedacted(t *testing.T) {
|
||||
func TestSubprocessAnnouncesActualOutputPaths(t *testing.T) {
|
||||
for _, fail := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(fail), func(t *testing.T) {
|
||||
f := newProcessFixture(t, "normal", "[]")
|
||||
selected, unused := "selected-path-secret", "unused-path-secret"
|
||||
f.provider.secret = selected
|
||||
t.Setenv("AUDITA_UNUSED_PATH_KEY", unused)
|
||||
cfg, err := os.ReadFile(filepath.Join(f.dir, "prompts.yml"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg = bytes.Replace(cfg, []byte("backends:\n"), []byte("backends:\n - id: unused\n endpoint: http://unused.invalid/v1\n api_key_env: AUDITA_UNUSED_PATH_KEY\n"), 1)
|
||||
if err := os.WriteFile(filepath.Join(f.dir, "prompts.yml"), cfg, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reportDir := filepath.Join(f.dir, unused)
|
||||
reportDir := filepath.Join(f.dir, "reports")
|
||||
if err := os.Mkdir(reportDir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.output = filepath.Join(reportDir, "out.json")
|
||||
debugParent := filepath.Join(f.dir, selected)
|
||||
debugParent := filepath.Join(f.dir, "diagnostics")
|
||||
if fail {
|
||||
if err := os.WriteFile(f.transcript, []byte("invalid"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1276,11 +1258,8 @@ func TestSubprocessPathAnnouncementsAreRedacted(t *testing.T) {
|
||||
if (!fail && code != 0) || (fail && code != 2) {
|
||||
t.Fatalf("code=%d stderr=%q", code, stderr)
|
||||
}
|
||||
if strings.Contains(stderr, selected) || strings.Contains(stderr, unused) {
|
||||
t.Fatalf("credential in stderr: %q", stderr)
|
||||
}
|
||||
if !fail && !strings.Contains(stderr, "[REDACTED]") {
|
||||
t.Fatalf("missing redacted announcement: %q", stderr)
|
||||
if !fail && (!strings.Contains(stderr, filepath.Join(reportDir, "report.md")) || !strings.Contains(stderr, debugParent)) {
|
||||
t.Fatalf("missing destination announcement: %q", stderr)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(reportDir, "report.md")); !fail && err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user