(t *testing.T)
| 348 | } |
| 349 | |
| 350 | func TestHttpProxyStartStop(t *testing.T) { |
| 351 | sess, mockFirewall := createMockSession() |
| 352 | mod := NewHttpProxy(sess) |
| 353 | |
| 354 | // Configure with test parameters |
| 355 | sess.Env.Set("http.port", "80") |
| 356 | sess.Env.Set("http.proxy.address", "127.0.0.1") |
| 357 | sess.Env.Set("http.proxy.port", "0") // Use port 0 to get a random available port |
| 358 | sess.Env.Set("http.proxy.redirect", "true") |
| 359 | sess.Env.Set("http.proxy.sslstrip", "false") |
| 360 | |
| 361 | // Start the proxy |
| 362 | err := mod.Start() |
| 363 | if err != nil { |
| 364 | t.Fatalf("Failed to start proxy: %v", err) |
| 365 | } |
| 366 | |
| 367 | if !mod.Running() { |
| 368 | t.Error("Proxy should be running after Start()") |
| 369 | } |
| 370 | |
| 371 | // Check that forwarding was enabled |
| 372 | if !mockFirewall.IsForwardingEnabled() { |
| 373 | t.Error("Forwarding should be enabled after starting proxy") |
| 374 | } |
| 375 | |
| 376 | // Check that redirection was added |
| 377 | if len(mockFirewall.redirections) != 1 { |
| 378 | t.Errorf("Expected 1 redirection, got %d", len(mockFirewall.redirections)) |
| 379 | } |
| 380 | |
| 381 | // Give the server time to start |
| 382 | time.Sleep(100 * time.Millisecond) |
| 383 | |
| 384 | // Stop the proxy |
| 385 | err = mod.Stop() |
| 386 | if err != nil { |
| 387 | t.Fatalf("Failed to stop proxy: %v", err) |
| 388 | } |
| 389 | |
| 390 | if mod.Running() { |
| 391 | t.Error("Proxy should not be running after Stop()") |
| 392 | } |
| 393 | |
| 394 | // Check that redirection was removed |
| 395 | if len(mockFirewall.redirections) != 0 { |
| 396 | t.Errorf("Expected 0 redirections after stop, got %d", len(mockFirewall.redirections)) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | func TestHttpProxyAlreadyStarted(t *testing.T) { |
| 401 | sess, _ := createMockSession() |
nothing calls this directly
no test coverage detected