Skip to content

Commit

Permalink
Merge pull request #48805 from skipkayhil/hm-rack-lint-request-id
Browse files Browse the repository at this point in the history
Add Rack::Lint to RequestId tests
  • Loading branch information
guilleiguaran committed Jul 28, 2023
2 parents 0e5a99d + b2da005 commit 0a39604
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions actionpack/test/dispatch/request_id_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0a39604

Please sign in to comment.