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

bundler:fix - correctly parse output error #921

Merged
merged 1 commit into from
Jan 10, 2022
Merged
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
17 changes: 11 additions & 6 deletions internal/services/formatters/ruby/bundler/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ import (
vulnhash "github.com/ZupIT/horusec/internal/utils/vuln_hash"
)

// ErrGemLockNotFound occurs when bundles does not find gemfile.lock.
// ErrGemLockNotFound occurs when project path does not have the Gemfile.lock file.
//
// nolint: lll
var ErrGemLockNotFound = errors.New("project doesn't have a gemfile.lock file, it would be a good idea to commit it so horusec can check for vulnerabilities")
// nolint: stylecheck
// We actually want that this error message be capitalized since the file name that was
// not found is capitalized.
var ErrGemLockNotFound = errors.New("Gemfile.lock file is required to execute Bundler analysis")

type Formatter struct {
formatters.IService
Expand Down Expand Up @@ -80,16 +82,19 @@ func (f *Formatter) startBundlerAudit(projectSubPath string) (string, error) {

func (f *Formatter) getDockerConfig(projectSubPath string) *dockerEntities.AnalysisData {
analysisData := &dockerEntities.AnalysisData{
CMD: f.AddWorkDirInCmd(CMD, file.GetSubPathByExtension(
f.GetConfigProjectPath(), projectSubPath, "Gemfile.lock"), tools.SecurityCodeScan),
CMD: f.AddWorkDirInCmd(
CMD,
file.GetSubPathByExtension(f.GetConfigProjectPath(), projectSubPath, "Gemfile.lock"),
tools.SecurityCodeScan,
),
Language: languages.Ruby,
}

return analysisData.SetImage(f.GetCustomImageByLanguage(languages.Ruby), images.Ruby)
}

func (f *Formatter) verifyGemLockError(output string) error {
if strings.Contains(output, "No such file or directory") && strings.Contains(output, "Errno::ENOENT") {
if strings.Contains(output, `Could not find "Gemfile.lock"`) {
return ErrGemLockNotFound
}

Expand Down