(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestRepositoryDoesNotContainForbiddenToken(t *testing.T) { |
| 12 | token := os.Getenv("DUCKGRES_FORBIDDEN_REPO_TOKEN") |
| 13 | if token == "" { |
| 14 | t.Skip("DUCKGRES_FORBIDDEN_REPO_TOKEN is unset") |
| 15 | } |
| 16 | |
| 17 | var matches []string |
| 18 | files, err := exec.Command("git", "ls-files", "-z").Output() |
| 19 | if err != nil { |
| 20 | t.Fatalf("list tracked files: %v", err) |
| 21 | } |
| 22 | |
| 23 | for _, file := range bytes.Split(files, []byte{0}) { |
| 24 | if len(file) == 0 { |
| 25 | continue |
| 26 | } |
| 27 | path := string(file) |
| 28 | content, err := os.ReadFile(path) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | if bytes.Contains(bytes.ToLower(content), []byte(strings.ToLower(token))) { |
| 33 | matches = append(matches, path) |
| 34 | } |
| 35 | } |
| 36 | if len(matches) > 0 { |
| 37 | t.Fatalf("forbidden repository token found in %s", strings.Join(matches, ", ")) |
| 38 | } |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected