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