1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::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
17 Rails.configuration.ManagementToken = 'configuredmanagementtoken'
19 Rails.configuration.ManagementToken = ""
22 @request.headers['Authorization'] = header
24 assert_response error_code
26 resp = JSON.parse(@response.body)
28 assert_equal(JSON.load('{"health":"OK"}'), resp)
30 assert_equal(error_msg, resp['errors'])