Merge branch 'master' into origin-3381-job-progress-bar-bug
[arvados.git] / services / api / test / functional / arvados / v1 / keep_disks_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::KeepDisksControllerTest < ActionController::TestCase
4
5   test "add keep disk with admin token" do
6     authorize_with :admin
7     post :ping, {
8       ping_secret: '',          # required by discovery doc, but ignored
9       filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f'
10     }
11     assert_response :success
12     assert_not_nil assigns(:object)
13     new_keep_disk = JSON.parse(@response.body)
14     assert_not_nil new_keep_disk['uuid']
15     assert_not_nil new_keep_disk['ping_secret']
16     assert_not_equal '', new_keep_disk['ping_secret']
17   end
18
19   [
20     {ping_secret: ''},
21     {ping_secret: '', filesystem_uuid: ''},
22   ].each do |opts|
23     test "add keep disk with no filesystem_uuid #{opts}" do
24       authorize_with :admin
25       post :ping, opts
26       assert_response :success
27       assert_not_nil JSON.parse(@response.body)['uuid']
28     end
29   end
30
31   test "refuse to add keep disk without admin token" do
32     post :ping, {
33       ping_secret: '',
34     }
35     assert_response 404
36   end
37
38   test "ping keep disk" do
39     post :ping, {
40       id: keep_disks(:nonfull).uuid,
41       ping_secret: keep_disks(:nonfull).ping_secret,
42       filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
43     }
44     assert_response :success
45     assert_not_nil assigns(:object)
46     keep_disk = JSON.parse(@response.body)
47     assert_not_nil keep_disk['uuid']
48     assert_not_nil keep_disk['ping_secret']
49   end
50
51   test "admin should get index with ping_secret" do
52     authorize_with :admin
53     get :index
54     assert_response :success
55     assert_not_nil assigns(:objects)
56     items = JSON.parse(@response.body)['items']
57     assert_not_equal 0, items.size
58     assert_not_nil items[0]['ping_secret']
59   end
60
61   # inactive user sees keep disks
62   test "inactive user should get index" do
63     authorize_with :inactive
64     get :index
65     assert_response :success
66     items = JSON.parse(@response.body)['items']
67     assert_not_equal 0, items.size
68
69     # Check these are still included
70     assert items[0]['service_host']
71     assert items[0]['service_port']
72   end
73
74   # active user sees non-secret attributes of keep disks
75   test "active user should get non-empty index with no ping_secret" do
76     authorize_with :active
77     get :index
78     assert_response :success
79     items = JSON.parse(@response.body)['items']
80     assert_not_equal 0, items.size
81     items.each do |item|
82       assert_nil item['ping_secret']
83       assert_not_nil item['is_readable']
84       assert_not_nil item['is_writable']
85       assert_not_nil item['service_host']
86       assert_not_nil item['service_port']
87     end
88   end
89
90   test "search keep_services with 'any' operator" do
91     authorize_with :active
92     get :index, {
93       where: { any: ['contains', 'o2t1q5w'] }
94     }
95     assert_response :success
96     found = assigns(:objects).collect(&:uuid)
97     assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')
98   end
99
100
101 end