2776: Added controller and route for keep_services, fixed tests.
[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   end
71
72   # active user sees non-secret attributes of keep disks
73   test "active user should get non-empty index with no ping_secret" do
74     authorize_with :active
75     get :index
76     assert_response :success
77     items = JSON.parse(@response.body)['items']
78     assert_not_equal 0, items.size
79     items.each do |item|
80       assert_nil item['ping_secret']
81       assert_not_nil item['is_readable']
82       assert_not_nil item['is_writable']
83       assert_not_nil item['service_host']
84       assert_not_nil item['service_port']
85     end
86   end
87
88   test "search keep_services with 'any' operator" do
89     authorize_with :active
90     get :index, {
91       where: { any: ['contains', 'o2t1q5w'] }
92     }
93     assert_response :success
94     found = assigns(:objects).collect(&:uuid)
95     assert_equal true, !!found.index('zzzzz-penuu-5w2o2t1q5wy7fhn')
96   end
97
98
99 end