Skip to content

Commit

Permalink
Make symlink prohibition rule catch links with folder target
Browse files Browse the repository at this point in the history
The use of `FilterOutDirs()` on the path list removed symlinks with folder targets, causing rule LS005 to only detect
symlinks with file targets. But all types of symlinks are prohibited so this resulted in false negatives.
  • Loading branch information
per1234 committed Jul 19, 2021
1 parent 8277f9e commit 1e517c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion internal/rule/rulefunction/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func LibraryContainsSymlinks() (result ruleresult.Type, output string) {
if err != nil {
panic(err)
}
projectPathListing.FilterOutDirs()

symlinkPaths := []string{}
for _, projectPathItem := range projectPathListing {
Expand Down
16 changes: 15 additions & 1 deletion internal/rule/rulefunction/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,28 @@ func TestLibraryHasSubmodule(t *testing.T) {

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

testTables := []libraryRuleFunctionTestTable{
{"Has symlink", testLibrary, ruleresult.Fail, ""},
{"Has file target symlink", testLibrary, ruleresult.Fail, ""},
}

checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t)

err = symlinkPath.RemoveAll()
require.Nil(t, err)

// Set up a library with a folder target symlink.
err = os.Symlink(librariesTestDataPath.Join(testLibrary, "src").String(), symlinkPath.String())
require.Nil(t, err)

testTables = []libraryRuleFunctionTestTable{
{"Has folder target symlink", testLibrary, ruleresult.Fail, ""},
}

checkLibraryRuleFunction(LibraryContainsSymlinks, testTables, t)
Expand Down

0 comments on commit 1e517c4

Please sign in to comment.