Files
archer/internal/app/state_config_test.go
T
voidandClaude Sonnet 4.6 bc4a6b504f Initial commit: archer, a Go-native MySQL/MariaDB table archiver
Renamed from arcdb: module path, cmd/archer, internal/archererr,
docs, build scripts and ARCHER_* environment variables.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-11-06 22:12:17 +08:00

44 lines
976 B
Go

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")
}
}