test: Add integration tests for EnforceHostMiddleware (WA-VERIFY-085)#1076
test: Add integration tests for EnforceHostMiddleware (WA-VERIFY-085)#1076kitcommerce merged 2 commits intonextfrom
Conversation
…nges (#1067) Fixes #1067 The rescue was already narrowed from bare rescue to rescue StandardError by PR #1040, but lacked an explanatory comment. Add a comment clarifying: - Why StandardError is used (not bare rescue): ensures SignalException/Interrupt and other non-StandardError signals propagate correctly - What the rescue does: falls back to async reindexing when inline indexing fails (e.g. Elasticsearch unavailable)
Adds EnforceHostMiddlewareTest covering: - Constant definition smoke test (regression guard for PR #1066 require_relative fix) - Middleware presence in Rails.application.middleware stack - Pass-through when enforce_host is disabled - Pass-through when request host matches configured host - 301 redirect when host does not match - Redirect preserves original request scheme - Skip enforcement via skip_enforce_host proc Follows RackAttackIntegrationTest pattern: isolated Rack stack, no full app boot needed. Fixes #1071
🤖 Wave 1 Automated Review — PR #1076Architecture —
|
Wave 2 Review Resultsrails-security: PASS — middleware behavior is security-adjacent; tests validate redirect/skip behavior without broadening exposure. Wave 2 PASSED. |
kitcommerce
left a comment
There was a problem hiding this comment.
Wave 3 reviews (performance / frontend / accessibility)
{"reviewer":"performance","verdict":"PASS","severity":null,"summary":"Test-only additions; no runtime performance impact.","findings":[]}{"reviewer":"frontend","verdict":"PASS","severity":null,"summary":"No frontend code changes.","findings":[]}{"reviewer":"accessibility","verdict":"PASS","severity":null,"summary":"No accessibility-affecting changes.","findings":[]}
kitcommerce
left a comment
There was a problem hiding this comment.
Wave 4 (documentation) review
PASS — No documentation updates required for additional integration tests.
Fixes #1071
Summary
Adds
EnforceHostMiddlewareTest— a new integration test file covering theWorkarea::EnforceHostMiddlewareclass end-to-end.Motivation: PR #1066 added
require_relativecalls incore/config/initializers/10_rack_middleware.rbto fix a Rails 7.0NameErrorforEnforceHostMiddleware. While the middleware's presence in the stack was already tested byRackMiddlewareStackTest#test_enforce_host_middleware_is_present, there were no tests exercising the middleware's actual request-level behavior or confirming the constant loads without error.What's covered:
Rails.application.middlewarestackWorkarea.config.enforce_hostisfalseWorkarea.config.hostskip_enforce_hostproc respected (both true and false branches)Follows the pattern established by
RackAttackIntegrationTest: isolated Rack stack built inline, no full app boot required, fast and hermetic.Rubocop: 1 file inspected, no offenses detected.
Client Impact
None — test-only addition.