1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
10 {ping_secret: '', service_ssl_flag: false, service_port: 1234}
13 test "add keep disk with admin token" do
15 post :ping, params: default_ping_opts.
16 merge(filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f')
17 assert_response :success
18 assert_not_nil assigns(:object)
19 new_keep_disk = JSON.parse(@response.body)
20 assert_not_nil new_keep_disk['uuid']
21 assert_not_nil new_keep_disk['ping_secret']
22 assert_not_equal '', new_keep_disk['ping_secret']
27 {filesystem_uuid: ''},
29 test "add keep disk with[out] filesystem_uuid #{opts}" do
31 post :ping, params: default_ping_opts.merge(opts)
32 assert_response :success
33 assert_not_nil JSON.parse(@response.body)['uuid']
37 test "refuse to add keep disk without admin token" do
38 post :ping, params: default_ping_opts
42 test "ping keep disk" do
43 post :ping, params: default_ping_opts.
44 merge(id: keep_disks(:nonfull).uuid,
45 ping_secret: keep_disks(:nonfull).ping_secret,
46 filesystem_uuid: keep_disks(:nonfull).filesystem_uuid)
47 assert_response :success
48 assert_not_nil assigns(:object)
49 keep_disk = JSON.parse(@response.body)
50 assert_not_nil keep_disk['uuid']
51 assert_not_nil keep_disk['ping_secret']
54 test "admin should get index with ping_secret" do
57 assert_response :success
58 assert_not_nil assigns(:objects)
59 items = JSON.parse(@response.body)['items']
60 assert_not_equal 0, items.size
61 assert_not_nil items[0]['ping_secret']
64 # inactive user sees keep disks
65 test "inactive user should get index" do
66 authorize_with :inactive
68 assert_response :success
69 items = JSON.parse(@response.body)['items']
70 assert_not_equal 0, items.size
72 # Check these are still included
73 assert items[0]['service_host']
74 assert items[0]['service_port']
77 # active user sees non-secret attributes of keep disks
78 test "active user should get non-empty index with no ping_secret" do
79 authorize_with :active
81 assert_response :success
82 items = JSON.parse(@response.body)['items']
83 assert_not_equal 0, items.size
85 assert_nil item['ping_secret']
86 assert_not_nil item['is_readable']
87 assert_not_nil item['is_writable']
88 assert_not_nil item['service_host']
89 assert_not_nil item['service_port']
93 test "search keep_services with 'any' operator" do
94 authorize_with :active
96 where: { any: ['contains', 'o2t1q5w'] }
98 assert_response :success
99 found = assigns(:objects).collect(&:uuid)
100 assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')