Skip to content

Commit bee3aef

Browse files
authored
Merge pull request #206 from per1234/fix-symlink-detection
Make symlink prohibition rule catch links with folder target
2 parents 8277f9e + 1e517c4 commit bee3aef

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: internal/rule/rulefunction/library.go

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func LibraryContainsSymlinks() (result ruleresult.Type, output string) {
8888
if err != nil {
8989
panic(err)
9090
}
91-
projectPathListing.FilterOutDirs()
9291

9392
symlinkPaths := []string{}
9493
for _, projectPathItem := range projectPathListing {

Diff for: internal/rule/rulefunction/library_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,28 @@ func TestLibraryHasSubmodule(t *testing.T) {
105105

106106
func TestLibraryContainsSymlinks(t *testing.T) {
107107
testLibrary := "Recursive"
108+
// Set up a library with a file target symlink.
108109
symlinkPath := librariesTestDataPath.Join(testLibrary, "test-symlink")
109110
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
110111
err := os.Symlink(librariesTestDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
111112
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
112113
defer symlinkPath.RemoveAll() // clean up
113114

114115
testTables := []libraryRuleFunctionTestTable{
115-
{"Has symlink", testLibrary, ruleresult.Fail, ""},
116+
{"Has file target symlink", testLibrary, ruleresult.Fail, ""},
117+
}
118+
119+
checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t)
120+
121+
err = symlinkPath.RemoveAll()
122+
require.Nil(t, err)
123+
124+
// Set up a library with a folder target symlink.
125+
err = os.Symlink(librariesTestDataPath.Join(testLibrary, "src").String(), symlinkPath.String())
126+
require.Nil(t, err)
127+
128+
testTables = []libraryRuleFunctionTestTable{
129+
{"Has folder target symlink", testLibrary, ruleresult.Fail, ""},
116130
}
117131

118132
checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t)

0 commit comments

Comments
 (0)