X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/96fe9fc822c2270cb6e4212798d61e61481ec2e0..9f57bcbab5b244365ca4d0ece8490d7540c72b86:/services/api/test/functional/application_controller_test.rb diff --git a/services/api/test/functional/application_controller_test.rb b/services/api/test/functional/application_controller_test.rb index 4144d0a922..27b046e3c2 100644 --- a/services/api/test/functional/application_controller_test.rb +++ b/services/api/test/functional/application_controller_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class ApplicationControllerTest < ActionController::TestCase @@ -46,4 +50,70 @@ class ApplicationControllerTest < ActionController::TestCase assert_response 422 check_error_token end + + test "X-Request-Id header" do + authorize_with :spectator + get(:index) + 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 + authorize_with :spectator + @request.headers['X-Request-Id'] = 'abcdefG' + get(:index) + 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 + @request.headers['X-Request-Id'] = 'abcdefG' * 1000 + get(:index) + assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id'] + end + + ['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus| + test "bogus boolean parameter #{bogus.inspect} returns error" do + @controller = Arvados::V1::GroupsController.new + authorize_with :active + post :create, { + group: {}, + ensure_unique_name: bogus + } + assert_response 422 + assert_match(/parameter must be a boolean/, json_response['errors'].first, + 'Helpful error message not found') + end + end + + [[true, [true, 'true', 1, '1']], + [false, [false, 'false', 0, '0']]].each do |bool, boolparams| + boolparams.each do |boolparam| + # Ensure boolparam is acceptable as a boolean + test "boolean parameter #{boolparam.inspect} acceptable" do + @controller = Arvados::V1::GroupsController.new + authorize_with :active + post :create, { + group: {}, + ensure_unique_name: boolparam + } + assert_response :success + end + + # Ensure boolparam is acceptable as the _intended_ boolean + test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do + @controller = Arvados::V1::GroupsController.new + authorize_with :active + post :create, { + group: { + name: groups(:aproject).name, + owner_uuid: groups(:aproject).owner_uuid + }, + ensure_unique_name: boolparam + } + assert_response (bool ? :success : 422) + end + end + end end