MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / TestScanDirectory_SkipsSymlinks

Function TestScanDirectory_SkipsSymlinks

cmd/code2context/code_test.go:95–111  ·  view source on GitHub ↗

TestScanDirectory_SkipsSymlinks checks that ScanDirectory does not follow a symlink to a file outside the project.

(t *testing.T)

Source from the content-addressed store, hash-verified

93// TestScanDirectory_SkipsSymlinks checks that ScanDirectory does not follow a
94// symlink to a file outside the project.
95func 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}

Callers

nothing calls this directly

Calls 1

ScanDirectoryFunction · 0.85

Tested by

no test coverage detected