1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ApplicationControllerTest < ActionController::TestCase
8 BAD_UUID = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
15 # These tests are meant to check behavior in ApplicationController.
16 # We instantiate a small concrete controller for convenience.
17 @controller = Arvados::V1::SpecimensController.new
18 @start_stamp = now_timestamp
22 token = json_response['error_token']
24 token_time = token.split('+', 2).first.to_i
25 assert_operator(token_time, :>=, @start_stamp, "error token too old")
26 assert_operator(token_time, :<=, now_timestamp, "error token too new")
29 def check_404(errmsg="Path not found")
31 assert_equal([errmsg], json_response['errors'])
35 test "requesting nonexistent object returns 404 error" do
37 get(:show, id: BAD_UUID)
41 test "requesting object without read permission returns 404 error" do
42 authorize_with :spectator
43 get(:show, id: specimens(:owned_by_active_user).uuid)
47 test "submitting bad object returns error" do
48 authorize_with :spectator
49 post(:create, specimen: {badattr: "badvalue"})
54 test "X-Request-Id header" do
55 authorize_with :spectator
57 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
60 # The response header is the one that gets logged, so this test also
61 # ensures we log the ID supplied in the request, if any.
62 test "X-Request-Id given by client" do
63 authorize_with :spectator
64 @request.headers['X-Request-Id'] = 'abcdefG'
66 assert_equal 'abcdefG', response.headers['X-Request-Id']
69 test "X-Request-Id given by client is ignored if too long" do
70 authorize_with :spectator
71 @request.headers['X-Request-Id'] = 'abcdefG' * 1000
73 assert_match /^req-[0-9a-zA-Z]{20}$/, response.headers['X-Request-Id']
76 ['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus|
77 test "bogus boolean parameter #{bogus.inspect} returns error" do
78 @controller = Arvados::V1::GroupsController.new
79 authorize_with :active
82 ensure_unique_name: bogus
85 assert_match(/parameter must be a boolean/, json_response['errors'].first,
86 'Helpful error message not found')
90 [[true, [true, 'true', 1, '1']],
91 [false, [false, 'false', 0, '0']]].each do |bool, boolparams|
92 boolparams.each do |boolparam|
93 # Ensure boolparam is acceptable as a boolean
94 test "boolean parameter #{boolparam.inspect} acceptable" do
95 @controller = Arvados::V1::GroupsController.new
96 authorize_with :active
99 ensure_unique_name: boolparam
101 assert_response :success
104 # Ensure boolparam is acceptable as the _intended_ boolean
105 test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
106 @controller = Arvados::V1::GroupsController.new
107 authorize_with :active
110 name: groups(:aproject).name,
111 owner_uuid: groups(:aproject).owner_uuid
113 ensure_unique_name: boolparam
115 assert_response (bool ? :success : 422)