Skip to content

Commit

Permalink
analysis:chore - add tool that generate the error on analysis errors (Z…
Browse files Browse the repository at this point in the history
…upIT#855)

Signed-off-by: Ian Cardoso <[email protected]>
  • Loading branch information
iancardosozup authored Dec 8, 2021
1 parent 35f5a70 commit 9341592
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
10 changes: 3 additions & 7 deletions e2e/commands/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
"os"
"path/filepath"

"github.com/ZupIT/horusec-devkit/pkg/enums/severities"
"github.com/ZupIT/horusec-devkit/pkg/enums/vulnerability"
"github.com/ZupIT/horusec-devkit/pkg/utils/logger/enums"
"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"

"github.com/ZupIT/horusec-devkit/pkg/enums/severities"
"github.com/ZupIT/horusec-devkit/pkg/enums/vulnerability"
"github.com/ZupIT/horusec-devkit/pkg/utils/logger/enums"
"github.com/ZupIT/horusec/internal/enums/outputtype"
"github.com/ZupIT/horusec/internal/utils/testutil"
)
Expand Down Expand Up @@ -148,7 +148,6 @@ var _ = Describe("running binary Horusec with start parameter", func() {
var certificateFileWithPath string

BeforeEach(func() {

certificateFileWithPath = testutil.GinkgoCreateTmpFile("*.crt")

flags = map[string]string{
Expand Down Expand Up @@ -468,7 +467,6 @@ var _ = Describe("running binary Horusec with start parameter", func() {
writeJsonFile(customRulesJson)

BeforeEach(func() {

flags = map[string]string{
testutil.StartFlagProjectPath: testutil.JavaExample1,
testutil.StartFlagCustomRulesPath: customRulesJson,
Expand All @@ -484,7 +482,6 @@ var _ = Describe("running binary Horusec with start parameter", func() {
Eventually(session.Wait(testutil.AverageTimeoutAnalyzeForExamplesFolder).Out).Should(gbytes.Say(`Details: Teste QA`))
Eventually(session.Wait(testutil.AverageTimeoutAnalyzeForExamplesFolder).Out).Should(gbytes.Say(`Teste de description QA`))
Eventually(session.Wait(testutil.AverageTimeoutAnalyzeForExamplesFolder).Out).Should(gbytes.Say(`Type: Vulnerability`))

})
})
})
Expand All @@ -498,7 +495,6 @@ func writeJsonFile(path string) {
defer file.Close()

customRules := []map[string]interface{}{

{
"id": "HS-JAVA-99999999999",
"name": "Teste QA",
Expand Down
4 changes: 1 addition & 3 deletions internal/enums/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ErrDockerNotInstalled = errors.New("{HORUSEC_CLI} Error Docker not found. Pl

// Occurs when not found rails project

var ErrNotFoundRailsProject = errors.New("{HORUSEC_CLI} Error not found rails project syntax")
var ErrNotFoundRailsProject = errors.New("brakeman only works on Ruby On Rails project")

// Occurs when gem lock not found

Expand All @@ -39,5 +39,3 @@ var ErrGemLockNotFound = errors.New(
" it would be a good idea to commit it so horusec can check for vulnerabilities")

var ErrImageTagCmdRequired = errors.New("{ERROR_DOCKER_API} required exists Image, Tag and CMD not empty")

var ErrorBodyIsRequired = errors.New("{ERROR_USE_CASES} body is required")
6 changes: 3 additions & 3 deletions internal/services/formatters/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *Service) SetAnalysisError(err error, tool tools.Tool, output, projectSu
if err != nil {
s.mutex.Lock()
defer s.mutex.Unlock()
s.addAnalysisError(err)
s.addAnalysisError(tool, err)
msg := s.GetAnalysisIDErrorMessage(tool, output)
if projectSubPath != "" {
msg += " | ProjectSubPath -> " + projectSubPath
Expand All @@ -128,11 +128,11 @@ func (s *Service) SetAnalysisError(err error, tool tools.Tool, output, projectSu
}
}

func (s *Service) addAnalysisError(err error) {
func (s *Service) addAnalysisError(tool tools.Tool, err error) {
if err != nil {
toAppend := ""
if len(s.analysis.Errors) > 0 {
s.analysis.Errors += "; " + err.Error()
s.analysis.Errors += fmt.Sprintf("; Error while running %s tool: %s", tool.ToString(), err.Error())
return
}
s.analysis.Errors += toAppend + err.Error()
Expand Down
3 changes: 2 additions & 1 deletion mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package main

import (
"github.com/magefile/mage/mage"
"os"

"github.com/magefile/mage/mage"
)

func main() { os.Exit(mage.Main()) }
3 changes: 2 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package main

import (
"github.com/magefile/mage/sh"

// mage:import
_ "github.com/ZupIT/horusec-devkit/pkg/utils/mageutils"
"github.com/magefile/mage/sh"
)

// GetCurrentDate execute "echo", `::set-output name=date::$(date "+%a %b %d %H:%M:%S %Y")`
Expand Down

0 comments on commit 9341592

Please sign in to comment.