Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatters:chore - normalize not found files warn message #1023

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/controllers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (a *Analyzer) removeWarningsFromErrors() {

for _, err := range strings.SplitAfter(a.analysis.Errors, ";") {
if a.isWarning(err) {
a.analysis.AddWarning(err)
a.analysis.AddWarning(strings.ReplaceAll(err, ";", ""))
} else {
errors += err
}
Expand All @@ -449,9 +449,8 @@ func (a *Analyzer) removeWarningsFromErrors() {

// isWarning workaround to check if the message it's form a warning until the formatters are refactored
func (a *Analyzer) isWarning(err string) bool {
return strings.Contains(err, messages.MsgErrorPacketJSONNotFound) ||
return strings.Contains(err, messages.MsgErrorPackageLockJSONNotFound) ||
strings.Contains(err, messages.MsgErrorYarnLockNotFound) ||
strings.Contains(err, messages.MsgErrorGemLockNotFound) ||
strings.Contains(err, messages.MsgErrorNotFoundRequirementsTxt) ||
strings.Contains(err, messages.MsgWarnPathIsInvalidGitRepository)
}
22 changes: 7 additions & 15 deletions internal/helpers/messages/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,13 @@ const (
MsgVulnerabilityTypeToShowInvalid = "{HORUSEC_CLI} Error on validate vulnerability type is wrong type: "
MsgErrorRunToolInDocker = "{HORUSEC_CLI} Error to execute tool %s | analysisID -> %s | output -> %s"
MsgErrorInvalidWorkDir = "{HORUSEC_CLI} Workdir is nil! Check the configuration and try again"
MsgErrorParseStringToToolsConfig = "{HORUSEC_CLI} Error when try parse tools config string to entity. " +
"Returning default values"
MsgErrorNotFoundRequirementsTxt = "{HORUSEC_CLI} Error The file requirements.txt not found in python project to " +
"start analysis. It would be a good idea to commit it so horusec can check for vulnerabilities"
MsgErrorPacketJSONNotFound = "{HORUSEC_CLI} Error It looks like your project doesn't have a package-lock.json " +
"file. If you use NPM to handle your dependencies, it would be a good idea to commit it so horusec can check " +
"for vulnerabilities"
MsgErrorYarnLockNotFound = "{HORUSEC_CLI} Error It looks like your project doesn't have a yarn.lock file. " +
"If you use Yarn to handle your dependencies, it would be a good idea to commit it so horusec " +
"can check for vulnerabilities"
MsgErrorYarnProcess = "{HORUSEC_CLI} Error Yarn returned an error: "
MsgErrorGemLockNotFound = "{HORUSEC_CLI} Error It looks like your project doesn't have a gemfile.lock file, " +
"it would be a good idea to commit it so horusec can check for vulnerabilities"
MsgErrorGetFilenameByExt = "Could not get filename by extension: "
MsgErrorNancyRateLimit = `{HORUSEC_CLI} Nancy tool failed to query the GitHub API for updates.
MsgErrorParseStringToToolsConfig = "{HORUSEC_CLI} Error when try parse tools config string to entity. Returning default values"
MsgErrorNotFoundRequirementsTxt = "file requirements.txt was not found in your Python project. It would be a good idea to commit it so Horusec can check for vulnerabilities"
MsgErrorPackageLockJSONNotFound = "file package-lock.json was not found in your Javascript project. If you use NPM to handle your dependencies, it would be a good idea to commit it so Horusec can check for vulnerabilities"
MsgErrorYarnLockNotFound = "file yarn.lock file was not found in your Javascript project. If you use Yarn to handle your dependencies, it would be a good idea to commit it so Horusec can check for vulnerabilities"
MsgErrorYarnProcess = "{HORUSEC_CLI} Yarn returned an error: "
MsgErrorGetFilenameByExt = "Could not get filename by extension: "
MsgErrorNancyRateLimit = `{HORUSEC_CLI} Nancy tool failed to query the GitHub API for updates.
This is most likely due to GitHub rate-limiting on unauthenticated requests.
To make authenticated requests please:
1. Generate a token at https://github.com/settings/tokens
Expand Down
2 changes: 1 addition & 1 deletion internal/services/formatters/go/gosec/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestGosecStartAnalysis(t *testing.T) {

gosec.StartAnalysis("")
assert.True(t, entity.HasErrors(), "Expected errors for analysis")
assert.Equal(t, "Error while running tool GoSec: some error", entity.Errors)
assert.Equal(t, "{HORUSEC_CLI} Error while running tool GoSec: some error", entity.Errors)
})

t.Run("Should run analysis and return error for an invalid output", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (f *Formatter) parseOutput(containerOutput, projectSubPath string) error {

func (f *Formatter) IsNotFoundError(containerOutput string) error {
if strings.Contains(containerOutput, "ERROR_PACKAGE_LOCK_NOT_FOUND") {
return errors.New(messages.MsgErrorPacketJSONNotFound)
return errors.New(messages.MsgErrorPackageLockJSONNotFound)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/services/formatters/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ func (s *Service) addAnalysisError(tool tools.Tool, err error) {
if err != nil {
buf := bytes.NewBufferString("")
if len(s.analysis.Errors) > 0 {
fmt.Fprintf(buf, "; ")
fmt.Fprintf(buf, ";")
}
fmt.Fprintf(buf, "Error while running tool %s: %v", tool, err)
fmt.Fprintf(buf, "{HORUSEC_CLI} Error while running tool %s: %v", tool, err)
s.analysis.Errors += buf.String()
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/formatters/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestSetAnalysisError(t *testing.T) {
svc.SetAnalysisError(errors.New("some error"), tools.HorusecEngine, "testing", "")
svc.SetAnalysisError(errors.New("other error"), tools.HorusecEngine, "testing 2", "")

expectedErrors := "Error while running tool HorusecEngine: some error; Error while running tool HorusecEngine: other error"
expectedErrors := "{HORUSEC_CLI} Error while running tool HorusecEngine: some error;{HORUSEC_CLI} Error while running tool HorusecEngine: other error"

assert.Equal(t, expectedErrors, analysis.Errors)
}
Expand Down