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
44 assert_includes group_uuids, groups(:group_with_no_class).uuid
47 test "get list of groups with bogus group_class" do
48 authorize_with :active
50 filters: [['group_class', '=', 'nogrouphasthislittleclass']],
53 assert_response :success
54 assert_equal [], json_response['items']
55 assert_equal 0, json_response['items_available']
58 def check_project_contents_response disabled_kinds=[]
59 assert_response :success
60 assert_operator 2, :<=, json_response['items_available']
61 assert_operator 2, :<=, json_response['items'].count
62 kinds = json_response['items'].collect { |i| i['kind'] }.uniq
63 expect_kinds = %w'arvados#group arvados#specimen arvados#pipelineTemplate arvados#job' - disabled_kinds
64 assert_equal expect_kinds, (expect_kinds & kinds)
66 json_response['items'].each do |i|
67 if i['kind'] == 'arvados#group'
68 assert(i['group_class'] == 'project',
69 "group#contents returned a non-project group")
73 disabled_kinds.each do |d|
74 assert_equal true, !kinds.include?(d)
78 test 'get group-owned objects' do
79 authorize_with :active
81 id: groups(:aproject).uuid,
84 check_project_contents_response
87 test "user with project read permission can see project objects" do
88 authorize_with :project_viewer
90 id: groups(:aproject).uuid,
93 check_project_contents_response
96 test "list objects across projects" do
97 authorize_with :project_viewer
100 filters: [['uuid', 'is_a', 'arvados#specimen']]
102 assert_response :success
103 found_uuids = json_response['items'].collect { |i| i['uuid'] }
104 [[:in_aproject, true],
105 [:in_asubproject, true],
106 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
108 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
110 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
115 test "list objects in home project" do
116 authorize_with :active
119 id: users(:active).uuid
121 assert_response :success
122 found_uuids = json_response['items'].collect { |i| i['uuid'] }
123 assert_includes found_uuids, specimens(:owned_by_active_user).uuid, "specimen did not appear in home project"
124 refute_includes found_uuids, specimens(:in_asubproject).uuid, "specimen appeared unexpectedly in home project"
127 test "user with project read permission can see project collections" do
128 authorize_with :project_viewer
130 id: groups(:asubproject).uuid,
133 ids = json_response['items'].map { |item| item["uuid"] }
134 assert_includes ids, collections(:baz_file_in_asubproject).uuid
138 ['desc', :>=]].each do |order, operator|
139 test "user with project read permission can sort project collections #{order}" do
140 authorize_with :project_viewer
142 id: groups(:asubproject).uuid,
144 filters: [['uuid', 'is_a', "arvados#collection"]],
145 order: "collections.name #{order}"
147 sorted_names = json_response['items'].collect { |item| item["name"] }
148 # Here we avoid assuming too much about the database
149 # collation. Both "alice"<"Bob" and "alice">"Bob" can be
150 # correct. Hopefully it _is_ safe to assume that if "a" comes
151 # before "b" in the ascii alphabet, "aX">"bY" is never true for
152 # any strings X and Y.
153 reliably_sortable_names = sorted_names.select do |name|
154 name[0] >= 'a' and name[0] <= 'z'
158 # Preserve order of sorted_names. But do not use &=. If
159 # sorted_names has out-of-order duplicates, we want to preserve
160 # them here, so we can detect them and fail the test below.
161 sorted_names.select! do |name|
162 reliably_sortable_names.include? name
164 actually_checked_anything = false
166 sorted_names.each do |entry|
168 assert_operator(previous, operator, entry,
169 "Entries sorted incorrectly.")
170 actually_checked_anything = true
174 assert actually_checked_anything, "Didn't even find two names to compare."
178 test 'list objects across multiple projects' do
179 authorize_with :project_viewer
182 filters: [['uuid', 'is_a', 'arvados#specimen']]
184 assert_response :success
185 found_uuids = json_response['items'].collect { |i| i['uuid'] }
186 [[:in_aproject, true],
187 [:in_asubproject, true],
188 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
190 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
192 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
197 # Even though the project_viewer tests go through other controllers,
198 # I'm putting them here so they're easy to find alongside the other
200 def check_new_project_link_fails(link_attrs)
201 @controller = Arvados::V1::LinksController.new
202 post :create, link: {
203 link_class: "permission",
205 head_uuid: groups(:aproject).uuid,
207 assert_includes(403..422, response.status)
210 test "user with project read permission can't add users to it" do
211 authorize_with :project_viewer
212 check_new_project_link_fails(tail_uuid: users(:spectator).uuid)
215 test "user with project read permission can't add items to it" do
216 authorize_with :project_viewer
217 check_new_project_link_fails(tail_uuid: collections(:baz_file).uuid)
220 test "user with project read permission can't rename items in it" do
221 authorize_with :project_viewer
222 @controller = Arvados::V1::LinksController.new
224 id: jobs(:running).uuid,
225 name: "Denied test name",
227 assert_includes(403..404, response.status)
230 test "user with project read permission can't remove items from it" do
231 @controller = Arvados::V1::PipelineTemplatesController.new
232 authorize_with :project_viewer
234 id: pipeline_templates(:two_part).uuid,
236 owner_uuid: users(:project_viewer).uuid,
242 test "user with project read permission can't delete it" do
243 authorize_with :project_viewer
244 post :destroy, {id: groups(:aproject).uuid}
248 test 'get group-owned objects with limit' do
249 authorize_with :active
251 id: groups(:aproject).uuid,
255 assert_response :success
256 assert_operator 1, :<, json_response['items_available']
257 assert_equal 1, json_response['items'].count
260 test 'get group-owned objects with limit and offset' do
261 authorize_with :active
263 id: groups(:aproject).uuid,
268 assert_response :success
269 assert_operator 1, :<, json_response['items_available']
270 assert_equal 0, json_response['items'].count
273 test 'get group-owned objects with additional filter matching nothing' do
274 authorize_with :active
276 id: groups(:aproject).uuid,
277 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
280 assert_response :success
281 assert_equal [], json_response['items']
282 assert_equal 0, json_response['items_available']
285 %w(offset limit).each do |arg|
286 ['foo', '', '1234five', '0x10', '-8'].each do |val|
287 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
288 authorize_with :active
290 :id => groups(:aproject).uuid,
299 test "Collection contents don't include manifest_text" do
300 authorize_with :active
302 id: groups(:aproject).uuid,
303 filters: [["uuid", "is_a", "arvados#collection"]],
306 assert_response :success
307 refute(json_response["items"].any? { |c| not c["portable_data_hash"] },
308 "response included an item without a portable data hash")
309 refute(json_response["items"].any? { |c| c.include?("manifest_text") },
310 "response included an item with a manifest text")
313 test 'get writable_by list for owned group' do
314 authorize_with :active
316 id: groups(:aproject).uuid,
319 assert_response :success
320 assert_not_nil(json_response['writable_by'],
321 "Should receive uuid list in 'writable_by' field")
322 assert_includes(json_response['writable_by'], users(:active).uuid,
323 "owner should be included in writable_by list")
326 test 'no writable_by list for group with read-only access' do
327 authorize_with :rominiadmin
329 id: groups(:testusergroup_admins).uuid,
332 assert_response :success
333 assert_equal([json_response['owner_uuid']],
334 json_response['writable_by'],
335 "Should only see owner_uuid in 'writable_by' field")
338 test 'get writable_by list by admin user' do
339 authorize_with :admin
341 id: groups(:testusergroup_admins).uuid,
344 assert_response :success
345 assert_not_nil(json_response['writable_by'],
346 "Should receive uuid list in 'writable_by' field")
347 assert_includes(json_response['writable_by'],
349 "Current user should be included in 'writable_by' field")
352 test 'creating subproject with duplicate name fails' do
353 authorize_with :active
357 owner_uuid: users(:active).uuid,
358 group_class: 'project',
362 response_errors = json_response['errors']
363 assert_not_nil response_errors, 'Expected error in response'
364 assert(response_errors.first.include?('duplicate key'),
365 "Expected 'duplicate key' error in #{response_errors.first}")
368 test 'creating duplicate named subproject succeeds with ensure_unique_name' do
369 authorize_with :active
373 owner_uuid: users(:active).uuid,
374 group_class: 'project',
376 ensure_unique_name: true
378 assert_response :success
379 new_project = json_response
380 assert_not_equal(new_project['uuid'],
381 groups(:aproject).uuid,
382 "create returned same uuid as existing project")
383 assert_match(/^A Project \(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z\)$/,
387 test "unsharing a project results in hiding it from previously shared user" do
388 # remove sharing link for project
389 @controller = Arvados::V1::LinksController.new
390 authorize_with :admin
391 post :destroy, id: links(:share_starred_project_with_project_viewer).uuid
392 assert_response :success
394 # verify that the user can no longer see the project
395 @test_counter = 0 # Reset executed action counter
396 @controller = Arvados::V1::GroupsController.new
397 authorize_with :project_viewer
398 get :index, filters: [['group_class', '=', 'project']], format: :json
399 assert_response :success
401 json_response['items'].each do |g|
402 found_projects[g['uuid']] = g
404 assert_equal false, found_projects.include?(groups(:starred_and_shared_active_user_project).uuid)
408 @controller = Arvados::V1::LinksController.new
409 authorize_with :system_user
410 post :create, link: {
411 link_class: "permission",
413 head_uuid: groups(:starred_and_shared_active_user_project).uuid,
414 tail_uuid: users(:project_viewer).uuid,
417 # verify that project_viewer user can now see shared project again
419 @controller = Arvados::V1::GroupsController.new
420 authorize_with :project_viewer
421 get :index, filters: [['group_class', '=', 'project']], format: :json
422 assert_response :success
424 json_response['items'].each do |g|
425 found_projects[g['uuid']] = g
427 assert_equal true, found_projects.include?(groups(:starred_and_shared_active_user_project).uuid)
431 [['owner_uuid', '!=', 'zzzzz-tpzed-xurymjxw79nv3jz'], 200,
432 'zzzzz-d1hrv-subprojpipeline', 'zzzzz-d1hrv-1xfj6xkicf2muk2'],
433 [["pipeline_instances.state", "not in", ["Complete", "Failed"]], 200,
434 'zzzzz-d1hrv-1xfj6xkicf2muk2', 'zzzzz-d1hrv-i3e77t9z5y8j9cc'],
435 [['container_requests.requesting_container_uuid', '=', nil], 200,
436 'zzzzz-xvhdp-cr4queuedcontnr', 'zzzzz-xvhdp-cr4requestercn2'],
437 [['container_requests.no_such_column', '=', nil], 422],
438 [['container_requests.', '=', nil], 422],
439 [['.requesting_container_uuid', '=', nil], 422],
440 [['no_such_table.uuid', '!=', 'zzzzz-tpzed-xurymjxw79nv3jz'], 422],
441 ].each do |filter, expect_code, expect_uuid, not_expect_uuid|
442 test "get contents with '#{filter}' filter" do
443 authorize_with :active
444 get :contents, filters: [filter], format: :json
445 assert_response expect_code
446 if expect_code == 200
447 assert_not_empty json_response['items']
448 item_uuids = json_response['items'].collect {|item| item['uuid']}
449 assert_includes(item_uuids, expect_uuid)
450 assert_not_includes(item_uuids, not_expect_uuid)
455 test 'get contents with jobs and pipeline instances disabled' do
456 Rails.configuration.disable_api_methods = ['jobs.index', 'pipeline_instances.index']
458 authorize_with :active
460 id: groups(:aproject).uuid,
463 check_project_contents_response %w'arvados#pipelineInstance arvados#job'