TestScanDirectory_SkipsSymlinks checks that ScanDirectory does not follow a symlink to a file outside the project.
(t *testing.T)
| 93 | // TestScanDirectory_SkipsSymlinks checks that ScanDirectory does not follow a |
| 94 | // symlink to a file outside the project. |
| 95 | func TestScanDirectory_SkipsSymlinks(t *testing.T) { |
| 96 | project := t.TempDir() |
| 97 | require.NoError(t, os.WriteFile(filepath.Join(project, "main.go"), []byte("package main"), 0o600)) |
| 98 | |
| 99 | outsideDir := t.TempDir() |
| 100 | target := filepath.Join(outsideDir, "target.txt") |
| 101 | require.NoError(t, os.WriteFile(target, []byte("OUTSIDE-FILE-TEXT"), 0o600)) |
| 102 | |
| 103 | if err := os.Symlink(target, filepath.Join(project, "link.txt")); err != nil { |
| 104 | t.Skipf("symlink unsupported: %v", err) |
| 105 | } |
| 106 | |
| 107 | out, err := ScanDirectory(project, 10, "", nil) |
| 108 | require.NoError(t, err) |
| 109 | assert.NotContains(t, string(out), "OUTSIDE-FILE-TEXT", "symlink target is in the output") |
| 110 | assert.Contains(t, string(out), "package main") |
| 111 | } |
nothing calls this directly
no test coverage detected