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 json_response['errors'].each do |err|
32 assert(err.include?(errmsg), "error message '#{err}' expected to include '#{errmsg}'")
37 test "requesting nonexistent object returns 404 error" do
39 get(:show, params: {id: BAD_UUID})
43 test "requesting object without read permission returns 404 error" do
44 authorize_with :spectator
45 get(:show, params: {id: specimens(:owned_by_active_user).uuid})
49 test "submitting bad object returns error" do
50 authorize_with :spectator
51 post(:create, params: {specimen: {badattr: "badvalue"}})
56 ['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus|
57 test "bogus boolean parameter #{bogus.inspect} returns error" do
58 @controller = Arvados::V1::GroupsController.new
59 authorize_with :active
60 post :create, params: {
62 ensure_unique_name: bogus
65 assert_match(/parameter must be a boolean/, json_response['errors'].first,
66 'Helpful error message not found')
70 [[true, [true, 'true', 1, '1']],
71 [false, [false, 'false', 0, '0']]].each do |bool, boolparams|
72 boolparams.each do |boolparam|
73 # Ensure boolparam is acceptable as a boolean
74 test "boolean parameter #{boolparam.inspect} acceptable" do
75 @controller = Arvados::V1::GroupsController.new
76 authorize_with :active
77 post :create, params: {
78 group: {group_class: "project"},
79 ensure_unique_name: boolparam
81 assert_response :success
84 # Ensure boolparam is acceptable as the _intended_ boolean
85 test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
86 @controller = Arvados::V1::GroupsController.new
87 authorize_with :active
88 post :create, params: {
90 name: groups(:aproject).name,
91 owner_uuid: groups(:aproject).owner_uuid,
92 group_class: "project"
94 ensure_unique_name: boolparam
96 assert_response (bool ? :success : 422)
101 test "exceptions with backtraces get logged at exception_backtrace key" do
102 Group.stubs(:new).raises(Exception, 'Whoops')
103 Rails.logger.expects(:info).with(any_parameters) do |param|
104 param.include?('Whoops') and param.include?('"exception_backtrace":')
106 @controller = Arvados::V1::GroupsController.new
107 authorize_with :active
108 post :create, params: {