diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-10-19 12:59:33 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-10-19 12:59:33 -0500 |
commit | afde6fdd5ef3e6b0693a7e330777e85ef4cffddb (patch) | |
tree | e8cc45b642d1908a1768117eb343ee3bf99c5596 /actionpack/test | |
parent | 3a746f7c48936bac1c08dcf229c7c8fc74fdfc13 (diff) | |
download | rails-afde6fdd5ef3e6b0693a7e330777e85ef4cffddb.tar.gz rails-afde6fdd5ef3e6b0693a7e330777e85ef4cffddb.tar.bz2 rails-afde6fdd5ef3e6b0693a7e330777e85ef4cffddb.zip |
Added X-Request-Id tracking and TaggedLogging to easily log that and other production concerns
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/request_id_test.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb new file mode 100644 index 0000000000..bdadbf6644 --- /dev/null +++ b/actionpack/test/dispatch/request_id_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' + +class RequestIdTest < ActiveSupport::TestCase + test "passing on the request id from the outside" do + assert_equal "external-uu-rid", stub_request('HTTP_X_REQUEST_ID' => 'external-uu-rid').uuid + end + + test "ensure that only alphanumeric uurids are accepted" do + assert_equal "X-Hacked-HeaderStuff", stub_request('HTTP_X_REQUEST_ID' => '; X-Hacked-Header: Stuff').uuid + end + + test "ensure that 255 char limit on the request id is being enforced" do + assert_equal "X" * 255, stub_request('HTTP_X_REQUEST_ID' => 'X' * 500).uuid + end + + test "generating a request id when none is supplied" do + assert_match /\w+-\w+-\w+-\w+-\w+/, stub_request.uuid + end + + private + def stub_request(env = {}) + ActionDispatch::RequestId.new(->(env) { [ 200, env, [] ] }).call(env) + ActionDispatch::Request.new(env) + end +end + +# FIXME: Testing end-to-end doesn't seem to work +# +# class RequestIdResponseTest < ActionDispatch::IntegrationTest +# class TestController < ActionController::Base +# def index +# head :ok +# end +# end +# +# test "request id is passed all the way to the response" do +# with_test_route_set do +# get '/' +# puts @response.headers.inspect +# assert_equal "internal-uu-rid", @response.headers["X-Request-Id"] +# end +# end +# +# +# private +# def with_test_route_set +# with_routing do |set| +# set.draw do +# match ':action', to: ::RequestIdResponseTest::TestController +# end +# +# @app = self.class.build_app(set) do |middleware| +# middleware.use ActionDispatch::RequestId +# end +# +# yield +# end +# end +# end
\ No newline at end of file |