3 class Arvados::V1::LinksControllerTest < ActionController::TestCase
5 test "no symbol keys in serialized hash" do
7 properties: {username: 'testusername'},
10 tail_uuid: users(:admin).uuid,
11 head_uuid: virtual_machines(:testvm).uuid
14 [link, link.to_json].each do |formatted_link|
15 post :create, link: formatted_link
16 assert_response :success
17 assert_not_nil assigns(:object)
18 assert_equal 'testusername', assigns(:object).properties['username']
19 assert_equal false, assigns(:object).properties.has_key?(:username)
23 %w(created_at modified_at).each do |attr|
24 {nil: nil, bogus: 2.days.ago}.each do |bogustype, bogusvalue|
25 test "cannot set #{bogustype} #{attr} in create" do
26 authorize_with :active
32 }.merge(attr => bogusvalue)
34 assert_response :success
35 resp = JSON.parse @response.body
36 assert_in_delta Time.now, Time.parse(resp[attr]), 3.0
38 test "cannot set #{bogustype} #{attr} in update" do
39 really_created_at = links(:test_timestamps).created_at
40 authorize_with :active
42 id: links(:test_timestamps).uuid,
44 :properties => {test: 'test'},
48 assert_response :success
49 resp = JSON.parse @response.body
52 assert_in_delta really_created_at, Time.parse(resp[attr]), 0.001
54 assert_in_delta Time.now, Time.parse(resp[attr]), 3.0
60 test "head must exist" do
64 tail_uuid: users(:active).uuid,
65 head_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
68 post :create, link: link
72 test "tail must exist" do
76 head_uuid: users(:active).uuid,
77 tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
80 post :create, link: link
84 test "head and tail exist, head_kind and tail_kind are returned" do
88 head_uuid: users(:active).uuid,
89 tail_uuid: users(:spectator).uuid,
92 post :create, link: link
93 assert_response :success
94 l = JSON.parse(@response.body)
95 assert 'arvados#user', l['head_kind']
96 assert 'arvados#user', l['tail_kind']
99 test "can supply head_kind and tail_kind without error" do
103 head_uuid: users(:active).uuid,
104 tail_uuid: users(:spectator).uuid,
105 head_kind: "arvados#user",
106 tail_kind: "arvados#user",
108 authorize_with :admin
109 post :create, link: link
110 assert_response :success
111 l = JSON.parse(@response.body)
112 assert 'arvados#user', l['head_kind']
113 assert 'arvados#user', l['tail_kind']
116 test "tail must be visible by user" do
120 head_uuid: users(:active).uuid,
121 tail_uuid: virtual_machines(:testvm).uuid
123 authorize_with :active
124 post :create, link: link
128 test "filter links with 'is_a' operator" do
129 authorize_with :admin
131 filters: [ ['tail_uuid', 'is_a', 'arvados#user'] ]
133 assert_response :success
134 found = assigns(:objects)
135 assert_not_equal 0, found.count
136 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
139 test "filter links with 'is_a' operator with more than one" do
140 authorize_with :admin
142 filters: [ ['tail_uuid', 'is_a', ['arvados#user', 'arvados#group'] ] ],
144 assert_response :success
145 found = assigns(:objects)
146 assert_not_equal 0, found.count
147 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-(tpzed|j7d0g)-[a-z0-9]{15}/}).count
150 test "filter links with 'is_a' operator with bogus type" do
151 authorize_with :admin
153 filters: [ ['tail_uuid', 'is_a', ['arvados#bogus'] ] ],
155 assert_response :success
156 found = assigns(:objects)
157 assert_equal 0, found.count
160 test "filter links with 'is_a' operator with collection" do
161 authorize_with :admin
163 filters: [ ['head_uuid', 'is_a', ['arvados#collection'] ] ],
165 assert_response :success
166 found = assigns(:objects)
167 assert_not_equal 0, found.count
168 assert_equal found.count, (found.select { |f| f.head_uuid.match /.....-4zz18-.............../}).count
171 test "test can still use where tail_kind" do
172 authorize_with :admin
174 where: { tail_kind: 'arvados#user' }
176 assert_response :success
177 found = assigns(:objects)
178 assert_not_equal 0, found.count
179 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
182 test "test can still use where head_kind" do
183 authorize_with :admin
185 where: { head_kind: 'arvados#user' }
187 assert_response :success
188 found = assigns(:objects)
189 assert_not_equal 0, found.count
190 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
193 test "test can still use filter tail_kind" do
194 authorize_with :admin
196 filters: [ ['tail_kind', '=', 'arvados#user'] ]
198 assert_response :success
199 found = assigns(:objects)
200 assert_not_equal 0, found.count
201 assert_equal found.count, (found.select { |f| f.tail_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
204 test "test can still use filter head_kind" do
205 authorize_with :admin
207 filters: [ ['head_kind', '=', 'arvados#user'] ]
209 assert_response :success
210 found = assigns(:objects)
211 assert_not_equal 0, found.count
212 assert_equal found.count, (found.select { |f| f.head_uuid.match /[a-z0-9]{5}-tpzed-[a-z0-9]{15}/}).count
215 test "head_kind matches head_uuid" do
219 head_uuid: groups(:public).uuid,
220 head_kind: "arvados#user",
221 tail_uuid: users(:spectator).uuid,
222 tail_kind: "arvados#user",
224 authorize_with :admin
225 post :create, link: link
229 test "tail_kind matches tail_uuid" do
233 head_uuid: users(:active).uuid,
234 head_kind: "arvados#user",
235 tail_uuid: groups(:public).uuid,
236 tail_kind: "arvados#user",
238 authorize_with :admin
239 post :create, link: link
243 test "test with virtual_machine" do
245 tail_kind: "arvados#user",
246 tail_uuid: users(:active).uuid,
247 head_kind: "arvados#virtual_machine",
248 head_uuid: virtual_machines(:testvm).uuid,
249 link_class: "permission",
251 properties: {username: "repo_and_user_name"}
253 authorize_with :admin
254 post :create, link: link
258 test "test with virtualMachine" do
260 tail_kind: "arvados#user",
261 tail_uuid: users(:active).uuid,
262 head_kind: "arvados#virtualMachine",
263 head_uuid: virtual_machines(:testvm).uuid,
264 link_class: "permission",
266 properties: {username: "repo_and_user_name"}
268 authorize_with :admin
269 post :create, link: link
270 assert_response :success
273 test "project owner can show a project permission" do
274 uuid = links(:project_viewer_can_read_project).uuid
275 authorize_with :active
277 assert_response :success
278 assert_equal(uuid, assigns(:object).andand.uuid)
281 test "admin can show a project permission" do
282 uuid = links(:project_viewer_can_read_project).uuid
283 authorize_with :admin
285 assert_response :success
286 assert_equal(uuid, assigns(:object).andand.uuid)
289 test "project viewer can't show others' project permissions" do
290 authorize_with :project_viewer
291 get :show, id: links(:admin_can_write_aproject).uuid
295 test "requesting a nonexistent link returns 404" do
296 authorize_with :active
297 get :show, id: 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
301 test "project owner can index project permissions" do
302 skip "Test tickles known bug"
303 # readable_by only lets users see permission links that relate to them
304 # directly. It does not allow users to see permission links for groups
306 # We'd like to fix this general issue, but we haven't settled on a general
307 # way to do it that doesn't involve making readable_by ridiculously hairy.
308 # This test demonstrates the desired behavior once we're ready to tackle
309 # it. In the meantime, clients should use /permissions to get this
311 authorize_with :active
312 get :index, filters: [['link_class', '=', 'permission'],
313 ['head_uuid', '=', groups(:aproject).uuid]]
314 assert_response :success
315 assert_not_nil assigns(:objects)
316 assert_includes(assigns(:objects).map(&:uuid),
317 links(:project_viewer_can_read_project).uuid)
320 test "admin can index project permissions" do
321 authorize_with :admin
322 get :index, filters: [['link_class', '=', 'permission'],
323 ['head_uuid', '=', groups(:aproject).uuid]]
324 assert_response :success
325 assert_not_nil assigns(:objects)
326 assert_includes(assigns(:objects).map(&:uuid),
327 links(:project_viewer_can_read_project).uuid)
330 test "project viewer can't index others' project permissions" do
331 authorize_with :project_viewer
332 get :index, filters: [['link_class', '=', 'permission'],
333 ['head_uuid', '=', groups(:aproject).uuid],
334 ['tail_uuid', '!=', users(:project_viewer).uuid]]
335 assert_response :success
336 assert_not_nil assigns(:objects)
337 assert_empty assigns(:objects)