High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
perf: speed up proxy tests + navigate timeout
Datad336ceafd84e
diff --git a/scripts/check.sh b/scripts/check.shindex 14bf8d45..7788a49f 100755--- a/scripts/check.sh+++ b/scripts/check.sh@@ -115,29 +115,36 @@ run_integration_tests() {local elapsedelapsed=$(echo "$line" | jq -r '.Elapsed // empty' 2>/dev/null)+ # Truncate long test names+ local display_name="$test_name"+ local max_len=40+ if [ ${#display_name} -gt $max_len ]; then+ display_name="${display_name:0:$((max_len - 1))}…"+ fi+case "$action" inrun)- printf "\r ${MUTED}▸ %s${NC}%*s" "$test_name" $((50 - ${#test_name})) ""+ printf "\r ${MUTED}▸ %-${max_len}s${NC} \r" "$display_name";;pass)count=$((count + 1))if [ -n "$elapsed" ]; then- printf "\r ${SUCCESS}✓${NC} ${MUTED}[%d]${NC} %-40s ${MUTED}%ss${NC}\n" "$count" "$test_name" "$elapsed"+ printf "\r ${SUCCESS}✓${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display_name" "$elapsed"else- printf "\r ${SUCCESS}✓${NC} ${MUTED}[%d]${NC} %s%*s\n" "$count" "$test_name" $((40 - ${#test_name})) ""+ printf "\r ${SUCCESS}✓${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display_name"fi;;fail)count=$((count + 1))if [ -n "$elapsed" ]; then- printf "\r ${ERROR}✗${NC} ${MUTED}[%d]${NC} %-40s ${MUTED}%ss${NC}\n" "$count" "$test_name" "$elapsed"+ printf "\r ${ERROR}✗${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED}%6ss${NC}\n" "$count" "$display_name" "$elapsed"else- printf "\r ${ERROR}✗${NC} ${MUTED}[%d]${NC} %s%*s\n" "$count" "$test_name" $((40 - ${#test_name})) ""+ printf "\r ${ERROR}✗${NC} ${MUTED}[%2d]${NC} %-${max_len}s\n" "$count" "$display_name"fi;;skip)count=$((count + 1))- printf "\r ${ACCENT}·${NC} ${MUTED}[%d]${NC} %s ${MUTED}(skip)${NC}%*s\n" "$count" "$test_name" $((30 - ${#test_name})) ""+ printf "\r ${ACCENT}·${NC} ${MUTED}[%2d]${NC} %-${max_len}s ${MUTED} skip${NC}\n" "$count" "$display_name";;esacdonediff --git a/tests/integration/navigate_test.go b/tests/integration/navigate_test.goindex 74e20ff3..0f45ff17 100644--- a/tests/integration/navigate_test.go+++ b/tests/integration/navigate_test.go@@ -74,8 +74,11 @@ func TestNavigate_NewTab(t *testing.T) {// N8: Navigate timeout handlingfunc TestNavigate_Timeout(t *testing.T) {// Use a reserved IP address that will timeout (TEST-NET-1)- // This should not hang forever, but may return an error or timeout gracefully- code, _ := httpPost(t, "/navigate", map[string]string{"url": "http://192.0.2.1"})+ // Pass a short timeout so we don't wait 30s for the default+ code, _ := httpPost(t, "/navigate", map[string]any{+ "url": "http://192.0.2.1",+ "timeout": 5, // 5s instead of default 30s+ })// Just verify request completes (doesn't hang forever)// Response code can vary (200, 400, etc)t.Logf("navigate timeout returned %d", code)diff --git a/tests/integration/security_proxy_test.go b/tests/integration/security_proxy_test.goindex ac553335..e99650a7 100644--- a/tests/integration/security_proxy_test.go+++ b/tests/integration/security_proxy_test.go@@ -9,70 +9,61 @@ import ("time")-// TestProxy_LocalhostOnly verifies that proxy endpoints only target localhost-// Security: Prevents Server-Side Request Forgery (SSRF) attacks-func TestProxy_LocalhostOnly(t *testing.T) {- // Create an instance first+// proxyInstance creates a shared instance for proxy tests that don't need isolation.+// Returns instance ID; registers cleanup via t.Cleanup.+func proxyInstance(t *testing.T) string {+ t.Helper()+payload := map[string]any{- "name": fmt.Sprintf("ssrf-test-%d", time.Now().Unix()),+ "name": fmt.Sprintf("proxy-test-%d", time.Now().Unix()),"headless": true,}status, body := httpPost(t, "/instances/launch", payload)if status != 201 {- t.Fatalf("failed to create instance: %d", status)+ t.Fatalf("failed to create proxy test instance: %d", status)}instID := jsonField(t, body, "id")- defer httpPost(t, fmt.Sprintf("/instances/%s/stop", instID), nil)+ t.Cleanup(func() {+ httpPost(t, fmt.Sprintf("/instances/%s/stop", instID), nil)+ })- // Wait for instance to be readywaitForInstanceReady(t, instID)-- // The proxy handler validates that Host is localhost- // This test verifies the construct happens correctly- // (actual SSRF prevention is done at handler level through url.URL struct)-- // Verify instance can be accessed via proxy- code, _, _ := navigateInstance(t, instID, "https://example.com")-- if code != 200 {- t.Errorf("expected 200 for valid localhost proxy, got %d", code)- }+ return instID}-// TestProxy_URLValidation verifies that URL construction is safe-// Security: Ensures URL.Host validation happens before making request-func TestProxy_URLValidation(t *testing.T) {- // Create instance- payload := map[string]any{- "name": fmt.Sprintf("url-val-test-%d", time.Now().Unix()),- "headless": true,- }-- status, body := httpPost(t, "/instances/launch", payload)- if status != 201 {- t.Fatalf("failed to create instance: %d", status)- }-- instID := jsonField(t, body, "id")- defer httpPost(t, fmt.Sprintf("/instances/%s/stop", instID), nil)+// TestProxy groups all proxy security tests under a single instance where possible.+func TestProxy(t *testing.T) {+ instID := proxyInstance(t)- // Wait for instance to be ready- waitForInstanceReady(t, instID)+ t.Run("LocalhostOnly", func(t *testing.T) {+ // Verify instance can be accessed via proxy (SSRF prevention)+ code, _, _ := navigateInstance(t, instID, "https://example.com")+ if code != 200 {+ t.Errorf("expected 200 for valid localhost proxy, got %d", code)+ }+ })- // Test with valid URL in path- code, respBody, _ := navigateInstance(t, instID, "https://example.com/path?query=value")+ t.Run("URLValidation", func(t *testing.T) {+ // Verify URL construction is safe with query params+ code, respBody, _ := navigateInstance(t, instID, "https://example.com/path?query=value")+ if code != 200 {+ t.Logf("navigate with query params got %d: %s", code, string(respBody))+ }+ })- if code != 200 {- t.Logf("navigate with query params got %d: %s", code, string(respBody))- // Not critical if query params cause issues, main thing is it goes through- }+ t.Run("SchemeValidation", func(t *testing.T) {+ // Verify proxy uses http scheme for localhost+ code, respBody, _ := navigateInstance(t, instID, "https://example.com")+ if code != 200 {+ t.Errorf("navigate failed (scheme validation): %d: %s", code, string(respBody))+ }+ })}-// TestProxy_InstanceIsolation verifies each instance is isolated via proxy+// TestProxy_InstanceIsolation needs its own instances to verify isolation.func TestProxy_InstanceIsolation(t *testing.T) {- // Create 2 instancesvar instIDs []stringvar ports []string@@ -100,71 +91,31 @@ func TestProxy_InstanceIsolation(t *testing.T) {}}()- // Verify instances have different ports (isolation)if ports[0] == ports[1] {t.Fatalf("instances have same port: %s == %s", ports[0], ports[1])}- // Wait for instances to be readywaitForInstanceReady(t, instIDs[0])waitForInstanceReady(t, instIDs[1])- // Navigate in first instancecode1, body1, _ := navigateInstance(t, instIDs[0], "https://example.com/page1")-if code1 != 200 {t.Errorf("navigate in inst1 failed: %d: %s", code1, string(body1))}- // Navigate in second instancecode2, body2, _ := navigateInstance(t, instIDs[1], "https://example.com/page2")-if code2 != 200 {t.Errorf("navigate in inst2 failed: %d: %s", code2, string(body2))}- // Verify tabs are isolated (each instance should have own tabs)- // This confirms proxy routing to correct instance_, tabsBody1 := httpPost(t, fmt.Sprintf("/instances/%s/tabs", instIDs[0]), nil)_, tabsBody2 := httpPost(t, fmt.Sprintf("/instances/%s/tabs", instIDs[1]), nil)- // Parse to verify both return valid tab data- var tabs1 map[string]any- var tabs2 map[string]any-+ var tabs1, tabs2 map[string]anyif err := json.Unmarshal(tabsBody1, &tabs1); err != nil {t.Logf("inst1 tabs response not JSON: %v", err)}-if err := json.Unmarshal(tabsBody2, &tabs2); err != nil {t.Logf("inst2 tabs response not JSON: %v", err)}}--// TestProxy_SchemeValidation verifies proxy always uses http scheme for localhost-// Security: Ensures we don't accidentally proxy to https:// localhost-func TestProxy_SchemeValidation(t *testing.T) {- // Create instance- payload := map[string]any{- "name": fmt.Sprintf("scheme-test-%d", time.Now().Unix()),- "headless": true,- }-- status, body := httpPost(t, "/instances/launch", payload)- if status != 201 {- t.Fatalf("failed to create instance: %d", status)- }-- instID := jsonField(t, body, "id")- defer httpPost(t, fmt.Sprintf("/instances/%s/stop", instID), nil)-- // Wait for instance to be ready- waitForInstanceReady(t, instID)-- // Navigate should work (verifies internal http scheme is used)- code, respBody, _ := navigateInstance(t, instID, "https://example.com")-- if code != 200 {- t.Errorf("navigate failed (scheme validation): %d: %s", code, string(respBody))- }-}