1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class HealthcheckControllerTest < ActionController::TestCase
8 reset_api_fixtures :after_each_test, false
9 reset_api_fixtures :after_suite, false
12 [false, nil, 404, 'disabled'],
13 [true, nil, 401, 'authorization required'],
14 [true, 'badformatwithnoBearer', 403, 'authorization error'],
15 [true, 'Bearer wrongtoken', 403, 'authorization error'],
16 [true, 'Bearer configuredmanagementtoken', 200, '{"health":"OK"}'],
17 ].each do |enabled, header, error_code, error_msg|
18 test "ping when #{if enabled then 'enabled' else 'disabled' end} with header '#{header}'" do
20 Rails.configuration.ManagementToken = 'configuredmanagementtoken'
22 Rails.configuration.ManagementToken = ""
25 @request.headers['Authorization'] = header
27 assert_response error_code
29 resp = JSON.parse(@response.body)
31 assert_equal(JSON.load('{"health":"OK"}'), resp)
33 assert_equal(resp['errors'], error_msg)