|
@@ -15,7 +15,10 @@ import (
|
|
|
const testRepoBase = "../test_data/test_repos/"
|
|
const testRepoBase = "../test_data/test_repos/"
|
|
|
|
|
|
|
|
func TestScan(t *testing.T) {
|
|
func TestScan(t *testing.T) {
|
|
|
- moveDotGit("dotGit", ".git")
|
|
|
|
|
|
|
+ err := moveDotGit("dotGit", ".git")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatal(err)
|
|
|
|
|
+ }
|
|
|
defer moveDotGit(".git", "dotGit")
|
|
defer moveDotGit(".git", "dotGit")
|
|
|
tests := []struct {
|
|
tests := []struct {
|
|
|
description string
|
|
description string
|
|
@@ -32,6 +35,7 @@ func TestScan(t *testing.T) {
|
|
|
Path: "../test_data/test_repos/test_repo_1",
|
|
Path: "../test_data/test_repos/test_repo_1",
|
|
|
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
|
|
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
|
|
|
ReportFormat: "json",
|
|
ReportFormat: "json",
|
|
|
|
|
+ Threads: runtime.GOMAXPROCS(0),
|
|
|
},
|
|
},
|
|
|
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
|
|
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
|
|
|
},
|
|
},
|
|
@@ -120,6 +124,7 @@ func TestScan(t *testing.T) {
|
|
|
Report: "../test_data/test_local_repo_two_leaks_file_commit_range.json.got",
|
|
Report: "../test_data/test_local_repo_two_leaks_file_commit_range.json.got",
|
|
|
ReportFormat: "json",
|
|
ReportFormat: "json",
|
|
|
CommitsFile: "../test_data/test_options/test_local_repo_commits.txt",
|
|
CommitsFile: "../test_data/test_options/test_local_repo_commits.txt",
|
|
|
|
|
+ Threads: runtime.GOMAXPROCS(0),
|
|
|
},
|
|
},
|
|
|
wantPath: "../test_data/test_local_repo_two_leaks_file_commit_range.json",
|
|
wantPath: "../test_data/test_local_repo_two_leaks_file_commit_range.json",
|
|
|
},
|
|
},
|
|
@@ -219,6 +224,7 @@ func TestScan(t *testing.T) {
|
|
|
Report: "../test_data/test_regex_entropy.json.got",
|
|
Report: "../test_data/test_regex_entropy.json.got",
|
|
|
ConfigPath: "../test_data/test_configs/regex_entropy.toml",
|
|
ConfigPath: "../test_data/test_configs/regex_entropy.toml",
|
|
|
ReportFormat: "json",
|
|
ReportFormat: "json",
|
|
|
|
|
+ Threads: runtime.GOMAXPROCS(0),
|
|
|
},
|
|
},
|
|
|
wantPath: "../test_data/test_regex_entropy.json",
|
|
wantPath: "../test_data/test_regex_entropy.json",
|
|
|
},
|
|
},
|
|
@@ -425,6 +431,38 @@ func TestScan(t *testing.T) {
|
|
|
},
|
|
},
|
|
|
wantPath: "../test_data/test_only_files_no_git.json",
|
|
wantPath: "../test_data/test_only_files_no_git.json",
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ description: "test allowlist files",
|
|
|
|
|
+ opts: options.Options{
|
|
|
|
|
+ Path: "../test_data/test_repos/test_repo_10",
|
|
|
|
|
+ Report: "../test_data/test_allow_list_file.json.got",
|
|
|
|
|
+ ReportFormat: "json",
|
|
|
|
|
+ ConfigPath: "../test_data/test_configs/allowlist_files.toml",
|
|
|
|
|
+ },
|
|
|
|
|
+ wantPath: "../test_data/test_allow_list_file.json",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ description: "test allowlist files no-git",
|
|
|
|
|
+ opts: options.Options{
|
|
|
|
|
+ Path: "../test_data/test_repos/test_repo_10",
|
|
|
|
|
+ Report: "../test_data/test_allow_list_file_no_git.json.got",
|
|
|
|
|
+ ReportFormat: "json",
|
|
|
|
|
+ ConfigPath: "../test_data/test_configs/allowlist_files.toml",
|
|
|
|
|
+ NoGit: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ wantPath: "../test_data/test_allow_list_file_no_git.json",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ description: "test allowlist docx no-git",
|
|
|
|
|
+ opts: options.Options{
|
|
|
|
|
+ Path: "../test_data/test_repos/test_repo_10",
|
|
|
|
|
+ Report: "../test_data/test_allow_list_docx_no_git.json.got",
|
|
|
|
|
+ ReportFormat: "json",
|
|
|
|
|
+ ConfigPath: "../test_data/test_configs/allowlist_docx.toml",
|
|
|
|
|
+ NoGit: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ wantPath: "../test_data/test_allow_list_docx_no_git.json",
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
for _, test := range tests {
|
|
@@ -708,6 +746,14 @@ func moveDotGit(from, to string) error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
for _, dir := range repoDirs {
|
|
for _, dir := range repoDirs {
|
|
|
|
|
+ if to == ".git" {
|
|
|
|
|
+ _, err := os.Stat(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), "dotGit"))
|
|
|
|
|
+ if os.IsNotExist(err) {
|
|
|
|
|
+ // dont want to delete the only copy of .git accidentally
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ os.RemoveAll(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), ".git"))
|
|
|
|
|
+ }
|
|
|
if !dir.IsDir() {
|
|
if !dir.IsDir() {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
@@ -721,6 +767,7 @@ func moveDotGit(from, to string) error {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
+ // fmt.Println("RENAMED")
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|