devbox/internal/config/config_test.go
shoemoney a8c32c4a23
Some checks failed
CI / vet-build-test (push) Has been cancelled
fix: CLI honors secrets.extra_patterns; SaveState uses a unique temp file
- add loadGuard(dir) helper in cmd/devbox/main.go; replaces all 4
  secret.New(nil) calls in publish/mount/restore/deploy so user's
  [secrets] extra_patterns from config.toml are enforced on CLI upload
  paths (was only enforced by the daemon — security leak)
- SaveState: switch from fixed .tmp suffix to os.CreateTemp(.state-*.tmp)
  mirroring SaveDaemon, eliminating concurrent-write corruption
2026-06-30 19:27:22 -05:00

49 lines
1.2 KiB
Go

package config
import "testing"
func TestDaemonRoundTrip(t *testing.T) {
dir := t.TempDir()
in := Daemon{Hub: "hub.shoemoney.ai", Mounts: []Mount{
{Share: "projects", Local: "/Users/jh/Projects", Hub: "hub.shoemoney.ai"},
{Share: "projects", Subpath: "p22/backend", Local: "/var/www", Hub: "hub.shoemoney.ai", ReadOnly: true},
}}
if err := SaveDaemon(dir, in); err != nil {
t.Fatal(err)
}
out, err := LoadDaemon(dir)
if err != nil {
t.Fatal(err)
}
if out.Hub != in.Hub || len(out.Mounts) != 2 {
t.Fatalf("roundtrip mismatch: %+v", out)
}
if !out.Mounts[1].ReadOnly || out.Mounts[1].Subpath != "p22/backend" {
t.Fatalf("mount fields lost: %+v", out.Mounts[1])
}
}
func TestLoadDaemonMissingIsEmpty(t *testing.T) {
d, err := LoadDaemon(t.TempDir())
if err != nil {
t.Fatal(err)
}
if d.Hub != "" || len(d.Mounts) != 0 {
t.Fatalf("expected empty daemon for missing file, got %+v", d)
}
}
func TestStateRoundTrip(t *testing.T) {
dir := t.TempDir()
in := map[string]string{"share\x00\x00/local": "snap123"}
if err := SaveState(dir, in); err != nil {
t.Fatal(err)
}
got, err := LoadState(dir)
if err != nil {
t.Fatal(err)
}
if got["share\x00\x00/local"] != "snap123" {
t.Fatalf("round-trip mismatch: %v", got)
}
}