From 1e517c43ba7c5e62dc029ac2e6af5cf3b83245d3 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 18 Jul 2021 17:50:37 -0700 Subject: [PATCH] Make symlink prohibition rule catch links with folder target 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. --- internal/rule/rulefunction/library.go | 1 - internal/rule/rulefunction/library_test.go | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/rule/rulefunction/library.go b/internal/rule/rulefunction/library.go index c80ed7db..f9ae4f27 100644 --- a/internal/rule/rulefunction/library.go +++ b/internal/rule/rulefunction/library.go @@ -88,7 +88,6 @@ func LibraryContainsSymlinks() (result ruleresult.Type, output string) { if err != nil { panic(err) } - projectPathListing.FilterOutDirs() symlinkPaths := []string{} for _, projectPathItem := range projectPathListing { diff --git a/internal/rule/rulefunction/library_test.go b/internal/rule/rulefunction/library_test.go index 86fd4d91..eaa68d71 100644 --- a/internal/rule/rulefunction/library_test.go +++ b/internal/rule/rulefunction/library_test.go @@ -105,6 +105,7 @@ 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()) @@ -112,7 +113,20 @@ func TestLibraryContainsSymlinks(t *testing.T) { 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)