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

Function TestHTTPProxyDoProxy

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

Source from the content-addressed store, hash-verified

424}
425
426func TestHTTPProxyDoProxy(t *testing.T) {
427 sess, _ := createMockSession()
428 proxy := NewHTTPProxy(sess, "test")
429
430 tests := []struct {
431 name string
432 request *http.Request
433 expected bool
434 }{
435 {
436 name: "valid request",
437 request: &http.Request{
438 Host: "example.com",
439 },
440 expected: true,
441 },
442 {
443 name: "empty host",
444 request: &http.Request{
445 Host: "",
446 },
447 expected: false,
448 },
449 {
450 name: "localhost request",
451 request: &http.Request{
452 Host: "localhost:8080",
453 },
454 expected: false,
455 },
456 {
457 name: "127.0.0.1 request",
458 request: &http.Request{
459 Host: "127.0.0.1:8080",
460 },
461 expected: false,
462 },
463 }
464
465 for _, tt := range tests {
466 t.Run(tt.name, func(t *testing.T) {
467 result := proxy.doProxy(tt.request)
468 if result != tt.expected {
469 t.Errorf("doProxy(%v) = %v, expected %v", tt.request.Host, result, tt.expected)
470 }
471 })
472 }
473}
474
475func TestHTTPProxyShouldProxy(t *testing.T) {
476 sess, _ := createMockSession()

Callers

nothing calls this directly

Calls 4

doProxyMethod · 0.95
NewHTTPProxyFunction · 0.85
createMockSessionFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected