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)
| 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. |
| 50 | func 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 | } |
nothing calls this directly
no test coverage detected