Something went wrong. Try again.
SQLite-backed dotfiles manager for silly cats.
dotfiles-manager sqlite dotfiles
Something went wrong. Try again.
2.3 kB · 84 lines
Go
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485package integration
import ( "os" "path/filepath" "testing")
func TestExecutablePathSafety(t *testing.T) { scenarios := []struct { name string run func(*testing.T) }{ {"symlinked parent rejected", testPathSymlinkParent}, {"blocking ancestor rejected", testPathBlockingAncestor}, {"case collision rejected", testPathCaseCollision}, {"parent child collision", testPathParentChild}, {"source target identity", testPathIdentity}, } for _, scenario := range scenarios { t.Run(scenario.name, scenario.run) }}
func testPathSymlinkParent(t *testing.T) { env := newExecEnv(t) env.initRepository(t) env.source(t, ".config/app", "v1") if err := os.MkdirAll(filepath.Join(env.home, ".config"), 0o700); err != nil { t.Fatal(err) } if err := os.Remove(filepath.Join(env.home, ".config")); err != nil { t.Fatal(err) } if err := os.Symlink(filepath.Join(env.repo, ".config"), filepath.Join(env.home, ".config")); err != nil { t.Fatal(err) } result := env.run(t, nil, "apply") if result.Code != 1 { t.Fatalf("code = %d, want 1 for a symlinked target parent", result.Code) }}
func testPathBlockingAncestor(t *testing.T) { env := newExecEnv(t) env.initRepository(t) env.source(t, "x/a/b", "v1") writeFile(t, filepath.Join(env.home, "a"), []byte("a file")) result := env.run(t, nil, "apply") if result.Code != 1 { t.Fatalf("code = %d, want 1 for a blocking ancestor", result.Code) }}
func testPathCaseCollision(t *testing.T) { env := newExecEnv(t) env.initRepository(t) env.source(t, ".config/app", "v1") env.source(t, ".config/App", "v2") result := env.run(t, nil, "validate") if result.Code != 1 { t.Fatalf("code = %d, want 1 for a case-colliding repository", result.Code) }}
func testPathParentChild(t *testing.T) { env := newExecEnv(t) env.initRepository(t) env.source(t, "a", "v1") env.source(t, "x/a/b", "v2") result := env.run(t, nil, "validate") if result.Code != 1 { t.Fatalf("code = %d, want 1 for a parent-child collision", result.Code) }}
func testPathIdentity(t *testing.T) { env := newExecEnv(t) env.initRepository(t) result := env.run(t, nil, "init", env.home) if result.Code != 1 { t.Fatalf("code = %d, want 1 for a repository identical to HOME", result.Code) }}