1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ErrorsTest < ActionDispatch::IntegrationTest
8 fixtures :api_client_authorizations
10 %w(/arvados/v1/shoes /arvados/shoes /shoes /nodes /users).each do |path|
11 test "non-existent route #{path}" do
12 get path, params: {:format => :json}, headers: auth(:active)
13 assert_nil assigns(:objects)
14 assert_nil assigns(:object)
15 assert_not_nil json_response['errors']
17 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
22 Rails.application.routes.routes.each do |route|
23 test "route #{n += 1} '#{route.path.spec.to_s}' is not an accident" do
24 # Generally, new routes should appear under /arvados/v1/. If
25 # they appear elsewhere, that might have been caused by default
26 # rails generator behavior that we don't want.
27 assert_match(/^\/(|\*a|arvados\/v1\/.*|auth\/.*|login|logout|database\/reset|discovery\/.*|static\/.*|sys\/trash_sweep|themes\/.*|assets|_health\/.*|metrics)(\(\.:format\))?$/,
29 "Unexpected new route: #{route.path.spec}")
33 test "X-Request-Id header" do
34 get "/", headers: auth(:spectator)
35 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
38 test "X-Request-Id header on non-existant object URL" do
39 get "/arvados/v1/container_requests/invalid",
40 params: {:format => :json}, headers: auth(:active)
42 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
45 # The response header is the one that gets logged, so this test also
46 # ensures we log the ID supplied in the request, if any.
47 test "X-Request-Id given by client" do
48 get "/", headers: auth(:spectator).merge({'X-Request-Id': 'abcdefG'})
49 assert_equal 'abcdefG', response.headers['X-Request-Id']
52 test "X-Request-Id given by client is ignored if too long" do
53 authorize_with :spectator
54 long_reqId = 'abcdefG' * 1000
55 get "/", headers: auth(:spectator).merge({'X-Request-Id': long_reqId})
56 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']