Skip to content

Commit

Permalink
Merge pull request #140 from coinbase/gosec_fix
Browse files Browse the repository at this point in the history
Gosec fix
  • Loading branch information
ghbren authored Jun 11, 2020
2 parents 6d0a639 + 7e7346e commit ee63898
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/salus/scanners/gosec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ def run
shell_return = Dir.chdir(@repository.path_to_repo) do
# sometimes the go.sum needs to be forced updated to be able to correctly build packages.
# forcing go get seems to do the trick
run_shell("go get")
if File.size?('go.mod')
go_get_ret = run_shell("go get ./...")
if go_get_ret.status != 0
go_get_err = "Unable to start gosec because go get ./... failed. #{go_get_ret.stderr}"
report_error(go_get_err, status: go_get_ret.status)
report_stderr(go_get_err)
return report_failure
end
end
cmd = "gosec #{config_options}-fmt=json ./..."
run_shell(cmd)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module test/hello

require (
test123.test456.test789/test2 v0.123456
)

go 1.13
5 changes: 5 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hello

func Hello() string {
return "Hello!"
}
10 changes: 10 additions & 0 deletions spec/fixtures/gosec/bad_gomod_app/hello_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hello

import "testing"

func TestHello(t *testing.T) {
want := "Hello!"
if got := Hello(); got != want {
t.Errorf("Hello() = %q, want %q", got, want)
}
}
11 changes: 11 additions & 0 deletions spec/lib/salus/scanners/gosec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

before { scanner.run }

context 'go get ./... fails' do
let(:repo) { Salus::Repo.new('spec/fixtures/gosec/bad_gomod_app') }

it 'should display go get error and not run gosec' do
expect(scanner.should_run?).to eq(true)
expect(scanner.report.passed?).to eq(false)
err_msg = scanner.report.to_h.fetch(:errors).first[:message]
expect(err_msg).to include('Unable to start gosec because go get ./... failed.')
end
end

context 'non-go project' do
let(:repo) { Salus::Repo.new('spec/fixtures/blank_repository') }

Expand Down

0 comments on commit ee63898

Please sign in to comment.