Merge branch '2798-go-keep-client' into 1885-keep-proxy refs #1885
[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   test "add keep disk with no filesystem_uuid" do
20     authorize_with :admin
21     opts = {
22       ping_secret: '',
23     }
24     post :ping, opts
25     assert_response :success
26     assert_not_nil JSON.parse(@response.body)['uuid']
27
28     post :ping, opts.merge(filesystem_uuid: '')
29     assert_response :success
30     assert_not_nil JSON.parse(@response.body)['uuid']
31   end
32
33   test "refuse to add keep disk without admin token" do
34     post :ping, {
35       ping_secret: '',
36     }
37     assert_response 404
38   end
39
40   test "ping keep disk" do
41     post :ping, {
42       id: keep_disks(:nonfull).uuid,
43       ping_secret: keep_disks(:nonfull).ping_secret,
44       filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
45     }
46     assert_response :success
47     assert_not_nil assigns(:object)
48     keep_disk = JSON.parse(@response.body)
49     assert_not_nil keep_disk['uuid']
50     assert_not_nil keep_disk['ping_secret']
51   end
52
53   test "admin should get index with ping_secret" do
54     authorize_with :admin
55     get :index
56     assert_response :success
57     assert_not_nil assigns(:objects)
58     items = JSON.parse(@response.body)['items']
59     assert_not_equal 0, items.size
60     assert_not_nil items[0]['ping_secret']
61   end
62
63   # inactive user sees keep disks
64   test "inactive user should get index" do
65     authorize_with :inactive
66     get :index
67     assert_response :success
68     items = JSON.parse(@response.body)['items']
69     assert_not_equal 0, items.size
70
71     # Check these are still included
72     assert items[0]['service_host']
73     assert items[0]['service_port']
74   end
75
76   # active user sees non-secret attributes of keep disks
77   test "active user should get non-empty index with no ping_secret" do
78     authorize_with :active
79     get :index
80     assert_response :success
81     items = JSON.parse(@response.body)['items']
82     assert_not_equal 0, items.size
83     items.each do |item|
84       assert_nil item['ping_secret']
85       assert_not_nil item['is_readable']
86       assert_not_nil item['is_writable']
87       assert_not_nil item['service_host']
88       assert_not_nil item['service_port']
89     end
90   end
91
92   test "search keep_services with 'any' operator" do
93     authorize_with :active
94     get :index, {
95       where: { any: ['contains', 'o2t1q5w'] }
96     }
97     assert_response :success
98     found = assigns(:objects).collect(&:uuid)
99     assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')
100   end
101
102
103 end