MCPcopy Index your code
hub / github.com/bettercap/bettercap / TestHTTPProxyScriptLoading

Function TestHTTPProxyScriptLoading

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

Source from the content-addressed store, hash-verified

646}
647
648func TestHTTPProxyScriptLoading(t *testing.T) {
649 sess, _ := createMockSession()
650 proxy := NewHTTPProxy(sess, "test")
651
652 // Create a temporary script file
653 scriptContent := `
654function onRequest(req, res) {
655 console.log("Request intercepted");
656}
657`
658 tmpFile, err := ioutil.TempFile("", "proxy_script_*.js")
659 if err != nil {
660 t.Fatalf("Failed to create temp file: %v", err)
661 }
662 defer os.Remove(tmpFile.Name())
663
664 if _, err := tmpFile.Write([]byte(scriptContent)); err != nil {
665 t.Fatalf("Failed to write script: %v", err)
666 }
667 tmpFile.Close()
668
669 // Try to configure with non-existent script
670 err = proxy.Configure("127.0.0.1", 8080, 80, false, "non_existent_script.js", "", false)
671 if err == nil {
672 t.Error("Configure should fail with non-existent script")
673 }
674
675 // Note: Actual script loading would require proper JS engine setup
676 // which is complex to mock. This test verifies the error handling.
677}
678
679// Benchmarks
680func BenchmarkHTTPProxyShouldProxy(b *testing.B) {

Callers

nothing calls this directly

Calls 8

ConfigureMethod · 0.95
NewHTTPProxyFunction · 0.85
createMockSessionFunction · 0.70
NameMethod · 0.65
RemoveMethod · 0.45
WriteMethod · 0.45
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected