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', 'in', ['project', 'folder']]], format: :json
20 assert_response :success
22 json_response['items'].each do |group|
23 assert_includes ['folder', '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', '=', nil]], format: :json
35 assert_response :success
37 json_response['items'].each do |group|
38 assert_equal nil, 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,
80 check_project_contents_response
83 test "user with project read permission can see project objects" do
84 authorize_with :project_viewer
86 id: groups(:aproject).uuid,
90 check_project_contents_response
93 [false, true].each do |include_linked|
94 test "list objects across projects, include_linked=#{include_linked}" do
95 authorize_with :project_viewer
98 include_linked: include_linked,
99 filters: [['uuid', 'is_a', 'arvados#specimen']]
101 assert_response :success
102 found_uuids = json_response['items'].collect { |i| i['uuid'] }
103 [[:in_aproject, true],
104 [:in_asubproject, true],
105 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
107 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
109 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
114 test "user with project read permission can see project collections" do
115 authorize_with :project_viewer
117 id: groups(:asubproject).uuid,
119 include_linked: true,
121 ids = json_response['items'].map { |item| item["uuid"] }
122 assert_includes ids, collections(:baz_file).uuid
125 test 'list objects across multiple projects' do
126 authorize_with :project_viewer
129 include_linked: false,
130 filters: [['uuid', 'is_a', 'arvados#specimen']]
132 assert_response :success
133 found_uuids = json_response['items'].collect { |i| i['uuid'] }
134 [[:in_aproject, true],
135 [:in_asubproject, true],
136 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
138 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
140 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
145 # Even though the project_viewer tests go through other controllers,
146 # I'm putting them here so they're easy to find alongside the other
148 def check_new_project_link_fails(link_attrs)
149 @controller = Arvados::V1::LinksController.new
150 post :create, link: {
151 link_class: "permission",
153 head_uuid: groups(:aproject).uuid,
155 assert_includes(403..422, response.status)
158 test "user with project read permission can't add users to it" do
159 authorize_with :project_viewer
160 check_new_project_link_fails(tail_uuid: users(:spectator).uuid)
163 test "user with project read permission can't add items to it" do
164 authorize_with :project_viewer
165 check_new_project_link_fails(tail_uuid: collections(:baz_file).uuid)
168 test "user with project read permission can't rename items in it" do
169 authorize_with :project_viewer
170 @controller = Arvados::V1::LinksController.new
172 id: links(:job_name_in_aproject).uuid,
173 link: {name: "Denied test name"},
175 assert_includes(403..404, response.status)
178 test "user with project read permission can't remove items from it" do
179 @controller = Arvados::V1::PipelineTemplatesController.new
180 authorize_with :project_viewer
182 id: links(:template_name_in_aproject).head_uuid,
184 owner_uuid: users(:project_viewer).uuid,
190 test "user with project read permission can't delete it" do
191 authorize_with :project_viewer
192 post :destroy, {id: groups(:aproject).uuid}
196 test 'get group-owned objects with limit' do
197 authorize_with :active
199 id: groups(:aproject).uuid,
203 assert_response :success
204 assert_operator 1, :<, json_response['items_available']
205 assert_equal 1, json_response['items'].count
208 test 'get group-owned objects with limit and offset' do
209 authorize_with :active
211 id: groups(:aproject).uuid,
216 assert_response :success
217 assert_operator 1, :<, json_response['items_available']
218 assert_equal 0, json_response['items'].count
221 test 'get group-owned objects with additional filter matching nothing' do
222 authorize_with :active
224 id: groups(:aproject).uuid,
225 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
228 assert_response :success
229 assert_equal [], json_response['items']
230 assert_equal 0, json_response['items_available']
233 test 'get group-owned objects without include_linked' do
234 unexpected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
235 authorize_with :active
237 id: groups(:asubproject).uuid,
240 assert_response :success
241 uuids = json_response['items'].collect { |i| i['uuid'] }
242 assert_equal nil, uuids.index(unexpected_uuid)
245 test 'get group-owned objects with include_linked' do
246 expected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
247 authorize_with :active
249 id: groups(:asubproject).uuid,
250 include_linked: true,
253 assert_response :success
254 uuids = json_response['items'].collect { |i| i['uuid'] }
255 assert_includes uuids, expected_uuid, "Did not get #{expected_uuid}"
257 expected_name = links(:specimen_is_in_two_projects).name
258 found_specimen_name = false
259 assert(json_response['links'].any?,
260 "Expected a non-empty array of links in response")
261 json_response['links'].each do |link|
262 if link['head_uuid'] == expected_uuid
263 if link['name'] == expected_name
264 found_specimen_name = true
268 assert(found_specimen_name,
269 "Expected to find name '#{expected_name}' in response")
272 [false, true].each do |inc_ind|
273 test "get all pages of group-owned #{'and -linked ' if inc_ind}objects" do
274 authorize_with :active
277 items_available = nil
281 # Behaving badly here, using the same controller multiple
282 # times within a test.
285 id: groups(:aproject).uuid,
286 include_linked: inc_ind,
291 assert_response :success
292 assert_operator(0, :<, json_response['items'].count,
293 "items_available=#{items_available} but received 0 "\
294 "items with offset=#{offset}")
295 items_available ||= json_response['items_available']
296 assert_equal(items_available, json_response['items_available'],
297 "items_available changed between page #{offset/limit} "\
298 "and page #{1+offset/limit}")
299 json_response['items'].each do |item|
301 assert_equal(nil, uuid_received[uuid],
302 "Received '#{uuid}' again on page #{1+offset/limit}")
303 uuid_received[uuid] = true
304 owner_received[item['owner_uuid']] = true
307 assert_equal groups(:aproject).uuid, item['owner_uuid']
310 break if offset >= items_available
313 assert_operator 0, :<, (json_response.keys - [users(:active).uuid]).count,
314 "Set include_linked=true but did not receive any non-owned items"
319 %w(offset limit).each do |arg|
320 ['foo', '', '1234five', '0x10', '-8'].each do |val|
321 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
322 authorize_with :active
324 :id => groups(:aproject).uuid,
333 test 'get writable_by list for owned group' do
334 authorize_with :active
336 id: groups(:aproject).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'], users(:active).uuid,
343 "owner should be included in writable_by list")
346 test 'no writable_by list for group with read-only access' do
347 authorize_with :rominiadmin
349 id: groups(:testusergroup_admins).uuid,
352 assert_response :success
353 assert_nil(json_response['writable_by'],
354 "Should not receive uuid list in 'writable_by' field")
357 test 'get writable_by list by admin user' do
358 authorize_with :admin
360 id: groups(:testusergroup_admins).uuid,
363 assert_response :success
364 assert_not_nil(json_response['writable_by'],
365 "Should receive uuid list in 'writable_by' field")
366 assert_includes(json_response['writable_by'],
368 "Current user should be included in 'writable_by' field")