MCPcopy
hub / github.com/OJ/gobuster / BenchmarkVhostMode

Function BenchmarkVhostMode

cli/vhost/vhost_test.go:27–83  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

25}
26
27func BenchmarkVhostMode(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: %v", h.URL, err)
34 }
35 pluginopts := gobustervhost.NewOptions()
36 pluginopts.URL = u
37 pluginopts.Timeout = 10 * time.Second
38
39 wordlist, err := os.CreateTemp(b.TempDir(), "")
40 if err != nil {
41 b.Fatalf("could not create tempfile: %v", err)
42 }
43 defer os.Remove(wordlist.Name())
44 for w := range 1000 {
45 _, _ = fmt.Fprintf(wordlist, "%d\n", w)
46 }
47 if err := wordlist.Close(); err != nil {
48 b.Fatalf("%v", err)
49 }
50
51 globalopts := libgobuster.Options{
52 Threads: 10,
53 Wordlist: wordlist.Name(),
54 NoProgress: true,
55 }
56
57 ctx := b.Context()
58 oldStdout := os.Stdout
59 oldStderr := os.Stderr
60 defer func(out, err *os.File) { os.Stdout = out; os.Stderr = err }(oldStdout, oldStderr)
61 devnull, err := os.Open(os.DevNull)
62 if err != nil {
63 b.Fatalf("could not get devnull %v", err)
64 }
65 defer devnull.Close()
66 log := libgobuster.NewLogger(false)
67
68 // Run the real benchmark
69 for b.Loop() {
70 os.Stdout = devnull
71 os.Stderr = devnull
72 plugin, err := gobustervhost.New(&globalopts, pluginopts, log)
73 if err != nil {
74 b.Fatalf("error on creating gobusterdir: %v", err)
75 }
76
77 if err := cli.Gobuster(ctx, &globalopts, plugin, log); err != nil {
78 b.Fatalf("error on running gobuster: %v", err)
79 }
80 os.Stdout = oldStdout
81 os.Stderr = oldStderr
82 }
83}

Callers

nothing calls this directly

Calls 7

NewOptionsFunction · 0.92
NewLoggerFunction · 0.92
NewFunction · 0.92
GobusterFunction · 0.92
FatalfMethod · 0.80
httpServerFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected