(b *testing.B)
| 25 | } |
| 26 | |
| 27 | func BenchmarkDirMode(b *testing.B) { |
| 28 | h := httpServer(b, "test") |
| 29 | defer h.Close() |
| 30 | |
| 31 | u, err := url.Parse(h.URL) |
| 32 | if err != nil { |
| 33 | b.Fatalf("could not parse URL: %v", err) |
| 34 | } |
| 35 | pluginopts := gobusterdir.NewOptions() |
| 36 | pluginopts.URL = u |
| 37 | pluginopts.Timeout = 10 * time.Second |
| 38 | |
| 39 | pluginopts.Extensions = ".php,.csv" |
| 40 | tmpExt, err := libgobuster.ParseExtensions(pluginopts.Extensions) |
| 41 | if err != nil { |
| 42 | b.Fatalf("could not parse extensions: %v", err) |
| 43 | } |
| 44 | pluginopts.ExtensionsParsed = tmpExt |
| 45 | |
| 46 | pluginopts.StatusCodes = "200,204,301,302,307,401,403" |
| 47 | tmpStat, err := libgobuster.ParseCommaSeparatedInt(pluginopts.StatusCodes) |
| 48 | if err != nil { |
| 49 | b.Fatalf("could not parse status codes: %v", err) |
| 50 | } |
| 51 | pluginopts.StatusCodesParsed = tmpStat |
| 52 | |
| 53 | wordlist, err := os.CreateTemp(b.TempDir(), "") |
| 54 | if err != nil { |
| 55 | b.Fatalf("could not create tempfile: %v", err) |
| 56 | } |
| 57 | defer os.Remove(wordlist.Name()) |
| 58 | for w := range 1000 { |
| 59 | _, _ = fmt.Fprintf(wordlist, "%d\n", w) |
| 60 | } |
| 61 | if err := wordlist.Close(); err != nil { |
| 62 | b.Fatalf("%v", err) |
| 63 | } |
| 64 | |
| 65 | globalopts := libgobuster.Options{ |
| 66 | Threads: 10, |
| 67 | Wordlist: wordlist.Name(), |
| 68 | NoProgress: true, |
| 69 | } |
| 70 | |
| 71 | ctx := b.Context() |
| 72 | oldStdout := os.Stdout |
| 73 | oldStderr := os.Stderr |
| 74 | defer func(out, err *os.File) { os.Stdout = out; os.Stderr = err }(oldStdout, oldStderr) |
| 75 | devnull, err := os.Open(os.DevNull) |
| 76 | if err != nil { |
| 77 | b.Fatalf("could not get devnull %v", err) |
| 78 | } |
| 79 | defer devnull.Close() |
| 80 | log := libgobuster.NewLogger(false) |
| 81 | |
| 82 | // Run the real benchmark |
| 83 | for b.Loop() { |
| 84 | os.Stdout = devnull |
nothing calls this directly
no test coverage detected