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