X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b64a7596b2fb456de13aa885dbe14a817fd8d5b2..b896832bf02ded0c9142d758c2866fa4f1ec09e9:/services/api/test/integration/errors_test.rb diff --git a/services/api/test/integration/errors_test.rb b/services/api/test/integration/errors_test.rb index 04843adcf7..8e9929117b 100644 --- a/services/api/test/integration/errors_test.rb +++ b/services/api/test/integration/errors_test.rb @@ -24,16 +24,35 @@ class ErrorsTest < ActionDispatch::IntegrationTest # Generally, new routes should appear under /arvados/v1/. If # they appear elsewhere, that might have been caused by default # rails generator behavior that we don't want. - assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|database\/reset|discovery\/.*|static\/.*|themes\/.*|assets|_health\/.*)(\(\.:format\))?$/, + assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|database\/reset|discovery\/.*|static\/.*|sys\/trash_sweep|themes\/.*|assets|_health\/.*|metrics)(\(\.:format\))?$/, route.path.spec.to_s, "Unexpected new route: #{route.path.spec}") end end - test "X-Request-Id header format on non-existant object URL" do + test "X-Request-Id header" do + get "/", headers: auth(:spectator) + assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id'] + end + + test "X-Request-Id header on non-existant object URL" do get "/arvados/v1/container_requests/invalid", params: {:format => :json}, headers: auth(:active) assert_response 404 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id'] end + + # The response header is the one that gets logged, so this test also + # ensures we log the ID supplied in the request, if any. + test "X-Request-Id given by client" do + get "/", headers: auth(:spectator).merge({'X-Request-Id': 'abcdefG'}) + assert_equal 'abcdefG', response.headers['X-Request-Id'] + end + + test "X-Request-Id given by client is ignored if too long" do + authorize_with :spectator + long_reqId = 'abcdefG' * 1000 + get "/", headers: auth(:spectator).merge({'X-Request-Id': long_reqId}) + assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id'] + end end