From d8e3a694f29e810e350b4ae4b885132f84b349ed Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sat, 9 Oct 2021 10:55:39 -0400 Subject: [PATCH 1/4] Fixed bug in extractLine function which was returning incorrect line # when the line contains multiple vuln types --- scan/utils.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scan/utils.go b/scan/utils.go index f9ec4cfd..92bb6de7 100644 --- a/scan/utils.go +++ b/scan/utils.go @@ -212,6 +212,8 @@ func extractLine(patchContent string, leak Leak, lineLookup map[string]bool) int if _, ok := lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)]; !ok { lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)] = true return lineNumber + } else if ok { + return lineNumber } } currLine++ From 36a4871585f378e9c65f3f7aad4fe05f62d37dd0 Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sun, 10 Oct 2021 16:38:24 -0400 Subject: [PATCH 2/4] Made changes to add support for cross-platform (os) testing as tests would pass on MacOS but no Windows --- config/config_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index d1eea0b8..7f7e7813 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -30,95 +30,95 @@ func TestParse(t *testing.T) { { description: "test successful load", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "aws_key.toml")), }, }, { description: "test bad toml", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key.toml")), }, wantErr: fmt.Errorf("Near line 7 (last key parsed 'rules.description'): expected value but found \"AWS\" instead"), }, { description: "test bad regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_regex_aws_key.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_regex_aws_key.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: invalid nested repetition operator: `???`"), }, { description: "test bad global allowlist file regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_global_allowlist_file.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), }, { description: "test bad global file regex", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_aws_key_file_regex.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_aws_key_file_regex.toml")), }, wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"), }, { description: "test successful load big ol thing", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "large.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "large.toml")), }, }, { description: "test load entropy", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "entropy.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "entropy.toml")), }, }, { description: "test entropy bad range", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_1.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_1.toml")), }, wantErr: fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value"), }, { description: "test entropy value max", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_2.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_2.toml")), }, wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), }, { description: "test entropy value min", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_3.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_3.toml")), }, wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_4.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_4.toml")), }, wantErr: fmt.Errorf("strconv.ParseInt: parsing \"x\": invalid syntax"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_5.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_5.toml")), }, wantErr: fmt.Errorf("problem loading config: group cannot be lower than 0"), }, { description: "test entropy value group", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_6.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_6.toml")), }, wantErr: fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp"), }, { description: "test entropy range limits", opts: options.Options{ - ConfigPath: filepath.Join(configPath, "bad_entropy_7.toml"), + ConfigPath: filepath.ToSlash(filepath.Join(configPath, "bad_entropy_7.toml")), }, wantErr: fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0"), }, @@ -200,7 +200,7 @@ func findRuleByDescription(rules []config.Rule, description string) (*config.Rul } func writeTestConfig(toml string) (string, error) { - tmpfile, err := ioutil.TempFile("", "testConfig") + tmpfile, err := ioutil.TempFile(".", "testConfig") if err != nil { return "", fmt.Errorf("Couldn't create test config got: %w", err) } From b8ff5eec73a4c1ccaac702ae930484d5edc777e5 Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sun, 10 Oct 2021 16:40:13 -0400 Subject: [PATCH 3/4] Had to re-add testdata/ folder to project in order to get scan tests passing on Windows --- testdata/repos/basic/dotGit/index | Bin 217 -> 217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/testdata/repos/basic/dotGit/index b/testdata/repos/basic/dotGit/index index 420b9edacff0039f2c2454fbccd2ab6b581c9f42..6099bcd069f778a2f63943e0ef046751e0d6fe42 100644 GIT binary patch delta 116 zcmcb~c$3k<#WTp6fq{VugcFnfb2xI-0}_+A1_Jp=pm7O|Gtod*8KkUxj|NbAhswM{&kED46IDoTy`=rG%jIaVEhVHBQnuI xRoO!Nxccp%yon(CW>y?TS=?q6Wfi_6@xQlPzVLd}z@!yX-tpFP4f9Q99RS6EA_xEg From 7cc3d7e4679bcc2266b840aa7aca26fc7a43b2fa Mon Sep 17 00:00:00 2001 From: "Matthew E. Grahlman" Date: Sun, 10 Oct 2021 17:27:45 -0400 Subject: [PATCH 4/4] Fix for Windows OS --- testdata/repos/basic/dotGit/index | Bin 217 -> 217 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/testdata/repos/basic/dotGit/index b/testdata/repos/basic/dotGit/index index 6099bcd069f778a2f63943e0ef046751e0d6fe42..7f7b84abfb326bf2400ef01acda157137b416370 100644 GIT binary patch delta 37 vcmV+=0NVfA0oehNUItb@Dg7VFkz`>Mws;}i)-|J@w@b5WCH?(8(eos_IujB@ delta 37 tcmcb~c$0BL9GicK%FP6oi7AO9U-Oxqucq?Hm+Eh}>U0ta6iY0Q2LKWW4Z;8b