Removed head_kind and tail_kind from workbench.
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
4
5   test "should get index" do
6     authorize_with :active
7     get :index
8     assert_response :success
9     assert_not_nil assigns(:objects)
10   end
11
12   test "should create" do
13     authorize_with :active
14     test_collection = {
15       manifest_text: <<-EOS
16 . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
17 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
18 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
19 ./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
20 EOS
21     }
22     test_collection[:uuid] =
23       Digest::MD5.hexdigest(test_collection[:manifest_text]) +
24       '+' +
25       test_collection[:manifest_text].length.to_s
26     post :create, {
27       collection: test_collection
28     }
29     assert_response :success
30     assert_nil assigns(:objects)
31
32     get :show, {
33       id: test_collection[:uuid]
34     }
35     assert_response :success
36     assert_not_nil assigns(:object)
37     resp = JSON.parse(@response.body)
38     assert_equal test_collection[:uuid], resp['uuid']
39     assert_equal test_collection[:manifest_text], resp['manifest_text']
40     assert_equal 9, resp['data_size']
41     assert_equal [['.', 'foo.txt', 0],
42                   ['.', 'bar.txt', 6],
43                   ['./baz', 'bar.txt', 3]], resp['files']
44   end
45
46   test "list of files is correct for empty manifest" do
47     authorize_with :active
48     test_collection = {
49       manifest_text: "",
50       uuid: "d41d8cd98f00b204e9800998ecf8427e+0"
51     }
52     post :create, {
53       collection: test_collection
54     }
55     assert_response :success
56
57     get :show, {
58       id: "d41d8cd98f00b204e9800998ecf8427e+0"
59     }
60     assert_response :success
61     resp = JSON.parse(@response.body)
62     assert_equal [], resp['files']
63   end
64
65   test "create with owner_uuid set to owned group" do
66     authorize_with :active
67     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
68     post :create, {
69       collection: {
70         owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
71         manifest_text: manifest_text,
72         uuid: "d30fe8ae534397864cb96c544f4cf102"
73       }
74     }
75     assert_response :success
76     resp = JSON.parse(@response.body)
77     assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
78   end
79
80   test "create with owner_uuid set to group i can_manage" do
81     authorize_with :active
82     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
83     post :create, {
84       collection: {
85         owner_uuid: 'zzzzz-j7d0g-8ulrifv67tve5sx',
86         manifest_text: manifest_text,
87         uuid: "d30fe8ae534397864cb96c544f4cf102"
88       }
89     }
90     assert_response :success
91     resp = JSON.parse(@response.body)
92     assert_equal 'zzzzz-tpzed-000000000000000', resp['owner_uuid']
93   end
94
95   test "create with owner_uuid set to group with no can_manage permission" do
96     authorize_with :active
97     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
98     post :create, {
99       collection: {
100         owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
101         manifest_text: manifest_text,
102         uuid: "d30fe8ae534397864cb96c544f4cf102"
103       }
104     }
105     assert_response 403
106   end
107
108   test "admin create with owner_uuid set to group with no permission" do
109     authorize_with :admin
110     manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
111     post :create, {
112       collection: {
113         owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
114         manifest_text: manifest_text,
115         uuid: "d30fe8ae534397864cb96c544f4cf102"
116       }
117     }
118     assert_response :success
119   end
120
121   test "should create with collection passed as json" do
122     authorize_with :active
123     post :create, {
124       collection: <<-EOS
125       {
126         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
127         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
128       }
129       EOS
130     }
131     assert_response :success
132   end
133
134   test "should fail to create with checksum mismatch" do
135     authorize_with :active
136     post :create, {
137       collection: <<-EOS
138       {
139         "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
140         "uuid":"d30fe8ae534397864cb96c544f4cf102"\
141       }
142       EOS
143     }
144     assert_response 422
145   end
146
147   test "get full provenance for baz file" do
148     authorize_with :active
149     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
150     assert_response :success
151     resp = JSON.parse(@response.body)
152     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
153     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
154     assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
155     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
156     assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
157   end
158
159   test "get no provenance for foo file" do
160     # spectator user cannot even see baz collection
161     authorize_with :spectator
162     get :provenance, uuid: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
163     assert_response 404
164   end
165
166   test "get partial provenance for baz file" do
167     # spectator user can see bar->baz job, but not foo->bar job
168     authorize_with :spectator
169     get :provenance, uuid: 'ea10d51bcf88862dbcc36eb292017dfd+45'
170     assert_response :success
171     resp = JSON.parse(@response.body)
172     assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
173     assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
174     assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq']     # bar->baz
175     assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon']         # foo->bar
176     assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
177   end
178
179 end