1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class GroupsTest < ActionDispatch::IntegrationTest
8 [[], ['replication_confirmed']].each do |orders|
9 test "results are consistent when provided orders #{orders} is incomplete" do
12 get '/arvados/v1/groups/contents',
14 id: groups(:aproject).uuid,
15 filters: [["uuid", "is_a", "arvados#collection"]].to_json,
16 orders: orders.to_json,
19 headers: auth(:active)
20 assert_response :success
22 last = json_response['items']
24 assert_equal last, json_response['items']
30 test "get all pages of group-owned objects" do
37 get "/arvados/v1/groups/contents",
39 id: groups(:aproject).uuid,
44 headers: auth(:active)
46 assert_response :success
47 assert_operator(0, :<, json_response['items'].count,
48 "items_available=#{items_available} but received 0 "\
49 "items with offset=#{offset}")
50 items_available ||= json_response['items_available']
51 assert_equal(items_available, json_response['items_available'],
52 "items_available changed between page #{offset/limit} "\
53 "and page #{1+offset/limit}")
54 json_response['items'].each do |item|
56 assert_equal(nil, uuid_received[uuid],
57 "Received '#{uuid}' again on page #{1+offset/limit}")
58 uuid_received[uuid] = true
59 owner_received[item['owner_uuid']] = true
61 assert_equal groups(:aproject).uuid, item['owner_uuid']
63 break if offset >= items_available
67 test "group contents with include trash collections" do
68 get "/arvados/v1/groups/contents",
70 include_trash: "true",
71 filters: [["uuid", "is_a", "arvados#collection"]].to_json,
74 headers: auth(:active)
78 json_response['items'].each { |c| coll_uuids << c['uuid'] }
79 assert_includes coll_uuids, collections(:foo_collection_in_aproject).uuid
80 assert_includes coll_uuids, collections(:expired_collection).uuid
83 test "group contents without trash collections" do
84 get "/arvados/v1/groups/contents",
86 filters: [["uuid", "is_a", "arvados#collection"]].to_json,
89 headers: auth(:active)
93 json_response['items'].each { |c| coll_uuids << c['uuid'] }
94 assert_includes coll_uuids, collections(:foo_collection_in_aproject).uuid
95 assert_not_includes coll_uuids, collections(:expired_collection).uuid
98 test "unsharing a project results in hiding it from previously shared user" do
99 # remove sharing link for project
100 delete "/arvados/v1/links/#{links(:share_starred_project_with_project_viewer).uuid}", headers: auth(:admin)
103 # verify that the user can no longer see the project
104 get "/arvados/v1/groups",
106 filters: [['group_class', '=', 'project']].to_json,
108 }, headers: auth(:project_viewer)
111 json_response['items'].each do |g|
112 found_projects[g['uuid']] = g
114 assert_equal false, found_projects.include?(groups(:starred_and_shared_active_user_project).uuid)
117 post "/arvados/v1/links", params: {
119 link_class: "permission",
121 head_uuid: groups(:starred_and_shared_active_user_project).uuid,
122 tail_uuid: users(:project_viewer).uuid,
124 }, headers: auth(:system_user)
126 assert_equal 'permission', json_response['link_class']
128 # verify that project_viewer user can now see shared project again
129 get "/arvados/v1/groups", params: {
130 filters: [['group_class', '=', 'project']].to_json,
132 }, headers: auth(:project_viewer)
135 json_response['items'].each do |g|
136 found_projects[g['uuid']] = g
138 assert_equal true, found_projects.include?(groups(:starred_and_shared_active_user_project).uuid)
141 test 'count none works with offset' do
143 (0..10).each do |offset|
144 get "/arvados/v1/groups/contents", params: {
145 id: groups(:aproject).uuid,
150 }, headers: auth(:active)
151 assert_response :success
152 assert_nil json_response['items_available']
153 if first_results.nil?
154 first_results = json_response['items']
156 assert_equal first_results[offset]['uuid'], json_response['items'][0]['uuid']
162 class NonTransactionalGroupsTest < ActionDispatch::IntegrationTest
163 # Transactional tests are disabled to be able to test the concurrent
164 # asynchronous permissions update feature.
165 # This is needed because nested transactions share the connection pool, so
166 # one thread is locked while trying to talk to the database, until the other
168 self.use_transactional_tests = false
171 # Explicitly reset the database after each test.
172 post '/database/reset', params: {}, headers: auth(:admin)
173 assert_response :success
176 test "create request with async=true does not defer permissions update" do
177 Rails.configuration.API.AsyncPermissionsUpdateInterval = 1 # second
178 name = "Random group #{rand(1000)}"
179 assert_equal nil, Group.find_by_name(name)
181 # Following the implementation of incremental permission updates
182 # (#16007) the async flag is now a no-op. Permission changes are
183 # visible immediately.
185 # Trigger the asynchronous permission update by using async=true parameter.
186 post "/arvados/v1/groups",
190 group_class: "project"
194 headers: auth(:active)
197 # The group exists in the database
198 assert_not_nil Group.find_by_name(name)
199 get "/arvados/v1/groups",
201 filters: [["name", "=", name]].to_json,
204 headers: auth(:active)
206 assert_equal 1, json_response['items_available']
208 # Wait a bit and try again.
210 get "/arvados/v1/groups",
212 filters: [["name", "=", name]].to_json,
215 headers: auth(:active)
217 assert_equal 1, json_response['items_available']