1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ApiClientTest < ActiveSupport::TestCase
8 include CurrentApiClient
10 [true, false].each do |token_lifetime_enabled|
11 test "configured workbench is trusted when token lifetime is#{token_lifetime_enabled ? '': ' not'} enabled" do
12 Rails.configuration.Login.TokenLifetime = token_lifetime_enabled ? 8.hours : 0
13 Rails.configuration.Services.Workbench1.ExternalURL = URI("http://wb1.example.com")
14 Rails.configuration.Services.Workbench2.ExternalURL = URI("https://wb2.example.com:443")
17 [["http://wb0.example.com", false],
18 ["http://wb1.example.com", true],
19 ["http://wb2.example.com", false],
20 ["https://wb2.example.com", true],
21 ["https://wb2.example.com/", true],
22 ].each do |pfx, result|
23 a = ApiClient.create(url_prefix: pfx, is_trusted: false)
24 if token_lifetime_enabled
25 assert_equal false, a.is_trusted, "API client with url prefix '#{pfx}' shouldn't be trusted"
27 assert_equal result, a.is_trusted
31 a = ApiClient.create(url_prefix: "http://example.com", is_trusted: true)