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

enable scopeConfig ignore for scan command #387

Merged
merged 1 commit into from
Aug 30, 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
3 changes: 2 additions & 1 deletion cmd/scanner_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type ScannerCmd struct {
func (s *ScannerCmd) Run(tRC *talismanrc.TalismanRC) int {
fmt.Printf("\n\n")
utility.CreateArt("Running Scan..")
detector.DefaultChain(tRC, "default").Test(s.additions, tRC, s.results)
additionsToScan := tRC.FilterAdditions(s.additions)
detector.DefaultChain(tRC, "default").Test(additionsToScan, tRC, s.results)
reportsPath, err := report.GenerateReport(s.results, s.reportDirectory)
if err != nil {
logr.Errorf("error while generating report: %v", err)
Expand Down
15 changes: 15 additions & 0 deletions cmd/scanner_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ func TestScannerCmdDetectsSecretAndFails(t *testing.T) {
assert.Equal(t, 1, scannerCmd.exitStatus(), "Expected ScannerCmd.exitStatus() to return 1 since secret present in history")
})
}

func TestScannerCmdAddingSecretKeyShouldExitZeroIfFileIsWithinConfiguredScope(t *testing.T) {
withNewTmpGitRepo(func(git *git_testing.GitTesting) {
git.SetupBaselineFiles("simple-file")
git.CreateFileWithContents("go.sum", awsAccessKeyIDExample)
git.CreateFileWithContents("go.mod", awsAccessKeyIDExample)
git.CreateFileWithContents(".talismanrc", talismanRCDataWithScopeAsGo)
git.AddAndcommit("*", "go sum file")
os.Chdir(git.GetRoot())

scannerCmd := NewScannerCmd(false, git.GetRoot())
scannerCmd.Run(&talismanrc.TalismanRC{ScopeConfig: []talismanrc.ScopeConfig{{ScopeName: "go"}}})
assert.Equal(t, 0, scannerCmd.exitStatus(), "Expected ScannerCmd.exitStatus() to return 0 since no secret is found")
})
}