X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/afb710394b65fc82da8e4edd024a3a5fc1a18d54..f170c5a75f22a6db11ca93eed5b0dfc9c65c4270:/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 142455880d..e3224f4912 100644 --- a/services/api/test/integration/errors_test.rb +++ b/services/api/test/integration/errors_test.rb @@ -9,11 +9,12 @@ class ErrorsTest < ActionDispatch::IntegrationTest %w(/arvados/v1/shoes /arvados/shoes /shoes /nodes /users).each do |path| test "non-existent route #{path}" do - get path, {:format => :json}, auth(:active) + get path, params: {:format => :json}, headers: auth(:active) assert_nil assigns(:objects) assert_nil assigns(:object) assert_not_nil json_response['errors'] assert_response 404 + assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id'] end end @@ -28,4 +29,30 @@ class ErrorsTest < ActionDispatch::IntegrationTest "Unexpected new route: #{route.path.spec}") end end + + 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