From fd390bbd37fa60c626244884f07cb20e4373ac11 Mon Sep 17 00:00:00 2001 From: Mehdi Moussaif Date: Wed, 22 Nov 2023 18:39:19 +0100 Subject: [PATCH] Bug fix where kubescape fails to read from framework local paths Fix typo in error description Bug fix where kubescape get policies from file Signed-off-by: Mehdi Moussaif Missing '.json' extension when getting Framework Paths Signed-off-by: Mehdi Moussaif Appropriate test case for FrameworksPaths Bug fix where kubescape fails to read from frameworks local paths Signed-off-by: Mehdi Moussaif --- core/cautils/getter/loadpolicy.go | 2 +- core/core/initutils.go | 2 +- core/core/initutils_test.go | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/cautils/getter/loadpolicy.go b/core/cautils/getter/loadpolicy.go index ae2d18a4..e4887a34 100644 --- a/core/cautils/getter/loadpolicy.go +++ b/core/cautils/getter/loadpolicy.go @@ -23,7 +23,7 @@ var ( ErrNameRequired = errors.New("missing required input framework name") ErrIDRequired = errors.New("missing required input control ID") ErrFrameworkNotMatching = errors.New("framework from file not matching") - ErrControlNotMatching = errors.New("framework from file not matching") + ErrControlNotMatching = errors.New("control from file not matching") ) var ( diff --git a/core/core/initutils.go b/core/core/initutils.go index 84f02e7e..e85e1dd6 100644 --- a/core/core/initutils.go +++ b/core/core/initutils.go @@ -240,7 +240,7 @@ func getDownloadReleasedPolicy(ctx context.Context, downloadReleasedPolicy *gett func getDefaultFrameworksPaths() []string { fwPaths := []string{} for i := range getter.NativeFrameworks { - fwPaths = append(fwPaths, getter.GetDefaultPath(getter.NativeFrameworks[i])) + fwPaths = append(fwPaths, getter.GetDefaultPath(getter.NativeFrameworks[i]+".json")) // GetDefaultPath expects a filename, not just the framework name } return fwPaths } diff --git a/core/core/initutils_test.go b/core/core/initutils_test.go index a139de8a..1975f4b0 100644 --- a/core/core/initutils_test.go +++ b/core/core/initutils_test.go @@ -3,6 +3,7 @@ package core import ( "context" "reflect" + "strings" "testing" "github.com/kubescape/go-logger" @@ -229,3 +230,13 @@ func TestIsScanTypeForSubmission(t *testing.T) { }) } } + +func TestGetDefaultFrameworksPaths(t *testing.T) { + result := getDefaultFrameworksPaths() + + assert.NotEmpty(t, result) + for _, path := range result { + assert.NotEmpty(t, path) + assert.True(t, strings.HasSuffix(path, ".json")) + } +}