MCPcopy
hub / github.com/bettercap/bettercap / TestHTTPProxyWithTestServer

Function TestHTTPProxyWithTestServer

modules/http_proxy/http_proxy_test.go:618–646  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

616}
617
618func TestHTTPProxyWithTestServer(t *testing.T) {
619 // Create a test HTTP server
620 testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
621 w.WriteHeader(http.StatusOK)
622 w.Write([]byte("<html><head></head><body>Test Page</body></html>"))
623 }))
624 defer testServer.Close()
625
626 sess, _ := createMockSession()
627 proxy := NewHTTPProxy(sess, "test")
628
629 // Configure proxy with JS injection
630 err := proxy.Configure("127.0.0.1", 0, 80, false, "", "console.log('injected');", false)
631 if err != nil {
632 t.Fatalf("Configure failed: %v", err)
633 }
634
635 // Create a simple test to verify proxy is initialized
636 if proxy.Proxy == nil {
637 t.Error("Proxy not initialized")
638 }
639
640 if proxy.jsHook == "" {
641 t.Error("JavaScript hook not set")
642 }
643
644 // Note: Testing actual proxy behavior would require setting up the proxy server
645 // and making HTTP requests through it, which is complex in a unit test environment
646}
647
648func TestHTTPProxyScriptLoading(t *testing.T) {
649 sess, _ := createMockSession()

Callers

nothing calls this directly

Calls 7

ConfigureMethod · 0.95
NewHTTPProxyFunction · 0.85
WriteHeaderMethod · 0.80
createMockSessionFunction · 0.70
WriteMethod · 0.45
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected