3ccfa055e705dd03ff80dc694d798db24fe76efc
[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       service_host: '::1',
10       service_port: 55555,
11       service_ssl_flag: false,
12       filesystem_uuid: 'eb1e77a1-db84-4193-b6e6-ca2894f67d5f'
13     }
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']
20   end
21
22   test "add keep disk with no filesystem_uuid" do
23     authorize_with :admin
24     opts = {
25       ping_secret: '',
26       service_host: '::1',
27       service_port: 55555,
28       service_ssl_flag: false
29     }
30     post :ping, opts
31     assert_response :success
32     assert_not_nil JSON.parse(@response.body)['uuid']
33
34     post :ping, opts.merge(filesystem_uuid: '')
35     assert_response :success
36     assert_not_nil JSON.parse(@response.body)['uuid']
37   end
38
39   test "refuse to add keep disk without admin token" do
40     post :ping, {
41       ping_secret: '',
42       service_host: '::1',
43       service_port: 55555,
44       service_ssl_flag: false
45     }
46     assert_response 404
47   end
48
49   test "ping keep disk" do
50     post :ping, {
51       uuid: keep_disks(:nonfull).uuid,
52       ping_secret: keep_disks(:nonfull).ping_secret,
53       filesystem_uuid: keep_disks(:nonfull).filesystem_uuid
54     }
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']
60   end
61
62   test "admin should get index with ping_secret" do
63     authorize_with :admin
64     get :index
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']
70   end
71
72   # inactive user sees keep disks
73   test "inactive user should get index" do
74     authorize_with :inactive
75     get :index
76     assert_response :success
77     items = JSON.parse(@response.body)['items']
78     assert_not_equal 0, items.size
79   end
80
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
84     get :index
85     assert_response :success
86     items = JSON.parse(@response.body)['items']
87     assert_not_equal 0, items.size
88     items.each do |item|
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']
94     end
95   end
96
97 end