3 class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
5 test "add keep disk with admin token" do
8 ping_secret: '', # required by discovery doc, but ignored
11 service_ssl_flag: false,
12 filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f'
14 assert_response :success
15 assert_not_nil assigns(:object)
16 new_keep_disk = JSON.parse(@response.body)
17 assert_not_nil new_keep_disk['uuid']
18 assert_not_nil new_keep_disk['ping_secret']
19 assert_not_equal '', new_keep_disk['ping_secret']
22 test "add keep disk with no filesystem_uuid" do
28 service_ssl_flag: false
31 assert_response :success
32 assert_not_nil JSON.parse(@response.body)['uuid']
34 post :ping, opts.merge(filesystem_uuid: '')
35 assert_response :success
36 assert_not_nil JSON.parse(@response.body)['uuid']
39 test "refuse to add keep disk without admin token" do
44 service_ssl_flag: false
49 test "ping keep disk" do
51 uuid: keep_disks(:nonfull).uuid,
52 ping_secret: keep_disks(:nonfull).ping_secret,
53 filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
55 assert_response :success
56 assert_not_nil assigns(:object)
57 keep_disk = JSON.parse(@response.body)
58 assert_not_nil keep_disk['uuid']
59 assert_not_nil keep_disk['ping_secret']
62 test "admin should get index with ping_secret" do
65 assert_response :success
66 assert_not_nil assigns(:objects)
67 items = JSON.parse(@response.body)['items']
68 assert_not_equal 0, items.size
69 assert_not_nil items[0]['ping_secret']
72 # inactive user sees keep disks
73 test "inactive user should get index" do
74 authorize_with :inactive
76 assert_response :success
77 items = JSON.parse(@response.body)['items']
78 assert_not_equal 0, items.size
81 # active user sees non-secret attributes of keep disks
82 test "active user should get non-empty index with no ping_secret" do
83 authorize_with :active
85 assert_response :success
86 items = JSON.parse(@response.body)['items']
87 assert_not_equal 0, items.size
89 assert_nil item['ping_secret']
90 assert_not_nil item['is_readable']
91 assert_not_nil item['is_writable']
92 assert_not_nil item['service_host']
93 assert_not_nil item['service_port']
97 test "search keep_disks by service_port with >= query" do
98 authorize_with :active
100 filters: [['service_port', '>=', 25107]]
102 assert_response :success
103 assert_equal true, assigns(:objects).any?
106 test "search keep_disks by service_port with < query" do
107 authorize_with :active
109 filters: [['service_port', '<', 25107]]
111 assert_response :success
112 assert_equal false, assigns(:objects).any?
115 test "search keep_disks with 'any' operator" do
116 authorize_with :active
118 where: { any: ['contains', 'o2t1q5w'] }
120 assert_response :success
121 found = assigns(:objects).collect(&:uuid)
122 assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')