X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/d61f56590d4c1bc2c965b640698217a5d4af1d8c..927524f1be454de021180b74999d682780b8cb6b:/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 b2ef13e1d3..a2a1545cee 100644 --- a/services/api/test/integration/errors_test.rb +++ b/services/api/test/integration/errors_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class ErrorsTest < ActionDispatch::IntegrationTest @@ -5,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 @@ -19,9 +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|discovery\/.*|static\/.*|themes\/.*)(\(\.:format\))?$/, + assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|database\/reset|discovery\/.*|static\/.*|sys\/trash_sweep|themes\/.*|assets|_health\/.*)(\(\.:format\))?$/, route.path.spec.to_s, "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