package app import ( "bytes" "os" "testing" "archer/internal/checkpoint" "archer/internal/cli" ) func TestStateConfigStoresRedactedDSN(t *testing.T) { const source = "u:s3cr3t@tcp(h:3306)/db?charset=utf8mb4" cfg, err := cli.Parse([]string{"--source", source, "--table", "t", "--where", "id > 0", "--file", "out"}, &bytes.Buffer{}) if err != nil { t.Fatal(err) } hash, fields, err := cfg.Fingerprint() if err != nil { t.Fatal(err) } dir := t.TempDir() if err := checkpoint.Save(dir, &checkpoint.State{ConfigHash: hash, Config: fields}); err != nil { t.Fatal(err) } st, err := checkpoint.Load(dir) if err != nil { t.Fatal(err) } want := redactDSN(source) if st.Config["source"] != want { t.Fatalf("config.source = %q, want %q", st.Config["source"], want) } raw, err := os.ReadFile(checkpoint.Path(dir)) if err != nil { t.Fatal(err) } if bytes.Contains(raw, []byte("s3cr3t")) { t.Fatal("state.json must not contain the password") } }