package modules_test import ( "context" "net/http" "net/http/httptest" "testing" "time" "github.com/vmfunc/sif/internal/modules" ) func runHAProxyStatsModule(t *testing.T, status int, body string) *modules.Result { t.Helper() def, err := modules.ParseYAMLModule("../../modules/recon/haproxy-stats-exposure.yaml") if err != nil { t.Fatalf("parse haproxy stats module: %v", err) } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(status) _, _ = w.Write([]byte(body)) })) defer srv.Close() res, err := modules.ExecuteHTTPModule(context.Background(), srv.URL, def, modules.Options{ Timeout: 5 * time.Second, Threads: 2, }) if err != nil { t.Fatalf("execute haproxy stats module: %v", err) } return res } func haproxyExtract(res *modules.Result, key string) string { for _, f := range res.Findings { if v := f.Extracted[key]; v != "" { return v } } return "" } func TestHAProxyStatsExposureModule(t *testing.T) { // title and process-info banner text taken verbatim from a live haproxy stats page statsBody := `
HAProxy version 3.5-dev1, released 2026/06/25
` + `pid = 1314390 (process #1, nbproc = 1, nbthread = 4)
` t.Run("an exposed haproxy stats page is flagged and versioned", func(t *testing.T) { res := runHAProxyStatsModule(t, 200, statsBody) if len(res.Findings) == 0 { t.Fatal("expected a haproxy stats finding") } if v := haproxyExtract(res, "haproxy_version"); v != "3.5" { t.Errorf("haproxy_version=%q, want 3.5", v) } }) t.Run("a basic-auth challenge is not a leak", func(t *testing.T) { body := `We run HAProxy version 2.8 behind nginx for high availability.
` if res := runHAProxyStatsModule(t, 200, body); len(res.Findings) > 0 { t.Errorf("prose mentioning haproxy version should not match, got %d findings", len(res.Findings)) } }) t.Run("a stats title without the version banner is not enough", func(t *testing.T) { // shares the title anchor but not the version banner, proving both are load-bearing body := `