CWL spec -> CWL standards
[arvados.git] / services / api / test / functional / arvados / v1 / keep_services_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class Arvados::V1::KeepServicesControllerTest < ActionController::TestCase
8
9   test "search by service_port with < query" do
10     authorize_with :active
11     get :index, params: {
12       filters: [['service_port', '<', 25107]]
13     }
14     assert_response :success
15     assert_equal false, assigns(:objects).any?
16   end
17
18   test "search by service_port with >= query" do
19     authorize_with :active
20     get :index, params: {
21       filters: [['service_port', '>=', 25107]]
22     }
23     assert_response :success
24     assert_equal true, assigns(:objects).any?
25   end
26
27   [:admin, :active, :inactive, :anonymous, nil].each do |u|
28     test "accessible to #{u.inspect} user" do
29       authorize_with(u) if u
30       get :accessible
31       assert_response :success
32       assert_not_empty json_response['items']
33       json_response['items'].each do |ks|
34         assert_not_equal ks['service_type'], 'proxy'
35       end
36     end
37   end
38
39   test "report configured servers if db is empty" do
40     KeepService.unscoped.all.delete_all
41     expect_rvz = {}
42     n = 0
43     Rails.configuration.Services.Keepstore.InternalURLs.each do |k,v|
44       n += 1
45       rvz = "%015x" % n
46       expect_rvz[k.to_s] = rvz
47       Rails.configuration.Services.Keepstore.InternalURLs[k].Rendezvous = rvz
48     end
49     expect_rvz[Rails.configuration.Services.Keepproxy.ExternalURL] = true
50     refute_empty expect_rvz
51     authorize_with :active
52     get :index,
53       params: {:format => :json},
54       headers: auth(:active)
55     assert_response :success
56     json_response['items'].each do |svc|
57       url = "#{svc['service_ssl_flag'] ? 'https' : 'http'}://#{svc['service_host']}:#{svc['service_port']}"
58       assert_equal true, expect_rvz.has_key?(url), "#{url} does not match any configured service: expecting #{expect_rvz}"
59       rvz = expect_rvz[url]
60       if rvz.is_a? String
61         assert_equal "zzzzz-bi6l4-#{rvz}", svc['uuid'], "exported service UUID should match InternalURLs.*.Rendezvous value"
62       end
63       expect_rvz.delete(url)
64     end
65     assert_equal({}, expect_rvz, "all configured Keepstore and Keepproxy services should be returned")
66   end
67
68 end