Add Rack::Lint to RequestId tests

This adds additional test coverage to RequestId to validate that its
input and output follow the Rack SPEC.

In this case, the only changes necessary were to the Request tests. This
is due to the fact that the Request and Response tests use different
classes for their Response headers. The Response tests simulate a Rails
app, where the Response headers will be a Rack::Headers object for
compatbility with both Rack 2 and 3. However, since the Request tests
are only using the Hash returned by the test app, the tests must use a
downcased header to support both Rack 2 and Rack 3.
This commit is contained in:
Hartley McGuire 2023-07-25 22:01:27 -04:00
parent dda937fa62
commit b2da0053aa
No known key found for this signature in database
GPG Key ID: E823FC1403858A82

@ -8,7 +8,7 @@ class RequestIdTest < ActiveSupport::TestCase
end
test "passing on the request id via a configured header" do
assert_equal "external-uu-rid", stub_request({ "HTTP_TRACER_ID" => "external-uu-rid" }, header: "Tracer-Id").request_id
assert_equal "external-uu-rid", stub_request({ "HTTP_TRACER_ID" => "external-uu-rid" }, header: "tracer-id").request_id
end
test "ensure that only alphanumeric uurids are accepted" do
@ -33,8 +33,17 @@ class RequestIdTest < ActiveSupport::TestCase
end
private
def stub_request(env = {}, header: "X-Request-Id")
ActionDispatch::RequestId.new(lambda { |environment| [ 200, environment, [] ] }, header: header).call(env)
def stub_request(env = {}, header: "x-request-id")
app = lambda { |_env| [ 200, {}, [] ] }
env = Rack::MockRequest.env_for("", env)
Rack::Lint.new(
ActionDispatch::RequestId.new(
Rack::Lint.new(app),
header: header,
)
).call(env)
ActionDispatch::Request.new(env)
end
end
@ -75,7 +84,9 @@ def with_test_route_set(header: "X-Request-Id")
end
@app = self.class.build_app(set) do |middleware|
middleware.use Rack::Lint
middleware.use ActionDispatch::RequestId, header: header
middleware.use Rack::Lint
end
yield