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}'"
115 # Even though the project_viewer tests go through other controllers,
116 # I'm putting them here so they're easy to find alongside the other
118 def check_new_project_link_fails(link_attrs)
119 @controller = Arvados::V1::LinksController.new
120 post :create, link: {
121 link_class: "permission",
123 head_uuid: groups(:aproject).uuid,
125 assert_includes(403..422, response.status)
128 test "user with project read permission can't add users to it" do
129 authorize_with :project_viewer
130 check_new_project_link_fails(tail_uuid: users(:spectator).uuid)
133 test "user with project read permission can't add items to it" do
134 authorize_with :project_viewer
135 check_new_project_link_fails(tail_uuid: collections(:baz_file).uuid)
138 test "user with project read permission can't rename items in it" do
139 authorize_with :project_viewer
140 @controller = Arvados::V1::LinksController.new
142 id: links(:job_name_in_aproject).uuid,
143 link: {name: "Denied test name"},
145 assert_includes(403..404, response.status)
148 test "user with project read permission can't remove items from it" do
149 @controller = Arvados::V1::PipelineTemplatesController.new
150 authorize_with :project_viewer
152 id: links(:template_name_in_aproject).head_uuid,
154 owner_uuid: users(:project_viewer).uuid,
160 test "user with project read permission can't delete it" do
161 authorize_with :project_viewer
162 post :destroy, {id: groups(:aproject).uuid}
166 test 'get group-owned objects with limit' do
167 authorize_with :active
169 id: groups(:aproject).uuid,
173 assert_response :success
174 assert_operator 1, :<, json_response['items_available']
175 assert_equal 1, json_response['items'].count
178 test 'get group-owned objects with limit and offset' do
179 authorize_with :active
181 id: groups(:aproject).uuid,
186 assert_response :success
187 assert_operator 1, :<, json_response['items_available']
188 assert_equal 0, json_response['items'].count
191 test 'get group-owned objects with additional filter matching nothing' do
192 authorize_with :active
194 id: groups(:aproject).uuid,
195 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
198 assert_response :success
199 assert_equal [], json_response['items']
200 assert_equal 0, json_response['items_available']
203 test 'get group-owned objects without include_linked' do
204 unexpected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
205 authorize_with :active
207 id: groups(:asubproject).uuid,
210 assert_response :success
211 uuids = json_response['items'].collect { |i| i['uuid'] }
212 assert_equal nil, uuids.index(unexpected_uuid)
215 test 'get group-owned objects with include_linked' do
216 expected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
217 authorize_with :active
219 id: groups(:asubproject).uuid,
220 include_linked: true,
223 assert_response :success
224 uuids = json_response['items'].collect { |i| i['uuid'] }
225 assert_includes uuids, expected_uuid, "Did not get #{expected_uuid}"
227 expected_name = links(:specimen_is_in_two_projects).name
228 found_specimen_name = false
229 assert(json_response['links'].any?,
230 "Expected a non-empty array of links in response")
231 json_response['links'].each do |link|
232 if link['head_uuid'] == expected_uuid
233 if link['name'] == expected_name
234 found_specimen_name = true
238 assert(found_specimen_name,
239 "Expected to find name '#{expected_name}' in response")
242 [false, true].each do |inc_ind|
243 test "get all pages of group-owned #{'and -linked ' if inc_ind}objects" do
244 authorize_with :active
247 items_available = nil
251 # Behaving badly here, using the same controller multiple
252 # times within a test.
255 id: groups(:aproject).uuid,
256 include_linked: inc_ind,
261 assert_response :success
262 assert_operator(0, :<, json_response['items'].count,
263 "items_available=#{items_available} but received 0 "\
264 "items with offset=#{offset}")
265 items_available ||= json_response['items_available']
266 assert_equal(items_available, json_response['items_available'],
267 "items_available changed between page #{offset/limit} "\
268 "and page #{1+offset/limit}")
269 json_response['items'].each do |item|
271 assert_equal(nil, uuid_received[uuid],
272 "Received '#{uuid}' again on page #{1+offset/limit}")
273 uuid_received[uuid] = true
274 owner_received[item['owner_uuid']] = true
277 assert_equal groups(:aproject).uuid, item['owner_uuid']
280 break if offset >= items_available
283 assert_operator 0, :<, (json_response.keys - [users(:active).uuid]).count,
284 "Set include_linked=true but did not receive any non-owned items"
289 %w(offset limit).each do |arg|
290 ['foo', '', '1234five', '0x10', '-8'].each do |val|
291 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
292 authorize_with :active
294 :id => groups(:aproject).uuid,
303 test 'get writable_by list for owned group' do
304 authorize_with :active
306 id: groups(:aproject).uuid,
309 assert_response :success
310 assert_not_nil(json_response['writable_by'],
311 "Should receive uuid list in 'writable_by' field")
312 assert_includes(json_response['writable_by'], users(:active).uuid,
313 "owner should be included in writable_by list")
316 test 'no writable_by list for group with read-only access' do
317 authorize_with :rominiadmin
319 id: groups(:testusergroup_admins).uuid,
322 assert_response :success
323 assert_nil(json_response['writable_by'],
324 "Should not receive uuid list in 'writable_by' field")
327 test 'get writable_by list by admin user' do
328 authorize_with :admin
330 id: groups(:testusergroup_admins).uuid,
333 assert_response :success
334 assert_not_nil(json_response['writable_by'],
335 "Should receive uuid list in 'writable_by' field")
336 assert_includes(json_response['writable_by'],
338 "Current user should be included in 'writable_by' field")