From 873d4104a6aa89be8f86d93db8e416909d9add87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paw=C5=82owski?= Date: Tue, 8 Aug 2023 01:26:40 +0200 Subject: [PATCH] start:bugfix wrong interpretation of subversion of docker (#1156) * Support single-digit subversions of docker * Fix: wrong path in test * fix paths test due to the .horusec dir creation during tests * simplify test code --------- Co-authored-by: Bruno Duru <80854347+brunoduruzup@users.noreply.github.com> --- internal/controllers/language_detect/language_detect_test.go | 2 +- internal/controllers/requirements/docker/docker.go | 3 ++- internal/utils/file/file_test.go | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/controllers/language_detect/language_detect_test.go b/internal/controllers/language_detect/language_detect_test.go index 8fbca5cd8..c2ce18e76 100644 --- a/internal/controllers/language_detect/language_detect_test.go +++ b/internal/controllers/language_detect/language_detect_test.go @@ -77,7 +77,7 @@ func TestLanguageDetectIgnoreFilesGithubFolder(t *testing.T) { cfg.EnableGitHistoryAnalysis = true cfg.EnableCommitAuthor = true cfg.FilesOrPathsToIgnore = []string{"**/leaks/**", "**/yaml/**"} - cfg.ProjectPath = filepath.Join(testutil.RootPath, "..", "horusec-examples-vulnerabilities") + cfg.ProjectPath = testutil.RootPath analysisID := uuid.New() diff --git a/internal/controllers/requirements/docker/docker.go b/internal/controllers/requirements/docker/docker.go index 89f4479f3..c6e8645c0 100644 --- a/internal/controllers/requirements/docker/docker.go +++ b/internal/controllers/requirements/docker/docker.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "strconv" + "strings" "github.com/ZupIT/horusec-devkit/pkg/utils/logger" @@ -86,7 +87,7 @@ func getVersionAndSubVersion(fullVersion string) (int, int, error) { if err != nil { return 0, 0, ErrDockerNotInstalled } - subversion, err := strconv.Atoi(fullVersion[3:5]) + subversion, err := strconv.Atoi(strings.Split(fullVersion[3:5], ".")[0]) if err != nil { return 0, 0, ErrDockerNotInstalled } diff --git a/internal/utils/file/file_test.go b/internal/utils/file/file_test.go index a29ec5bea..edd4adf16 100644 --- a/internal/utils/file/file_test.go +++ b/internal/utils/file/file_test.go @@ -30,11 +30,11 @@ import ( func TestGetFilePathIntoBasePath(t *testing.T) { t.Run("Should return path correctly", func(t *testing.T) { filePath := filepath.Join("file", "file_test.go") - volume := testutil.RootPath + volume := filepath.Join(testutil.RootPath, "internal") response, err := file.GetPathFromFilename(filePath, volume) assert.NoError(t, err) assert.NotEqual(t, response, filePath) - assert.Equal(t, filepath.Join("internal", "utils", "file", "file_test.go"), response) + assert.Equal(t, filepath.Join("utils", "file", "file_test.go"), response) }) t.Run("Should return filePath because not found", func(t *testing.T) { filePath := "some_other_not_existing_file.go"