Merge pull request #48805 from skipkayhil/hm-rack-lint-request-id

Add Rack::Lint to RequestId tests
This commit is contained in:
Guillermo Iguaran 2023-07-28 10:25:50 -07:00 committed by GitHub
commit 0a39604161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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