MCPcopy
hub / github.com/filebrowser/filebrowser / TestCopyAllowsInScopeSymlink

Function TestCopyAllowsInScopeSymlink

fileutils/copy_test.go:50–75  ·  view source on GitHub ↗

A symlink whose target stays within scope is legitimate and must still be copied (dereferenced) so the fix does not over-block normal usage.

(t *testing.T)

Source from the content-addressed store, hash-verified

48// A symlink whose target stays within scope is legitimate and must still be
49// copied (dereferenced) so the fix does not over-block normal usage.
50func TestCopyAllowsInScopeSymlink(t *testing.T) {
51 scope := t.TempDir()
52 if err := os.MkdirAll(filepath.Join(scope, "srcdir", "real"), 0o755); err != nil {
53 t.Fatal(err)
54 }
55 if err := os.WriteFile(filepath.Join(scope, "srcdir", "real", "f.txt"), []byte("in-scope"), 0o644); err != nil {
56 t.Fatal(err)
57 }
58 if err := os.Symlink(filepath.Join(scope, "srcdir", "real", "f.txt"), filepath.Join(scope, "srcdir", "link.txt")); err != nil {
59 t.Skipf("cannot create symlink: %v", err)
60 }
61
62 afs := files.NewScopedFs(afero.NewOsFs(), scope)
63
64 if err := Copy(afs, "/srcdir", "/dstdir", 0o644, 0o755); err != nil {
65 t.Fatalf("expected copy of an in-scope symlink to succeed, got: %v", err)
66 }
67
68 data, err := afero.ReadFile(afs, "/dstdir/link.txt")
69 if err != nil {
70 t.Fatalf("expected in-scope symlink to be copied, got: %v", err)
71 }
72 if string(data) != "in-scope" {
73 t.Fatalf("unexpected copied content: %q", string(data))
74 }
75}

Callers

nothing calls this directly

Calls 3

NewScopedFsFunction · 0.92
CopyFunction · 0.85
MkdirAllMethod · 0.80

Tested by

no test coverage detected