3 class Arvados::V1::GroupsControllerTest < ActionController::TestCase
5 test "attempt to delete group without read or write access" do
7 post :destroy, id: groups(:empty_lonely_group).uuid
11 test "attempt to delete group without write access" do
12 authorize_with :active
13 post :destroy, id: groups(:all_users).uuid
17 test "get list of projects" do
18 authorize_with :active
19 get :index, filters: [['group_class', '=', 'project']], format: :json
20 assert_response :success
22 json_response['items'].each do |group|
23 assert_equal 'project', group['group_class']
24 group_uuids << group['uuid']
26 assert_includes group_uuids, groups(:aproject).uuid
27 assert_includes group_uuids, groups(:asubproject).uuid
28 assert_not_includes group_uuids, groups(:system_group).uuid
29 assert_not_includes group_uuids, groups(:private).uuid
32 test "get list of groups that are not projects" do
33 authorize_with :active
34 get :index, filters: [['group_class', '!=', 'project']], format: :json
35 assert_response :success
37 json_response['items'].each do |group|
38 assert_not_equal 'project', group['group_class']
39 group_uuids << group['uuid']
41 assert_not_includes group_uuids, groups(:aproject).uuid
42 assert_not_includes group_uuids, groups(:asubproject).uuid
43 assert_includes group_uuids, groups(:private).uuid
46 test "get list of groups with bogus group_class" do
47 authorize_with :active
49 filters: [['group_class', '=', 'nogrouphasthislittleclass']],
52 assert_response :success
53 assert_equal [], json_response['items']
54 assert_equal 0, json_response['items_available']
57 def check_project_contents_response
58 assert_response :success
59 assert_operator 2, :<=, json_response['items_available']
60 assert_operator 2, :<=, json_response['items'].count
61 kinds = json_response['items'].collect { |i| i['kind'] }.uniq
62 expect_kinds = %w'arvados#group arvados#specimen arvados#pipelineTemplate arvados#job'
63 assert_equal expect_kinds, (expect_kinds & kinds)
65 json_response['items'].each do |i|
66 if i['kind'] == 'arvados#group'
67 assert(i['group_class'] == 'project',
68 "group#contents returned a non-project group")
73 test 'get group-owned objects' do
74 authorize_with :active
76 id: groups(:aproject).uuid,
79 check_project_contents_response
82 test "user with project read permission can see project objects" do
83 authorize_with :project_viewer
85 id: groups(:aproject).uuid,
88 check_project_contents_response
91 test "list objects across projects" do
92 authorize_with :project_viewer
95 filters: [['uuid', 'is_a', 'arvados#specimen']]
97 assert_response :success
98 found_uuids = json_response['items'].collect { |i| i['uuid'] }
99 [[:in_aproject, true],
100 [:in_asubproject, true],
101 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
103 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
105 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
110 test "list objects in home project" do
111 authorize_with :active
114 id: users(:active).uuid
116 assert_response :success
117 found_uuids = json_response['items'].collect { |i| i['uuid'] }
118 assert_includes found_uuids, specimens(:owned_by_active_user).uuid, "specimen did not appear in home project"
119 refute_includes found_uuids, specimens(:in_asubproject).uuid, "specimen appeared unexpectedly in home project"
122 test "user with project read permission can see project collections" do
123 authorize_with :project_viewer
125 id: groups(:asubproject).uuid,
128 ids = json_response['items'].map { |item| item["uuid"] }
129 assert_includes ids, collections(:baz_file_in_asubproject).uuid
133 ['desc', :>=]].each do |order, operator|
134 test "user with project read permission can sort project collections #{order}" do
135 authorize_with :project_viewer
137 id: groups(:asubproject).uuid,
139 filters: [['uuid', 'is_a', "arvados#collection"]],
140 order: "collections.name #{order}"
142 sorted_names = json_response['items'].collect { |item| item["name"] }
143 # Here we avoid assuming too much about the database
144 # collation. Both "alice"<"Bob" and "alice">"Bob" can be
145 # correct. Hopefully it _is_ safe to assume that if "a" comes
146 # before "b" in the ascii alphabet, "aX">"bY" is never true for
147 # any strings X and Y.
148 reliably_sortable_names = sorted_names.select do |name|
149 name[0] >= 'a' and name[0] <= 'z'
153 # Preserve order of sorted_names. But do not use &=. If
154 # sorted_names has out-of-order duplicates, we want to preserve
155 # them here, so we can detect them and fail the test below.
156 sorted_names.select! do |name|
157 reliably_sortable_names.include? name
159 actually_checked_anything = false
161 sorted_names.each do |entry|
163 assert_operator(previous, operator, entry,
164 "Entries sorted incorrectly.")
165 actually_checked_anything = true
169 assert actually_checked_anything, "Didn't even find two names to compare."
173 test 'list objects across multiple projects' do
174 authorize_with :project_viewer
177 filters: [['uuid', 'is_a', 'arvados#specimen']]
179 assert_response :success
180 found_uuids = json_response['items'].collect { |i| i['uuid'] }
181 [[:in_aproject, true],
182 [:in_asubproject, true],
183 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
185 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
187 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
192 # Even though the project_viewer tests go through other controllers,
193 # I'm putting them here so they're easy to find alongside the other
195 def check_new_project_link_fails(link_attrs)
196 @controller = Arvados::V1::LinksController.new
197 post :create, link: {
198 link_class: "permission",
200 head_uuid: groups(:aproject).uuid,
202 assert_includes(403..422, response.status)
205 test "user with project read permission can't add users to it" do
206 authorize_with :project_viewer
207 check_new_project_link_fails(tail_uuid: users(:spectator).uuid)
210 test "user with project read permission can't add items to it" do
211 authorize_with :project_viewer
212 check_new_project_link_fails(tail_uuid: collections(:baz_file).uuid)
215 test "user with project read permission can't rename items in it" do
216 authorize_with :project_viewer
217 @controller = Arvados::V1::LinksController.new
219 id: jobs(:running).uuid,
220 name: "Denied test name",
222 assert_includes(403..404, response.status)
225 test "user with project read permission can't remove items from it" do
226 @controller = Arvados::V1::PipelineTemplatesController.new
227 authorize_with :project_viewer
229 id: pipeline_templates(:two_part).uuid,
231 owner_uuid: users(:project_viewer).uuid,
237 test "user with project read permission can't delete it" do
238 authorize_with :project_viewer
239 post :destroy, {id: groups(:aproject).uuid}
243 test 'get group-owned objects with limit' do
244 authorize_with :active
246 id: groups(:aproject).uuid,
250 assert_response :success
251 assert_operator 1, :<, json_response['items_available']
252 assert_equal 1, json_response['items'].count
255 test 'get group-owned objects with limit and offset' do
256 authorize_with :active
258 id: groups(:aproject).uuid,
263 assert_response :success
264 assert_operator 1, :<, json_response['items_available']
265 assert_equal 0, json_response['items'].count
268 test 'get group-owned objects with additional filter matching nothing' do
269 authorize_with :active
271 id: groups(:aproject).uuid,
272 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
275 assert_response :success
276 assert_equal [], json_response['items']
277 assert_equal 0, json_response['items_available']
280 %w(offset limit).each do |arg|
281 ['foo', '', '1234five', '0x10', '-8'].each do |val|
282 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
283 authorize_with :active
285 :id => groups(:aproject).uuid,
294 test "Collection contents don't include manifest_text" do
295 authorize_with :active
297 id: groups(:aproject).uuid,
298 filters: [["uuid", "is_a", "arvados#collection"]],
301 assert_response :success
302 refute(json_response["items"].any? { |c| not c["portable_data_hash"] },
303 "response included an item without a portable data hash")
304 refute(json_response["items"].any? { |c| c.include?("manifest_text") },
305 "response included an item with a manifest text")
308 test 'get writable_by list for owned group' do
309 authorize_with :active
311 id: groups(:aproject).uuid,
314 assert_response :success
315 assert_not_nil(json_response['writable_by'],
316 "Should receive uuid list in 'writable_by' field")
317 assert_includes(json_response['writable_by'], users(:active).uuid,
318 "owner should be included in writable_by list")
321 test 'no writable_by list for group with read-only access' do
322 authorize_with :rominiadmin
324 id: groups(:testusergroup_admins).uuid,
327 assert_response :success
328 assert_equal([json_response['owner_uuid']],
329 json_response['writable_by'],
330 "Should only see owner_uuid in 'writable_by' field")
333 test 'get writable_by list by admin user' do
334 authorize_with :admin
336 id: groups(:testusergroup_admins).uuid,
339 assert_response :success
340 assert_not_nil(json_response['writable_by'],
341 "Should receive uuid list in 'writable_by' field")
342 assert_includes(json_response['writable_by'],
344 "Current user should be included in 'writable_by' field")
347 test 'creating subproject with duplicate name fails' do
348 authorize_with :active
352 owner_uuid: users(:active).uuid,
353 group_class: 'project',
357 response_errors = json_response['errors']
358 assert_not_nil response_errors, 'Expected error in response'
359 assert(response_errors.first.include?('duplicate key'),
360 "Expected 'duplicate key' error in #{response_errors.first}")
363 test 'creating duplicate named subproject succeeds with ensure_unique_name' do
364 authorize_with :active
368 owner_uuid: users(:active).uuid,
369 group_class: 'project',
371 ensure_unique_name: true
373 assert_response :success
374 new_project = json_response
375 assert_not_equal(new_project['uuid'],
376 groups(:aproject).uuid,
377 "create returned same uuid as existing project")
378 assert_equal(new_project['name'],
380 "new project name '#{new_project['name']}' was expected to be 'A Project (2)'")