Files
Reims-Go/internal/app/diagnostics_test.go

63 lines
1.7 KiB
Go

package app
import (
"archive/zip"
"io"
"path/filepath"
"strings"
"testing"
"github.com/Nwflower/reims-go/internal/host"
"github.com/Nwflower/reims-go/internal/macos/reims"
)
func TestWriteDiagnosticsZipRedactsSensitiveData(t *testing.T) {
zipPath := filepath.Join(t.TempDir(), "reports", "diag.zip")
err := writeDiagnosticsZip(zipPath, diagnosticsBundle{
HostReport: host.Report{OS: "windows", LogicalCPUs: 16, DataRootDriveType: "fixed"},
VMDetail: &reims.VMDetail{
Name: "macos-tahoe",
NetworkSummary: "user, mac 52:54:00:ab:cd:ef, ssh on 127.0.0.1:2222",
ExtraArgs: "-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal",
},
SerialLog: "OpenCore presents iMac20,1, serial C02FAKE123456\n",
QEMULog: "Authorization: Bearer 0123456789abcdef0123456789abcdef\n",
AppLogs: []string{`REIMS_TOKEN="abcdef0123456789abcdef0123456789"`},
})
if err != nil {
t.Fatalf("writeDiagnosticsZip: %v", err)
}
zr, err := zip.OpenReader(zipPath)
if err != nil {
t.Fatal(err)
}
defer zr.Close()
var all strings.Builder
for _, f := range zr.File {
rc, err := f.Open()
if err != nil {
t.Fatal(err)
}
b, _ := io.ReadAll(rc)
rc.Close()
all.WriteString(f.Name + ":\n" + string(b) + "\n")
}
text := all.String()
for _, secret := range []string{
"52:54:00:ab:cd:ef",
"C02FAKE123456",
"ourhardworkbythesewordsguardedpleasedontsteal",
"0123456789abcdef0123456789abcdef",
"abcdef0123456789abcdef0123456789",
} {
if strings.Contains(text, secret) {
t.Fatalf("diagnostics zip leaked secret %q\n%s", secret, text)
}
}
if !strings.Contains(text, "[redacted]") {
t.Fatalf("expected [redacted] markers in zip output")
}
}