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 ['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus|
55 test "bogus boolean parameter #{bogus.inspect} returns error" do
56 @controller = Arvados::V1::GroupsController.new
57 authorize_with :active
60 ensure_unique_name: bogus
63 assert_match(/parameter must be a boolean/, json_response['errors'].first,
64 'Helpful error message not found')
68 [[true, [true, 'true', 1, '1']],
69 [false, [false, 'false', 0, '0']]].each do |bool, boolparams|
70 boolparams.each do |boolparam|
71 # Ensure boolparam is acceptable as a boolean
72 test "boolean parameter #{boolparam.inspect} acceptable" do
73 @controller = Arvados::V1::GroupsController.new
74 authorize_with :active
77 ensure_unique_name: boolparam
79 assert_response :success
82 # Ensure boolparam is acceptable as the _intended_ boolean
83 test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
84 @controller = Arvados::V1::GroupsController.new
85 authorize_with :active
88 name: groups(:aproject).name,
89 owner_uuid: groups(:aproject).owner_uuid
91 ensure_unique_name: boolparam
93 assert_response (bool ? :success : 422)