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)
66 test 'get group-owned objects' do
67 authorize_with :active
69 id: groups(:aproject).uuid,
73 check_project_contents_response
76 test "user with project read permission can see project objects" do
77 authorize_with :project_viewer
79 id: groups(:aproject).uuid,
83 check_project_contents_response
86 test 'list objects across multiple projects' do
87 authorize_with :project_viewer
90 include_linked: false,
91 filters: [['uuid', 'is_a', 'arvados#specimen']]
93 assert_response :success
94 found_uuids = json_response['items'].collect { |i| i['uuid'] }
95 [[:in_aproject, true],
96 [:in_asubproject, true],
97 [:owned_by_private_group, false]].each do |specimen_fixture, should_find|
99 assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'"
101 refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'"
106 # Even though the project_viewer tests go through other controllers,
107 # I'm putting them here so they're easy to find alongside the other
109 def check_new_project_link_fails(link_attrs)
110 @controller = Arvados::V1::LinksController.new
111 post :create, link: {
112 link_class: "permission",
114 head_uuid: groups(:aproject).uuid,
116 assert_includes(403..422, response.status)
119 test "user with project read permission can't add users to it" do
120 authorize_with :project_viewer
121 check_new_project_link_fails(tail_uuid: users(:spectator).uuid)
124 test "user with project read permission can't add items to it" do
125 authorize_with :project_viewer
126 check_new_project_link_fails(tail_uuid: collections(:baz_file).uuid)
129 test "user with project read permission can't rename items in it" do
130 authorize_with :project_viewer
131 @controller = Arvados::V1::LinksController.new
133 id: links(:job_name_in_aproject).uuid,
134 link: {name: "Denied test name"},
136 assert_includes(403..404, response.status)
139 test "user with project read permission can't remove items from it" do
140 @controller = Arvados::V1::PipelineTemplatesController.new
141 authorize_with :project_viewer
143 id: links(:template_name_in_aproject).head_uuid,
145 owner_uuid: users(:project_viewer).uuid,
151 test "user with project read permission can't delete it" do
152 authorize_with :project_viewer
153 post :destroy, {id: groups(:aproject).uuid}
157 test 'get group-owned objects with limit' do
158 authorize_with :active
160 id: groups(:aproject).uuid,
164 assert_response :success
165 assert_operator 1, :<, json_response['items_available']
166 assert_equal 1, json_response['items'].count
169 test 'get group-owned objects with limit and offset' do
170 authorize_with :active
172 id: groups(:aproject).uuid,
177 assert_response :success
178 assert_operator 1, :<, json_response['items_available']
179 assert_equal 0, json_response['items'].count
182 test 'get group-owned objects with additional filter matching nothing' do
183 authorize_with :active
185 id: groups(:aproject).uuid,
186 filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
189 assert_response :success
190 assert_equal [], json_response['items']
191 assert_equal 0, json_response['items_available']
194 test 'get group-owned objects without include_linked' do
195 unexpected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
196 authorize_with :active
198 id: groups(:asubproject).uuid,
201 assert_response :success
202 uuids = json_response['items'].collect { |i| i['uuid'] }
203 assert_equal nil, uuids.index(unexpected_uuid)
206 test 'get group-owned objects with include_linked' do
207 expected_uuid = specimens(:in_aproject_linked_from_asubproject).uuid
208 authorize_with :active
210 id: groups(:asubproject).uuid,
211 include_linked: true,
214 assert_response :success
215 uuids = json_response['items'].collect { |i| i['uuid'] }
216 assert_includes uuids, expected_uuid, "Did not get #{expected_uuid}"
218 expected_name = links(:specimen_is_in_two_projects).name
219 found_specimen_name = false
220 assert(json_response['links'].any?,
221 "Expected a non-empty array of links in response")
222 json_response['links'].each do |link|
223 if link['head_uuid'] == expected_uuid
224 if link['name'] == expected_name
225 found_specimen_name = true
229 assert(found_specimen_name,
230 "Expected to find name '#{expected_name}' in response")
233 [false, true].each do |inc_ind|
234 test "get all pages of group-owned #{'and -linked ' if inc_ind}objects" do
235 authorize_with :active
238 items_available = nil
242 # Behaving badly here, using the same controller multiple
243 # times within a test.
246 id: groups(:aproject).uuid,
247 include_linked: inc_ind,
252 assert_response :success
253 assert_operator(0, :<, json_response['items'].count,
254 "items_available=#{items_available} but received 0 "\
255 "items with offset=#{offset}")
256 items_available ||= json_response['items_available']
257 assert_equal(items_available, json_response['items_available'],
258 "items_available changed between page #{offset/limit} "\
259 "and page #{1+offset/limit}")
260 json_response['items'].each do |item|
262 assert_equal(nil, uuid_received[uuid],
263 "Received '#{uuid}' again on page #{1+offset/limit}")
264 uuid_received[uuid] = true
265 owner_received[item['owner_uuid']] = true
268 assert_equal groups(:aproject).uuid, item['owner_uuid']
271 break if offset >= items_available
274 assert_operator 0, :<, (json_response.keys - [users(:active).uuid]).count,
275 "Set include_linked=true but did not receive any non-owned items"
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 'get writable_by list for owned group' do
295 authorize_with :active
297 id: groups(:aproject).uuid,
300 assert_response :success
301 assert_not_nil(json_response['writable_by'],
302 "Should receive uuid list in 'writable_by' field")
303 assert_includes(json_response['writable_by'], users(:active).uuid,
304 "owner should be included in writable_by list")
307 test 'no writable_by list for group with read-only access' do
308 authorize_with :rominiadmin
310 id: groups(:testusergroup_admins).uuid,
313 assert_response :success
314 assert_nil(json_response['writable_by'],
315 "Should not receive uuid list in 'writable_by' field")
318 test 'get writable_by list by admin user' do
319 authorize_with :admin
321 id: groups(:testusergroup_admins).uuid,
324 assert_response :success
325 assert_not_nil(json_response['writable_by'],
326 "Should receive uuid list in 'writable_by' field")
327 assert_includes(json_response['writable_by'],
329 "Current user should be included in 'writable_by' field")