🐛 fix: add Host header to Go test requests for fasthttp 1.72.0#19930
Conversation
fasthttp 1.72.0 (bumped in #19889) requires a Host header on every HTTP request. Add req.Host = "localhost" after every http.NewRequest and httptest.NewRequest call across 174 test files (1163 call sites). Fixes #19909 Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
✅ Deploy Preview for kubestellarconsole canceled.
|
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
This PR addresses Go test failures introduced by the fasthttp 1.72.0 update by ensuring every test HTTP request has a non-empty Host value, which is now required by Fiber/fasthttp when adapting net/http requests.
Changes:
- Added
req.Host = "localhost"afterhttptest.NewRequest/http.NewRequestin a broad sweep of Go tests. - Restored passing behavior for many previously failing Fiber route/handler tests affected by the missing Host header.
- Touched a large number of test files to apply the fix consistently (PR description: 174 files / 1163 call sites).
Reviewed changes
Copilot reviewed 174 out of 174 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/watcher/watcher_test.go | Set Host on httptest requests used by watcher fallback/API detection tests. |
| pkg/watcher/watcher_coverage_test.go | Set Host on httptest requests used by ServeFallback coverage tests. |
| pkg/api/routes_registration_test.go | Set Host on Fiber app.Test requests for registration route tests. |
| pkg/api/routes_health_test.go | Set Host on Fiber app.Test requests for health/version route tests. |
| pkg/api/routes_feedback_test.go | Set Host on Fiber app.Test requests for feedback route tests. |
| pkg/api/routes_auth_test.go | Set Host on Fiber app.Test requests for auth route registration tests. |
| pkg/api/routes_api_core_test.go | Set Host on Fiber app.Test requests for core API route tests. |
| pkg/api/middleware/websocket_origin_test.go | Set Host on requests used by websocket origin middleware tests. |
| pkg/api/middleware/ratelimit_test.go | Set Host on requests used by ratelimit middleware tests. |
| pkg/api/middleware/csrf_test.go | Set Host on requests used by CSRF middleware tests. |
| pkg/api/middleware/auth_ws_revoke_test.go | Set Host on requests used by websocket revoke/auth tests. |
| pkg/api/middleware_setup_test.go | Set Host on requests used by middleware setup/CSP tests. |
| pkg/api/handlers/youtube_test.go | Set Host on handler test requests for YouTube endpoints. |
| pkg/api/handlers/workloads/persistence_test.go | Set Host on handler test requests for workloads persistence endpoints. |
| pkg/api/handlers/workloads/helpers_test.go | Set Host on handler test requests for demo-mode helpers. |
| pkg/api/handlers/workloads/cluster_query_test.go | Set Host on handler test requests for AI cluster query endpoints. |
| pkg/api/handlers/websocket_ratelimit_test.go | Set Host on handler test requests for websocket rate limiting. |
| pkg/api/handlers/validate_test.go | Set Host on handler test requests for validation endpoints. |
| pkg/api/handlers/user_test.go | Set Host on handler test requests for user endpoints. |
| pkg/api/handlers/topology_test.go | Set Host on handler test requests for topology endpoint. |
| pkg/api/handlers/token_usage_test.go | Set Host on handler test requests for token-usage endpoints. |
| pkg/api/handlers/timeline_test.go | Set Host on handler test requests for timeline endpoints. |
| pkg/api/handlers/teams_test.go | Set Host in shared helper request builder for teams tests. |
| pkg/api/handlers/swap_test.go | Set Host on handler test requests for swap endpoints. |
| pkg/api/handlers/stellar/security_test.go | Set Host on handler test requests for Stellar security endpoints. |
| pkg/api/handlers/stellar/providers_test.go | Set Host on handler test requests for Stellar providers endpoints. |
| pkg/api/handlers/stellar/preferences_test.go | Set Host on handler test requests for Stellar preferences endpoints. |
| pkg/api/handlers/stellar/observations_test.go | Set Host on handler test requests for Stellar observations endpoints. |
| pkg/api/handlers/stellar/notifications_test.go | Set Host on handler test requests for Stellar notifications endpoints. |
| pkg/api/handlers/stellar/mocked_handlers_test.go | Set Host on handler test requests for Stellar mocked-store handler tests. |
| pkg/api/handlers/stellar/missions_test.go | Set Host on handler test requests for Stellar missions payload tests. |
| pkg/api/handlers/stellar/auth_test.go | Set Host on handler test requests for Stellar auth helper tests. |
| pkg/api/handlers/stellar/actions_test.go | Set Host on handler test requests for Stellar actions endpoints. |
| pkg/api/handlers/shared_utils_test.go | Set Host on handler test requests for shared utils parsing tests. |
| pkg/api/handlers/settings_test.go | Set Host on handler test requests for settings endpoints. |
| pkg/api/handlers/settings_integration_test.go | Set Host on integration test requests for settings round-trip. |
| pkg/api/handlers/service_exports_test.go | Set Host on handler test requests for service-exports endpoints. |
| pkg/api/handlers/self_upgrade_test.go | Set Host on handler test requests for self-upgrade endpoints. |
| pkg/api/handlers/rewards/handler_test.go | Set Host on handler test requests for rewards handler. |
| pkg/api/handlers/rewards/badge_test.go | Set Host on handler test requests for rewards badge handler. |
| pkg/api/handlers/rbac_test.go | Set Host on handler test requests for RBAC endpoints. |
| pkg/api/handlers/quantum_proxy_test.go | Set Host on handler test requests for quantum proxy endpoints. |
| pkg/api/handlers/ping_test.go | Set Host on handler test requests for ping endpoint tests. |
| pkg/api/handlers/persistence_admin_test.go | Set Host on handler test requests for persistence admin endpoints. |
| pkg/api/handlers/orbit_test.go | Set Host on handler test requests for orbit endpoints. |
| pkg/api/handlers/onboarding_test.go | Set Host on handler test requests for onboarding endpoints. |
| pkg/api/handlers/notifications_test.go | Set Host on handler test requests for notifications endpoints. |
| pkg/api/handlers/namespaces_test.go | Set Host on handler test requests for namespaces endpoints. |
| pkg/api/handlers/missions/scores_test.go | Set Host on handler test requests for missions scores endpoints. |
| pkg/api/handlers/missions/helpers_test.go | Set Host on handler test requests for missions helper middleware tests. |
| pkg/api/handlers/medium_test.go | Set Host on handler test requests for Medium proxy endpoint. |
| pkg/api/handlers/mcs_test.go | Set Host on handler test requests for MCS endpoints. |
| pkg/api/handlers/mcp/query_test.go | Set Host on handler test requests for MCP query parsing. |
| pkg/api/handlers/mcp/helpers_test.go | Set Host on handler test requests for MCP helper middleware. |
| pkg/api/handlers/lima_test.go | Set Host on handler test requests for Lima endpoints. |
| pkg/api/handlers/kubara_catalog_test.go | Set Host on handler test requests for Kubara catalog endpoints. |
| pkg/api/handlers/kagent_proxy_test.go | Set Host on handler test requests for kagent proxy endpoints. |
| pkg/api/handlers/k8s_helpers_test.go | Set Host on handler test requests for k8s helper tests. |
| pkg/api/handlers/k8s_errors_test.go | Set Host on handler test requests for k8s error mapping tests. |
| pkg/api/handlers/gpu_test.go | Set Host on handler test requests for GPU endpoints. |
| pkg/api/handlers/gitops/operators_test.go | Set Host on handler test requests for GitOps operator endpoints. |
| pkg/api/handlers/gitops/helpers_test.go | Set Host on handler test requests for GitOps helper demo-mode tests. |
| pkg/api/handlers/gitops/handler_test.go | Set Host on handler test requests for GitOps handler tests. |
| pkg/api/handlers/gitops/drift_test.go | Set Host on handler test requests for GitOps drift endpoints. |
| pkg/api/handlers/gitops/argo_test.go | Set Host on handler test requests for GitOps Argo endpoints. |
| pkg/api/handlers/github/proxy_test.go | Set Host on handler test requests for GitHub proxy endpoints. |
| pkg/api/handlers/github/pipelines_cache_test.go | Set Host on handler test requests for pipelines cache tests. |
| pkg/api/handlers/github/nightly_e2e_integration_test.go | Set Host on handler test requests for nightly-e2e integration tests. |
| pkg/api/handlers/github/nightly_e2e_handler_test.go | Set Host on handler test requests for nightly-e2e handler tests. |
| pkg/api/handlers/gadget_test.go | Set Host on handler test requests for gadget endpoints. |
| pkg/api/handlers/feedback/verification_test.go | Set Host on handler test requests for feedback verification endpoints. |
| pkg/api/handlers/feedback/test.go | Set Host on requests in feedback tests (note: file naming concern raised in review). |
| pkg/api/handlers/feedback/requests_test.go | Set Host on handler test requests for feedback requests endpoints. |
| pkg/api/handlers/feedback/requests_notifications_test.go | Set Host on handler test requests for feedback notifications endpoints. |
| pkg/api/handlers/feedback/requests_list_test.go | Set Host on handler test requests for feedback list endpoints. |
| pkg/api/handlers/feedback/requests_github_test.go | Set Host on handler test requests for feedback GitHub integration tests. |
| pkg/api/handlers/feedback/requests_crud_test.go | Set Host on handler test requests for feedback CRUD endpoints. |
| pkg/api/handlers/feedback/github_webhook_test.go | Set Host on handler test requests for feedback GitHub webhook tests. |
| pkg/api/handlers/feedback/crud_validation_test.go | Set Host on handler test requests for feedback CRUD validation helpers. |
| pkg/api/handlers/feedback/client_auth_test.go | Set Host on handler test requests for feedback client auth tests. |
| pkg/api/handlers/events_test.go | Set Host on handler test requests for events endpoints. |
| pkg/api/handlers/demo_data_test.go | Set Host on handler test requests for demo data helpers. |
| pkg/api/handlers/dashboard_test.go | Set Host on handler test requests for dashboard endpoints. |
| pkg/api/handlers/crds_test.go | Set Host on handler test requests for CRDs endpoints. |
| pkg/api/handlers/console_persistence_store_unit_test.go | Set Host on handler test requests for console persistence unit tests. |
| pkg/api/handlers/console_persistence_store_test.go | Set Host on handler test requests for console persistence tests. |
| pkg/api/handlers/console_persistence_helpers_test.go | Set Host on handler test requests for console persistence helper tests. |
| pkg/api/handlers/compliance/supply_chain_test.go | Set Host on handler test requests for supply chain endpoints. |
| pkg/api/handlers/compliance/stig_test.go | Set Host on handler test requests for STIG endpoints. |
| pkg/api/handlers/compliance/sod_test.go | Set Host on handler test requests for SoD endpoints. |
| pkg/api/handlers/compliance/siem_test.go | Set Host on handler test requests for SIEM endpoint auth coverage. |
| pkg/api/handlers/compliance/nist80053_test.go | Set Host on handler test requests for NIST 800-53 endpoints. |
| pkg/api/handlers/compliance/hipaa_test.go | Set Host on handler test requests for HIPAA endpoints. |
| pkg/api/handlers/compliance/gxp_test.go | Set Host on handler test requests for GxP endpoints. |
| pkg/api/handlers/compliance/fedramp_test.go | Set Host on handler test requests for FedRAMP endpoints. |
| pkg/api/handlers/compliance/data_residency_test.go | Set Host on handler test requests for data residency endpoints. |
| pkg/api/handlers/compliance/compliance_reports_test.go | Set Host on handler test requests for compliance reports endpoints. |
| pkg/api/handlers/compliance/compliance_frameworks_test.go | Set Host on handler test requests for compliance frameworks endpoints. |
| pkg/api/handlers/compliance/attestation_test.go | Set Host on handler test requests for attestation endpoints. |
| pkg/api/handlers/compliance/acmm_test.go | Set Host on handler test requests for ACMM endpoints. |
| pkg/api/handlers/compliance/acmm_scan_test.go | Set Host on handler test requests for ACMM scan tests. |
| pkg/api/handlers/compliance/acmm_badge_test.go | Set Host on handler test requests for ACMM badge tests. |
| pkg/api/handlers/change_control_test.go | Set Host on handler test requests for change-control endpoints. |
| pkg/api/handlers/card_proxy_test.go | Set Host on handler test requests for card-proxy endpoints. |
| pkg/api/handlers/benchmarks/benchmarks_test.go | Set Host on handler test requests for benchmarks endpoints. |
| pkg/api/handlers/benchmarks/benchmarks_streaming_test.go | Set Host on handler test requests for benchmarks streaming endpoints. |
| pkg/api/handlers/benchmarks/benchmarks_run_handler_test.go | Set Host on handler test requests for benchmarks run endpoints. |
| pkg/api/handlers/baa_test.go | Set Host on handler test requests for BAA compliance endpoints. |
| pkg/api/handlers/auth/oauth_test.go | Set Host on handler test requests for OAuth flow tests. |
| pkg/api/handlers/auth/middleware_wrappers_test.go | Set Host on handler test requests for auth middleware wrapper tests. |
| pkg/api/handlers/auth/middleware_test.go | Set Host on handler test requests for auth middleware tests. |
| pkg/api/handlers/auth/helpers_test.go | Set Host on handler test requests for auth helper tests. |
| pkg/api/handlers/auth/handler_test.go | Set Host on handler test requests for auth handler tests. |
| pkg/api/handlers/audit_test.go | Set Host on handler test requests for audit endpoints. |
| pkg/api/handlers/audit_export_integration_test.go | Set Host on handler test requests for audit export integration tests. |
| pkg/api/handlers/api_contract_test.go | Set Host on handler test requests for API contract tests. |
| pkg/api/handlers/analytics_proxy_test.go | Set Host on handler test requests for analytics proxy endpoint. |
| pkg/api/handlers/airgap_test.go | Set Host on handler test requests for airgap endpoints. |
| pkg/api/handlers/agentic_detection_runs_test.go | Set Host on handler test requests for detection runs endpoints. |
| pkg/api/handlers/agent_backend_integration_test.go | Set Host on handler test requests for agent backend integration tests. |
| pkg/api/handlers/admission_webhooks_test.go | Set Host on handler test requests for admission webhooks endpoints. |
| pkg/api/handlers/admin_test.go | Set Host on handler test requests for admin endpoints. |
| pkg/api/auth_sweep_test.go | Set Host on requests used by auth sweep tests. |
| pkg/api/audit/audit_test.go | Set Host on requests used by audit logging unit tests. |
| pkg/agent/workload_http_test.go | Set Host on httptest requests for agent workload HTTP handler tests. |
| pkg/agent/server_rbac_test.go | Set Host on httptest requests for agent RBAC handler tests. |
| pkg/agent/server_ops_settings_test.go | Set Host on httptest requests for agent ops/settings handler tests. |
| pkg/agent/server_ops_predictions_test.go | Set Host on httptest requests for agent predictions handler tests. |
| pkg/agent/server_ops_insights_test.go | Set Host on httptest requests for agent insights handler tests. |
| pkg/agent/server_ops_clusters_test.go | Set Host on httptest requests for agent clusters/ops handler tests. |
| pkg/agent/server_operations_test.go | Set Host on httptest requests for agent operations tests. |
| pkg/agent/server_nvidia_test.go | Set Host on httptest requests for agent Nvidia handler tests. |
| pkg/agent/server_http_workloads_test.go | Set Host on httptest requests for agent HTTP workloads tests. |
| pkg/agent/server_http_test.go | Set Host on httptest requests for agent HTTP resource/mutation tests. |
| pkg/agent/server_http_resources_workloads_test.go | Set Host on httptest requests for agent HTTP resource/workloads tests. |
| pkg/agent/server_http_resources_test.go | Set Host on httptest requests for agent HTTP resources tests. |
| pkg/agent/server_http_resources_stream_test.go | Set Host on httptest requests for agent streaming/SSE handler tests. |
| pkg/agent/server_http_resources_rbac_storage_test.go | Set Host on httptest requests for agent RBAC storage handler tests. |
| pkg/agent/server_helm_test.go | Set Host on httptest requests for agent Helm handler tests. |
| pkg/agent/server_health_test.go | Set Host on httptest requests for agent health/status/metrics tests. |
| pkg/agent/server_health_handler_test.go | Set Host on httptest requests for agent health handler unit tests. |
| pkg/agent/server_gpu_health_test.go | Set Host on httptest requests for agent GPU health cronjob tests. |
| pkg/agent/server_gitops_test.go | Set Host on httptest requests for agent GitOps handler tests. |
| pkg/agent/server_federation_test.go | Set Host on httptest requests for agent federation endpoints tests. |
| pkg/agent/server_exec_test.go | Set Host on httptest requests for agent exec/websocket endpoint tests. |
| pkg/agent/server_console_cr_test.go | Set Host on httptest requests for agent console CR handler tests. |
| pkg/agent/server_cilium_test.go | Set Host on httptest requests for agent Cilium handler tests. |
| pkg/agent/server_auth_test.go | Set Host on httptest requests for agent websocket/auth tests. |
| pkg/agent/server_argocd_test.go | Set Host on httptest requests for agent ArgoCD handler tests. |
| pkg/agent/prometheus_test.go | Set Host on httptest requests for agent Prometheus query tests. |
| pkg/agent/middleware_body_limit_test.go | Set Host on httptest requests for agent body limit middleware tests. |
| pkg/agent/kagenti_test.go | Set Host on httptest requests for Kagenti handler tests. |
| pkg/agent/kagent_crds_test.go | Set Host on httptest requests for kagent CRDs handler tests. |
| pkg/agent/endpoint_auth_test.go | Set Host on httptest requests for agent endpoint auth matrix tests. |
| pkg/agent/csrf_test.go | Set Host on httptest requests for agent CSRF middleware tests. |
| func TestFeedback_CreateFeatureRequest_InvalidTitleValidation(t *testing.T) { | ||
| userID := uuid.New() | ||
| app, handler := setupFeedbackTest(t, userID, "", nil) | ||
| app.Post("/api/feedback/requests", handler.CreateFeatureRequest) | ||
|
|
||
| payload := `{"title":"short","description":"this description has enough words","requestType":"feature"}` | ||
| req, err := http.NewRequest(http.MethodPost, "/api/feedback/requests", strings.NewReader(payload)) | ||
| req.Host = "localhost" | ||
| require.NoError(t, err) |
drasi_proxy_helpers_test.go (added recently) duplicates 5 test functions and 1 type declaration from drasi_proxy_test.go, causing go vet failures. Remove the duplicates from the older file. Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Place req.Host = "localhost" after require.NoError(t, err) to avoid nilaway "potential nil panic" findings. The Host must be set after confirming the request was created successfully. Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
- Change `req, _ :=` to `req, err :=` with `require.NoError(t, err)` in files that previously discarded the error from http.NewRequest - Add missing testify/require imports where needed - Move Host assignment after error-check blocks in orbit_test.go Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
- Move Host after panic(err) check in refreshReq helper - Change multi-line NewRequest _, to err with require.NoError Signed-off-by: Andy Anderson <andy@clubanderson.com> Signed-off-by: Andrew Anderson <andy@clubanderson.com>
CI Failure AnalysisThe
The gitops failure is NOT a Host header issue — fasthttp 1.72.0 now rejects the raw HTTP request at the parser level because the URL contains unencoded special characters ( Fix needed: In |
- auth tests: use relative URL path instead of absolute to avoid Host header serialization issue with fasthttp 1.72.0 - gitops tests: URL-encode special characters in cluster params so fasthttp request parser doesn't reject them Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: clubanderson <clubanderson@users.noreply.github.com>
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
⏹️ Post-Merge Verification: cancelledCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
Summary
Hostheader on every HTTP requesthttp.NewRequest/httptest.NewRequestwere missing this headerreq.Host = "localhost"after everyNewRequestcall across 174 test files (1163 call sites)Test plan
go test ./pkg/...passes locally (only 5 pre-existing failures remain, all present on main before this change)Fixes #19909