3 class Arvados::V1::UsersControllerTest < ActionController::TestCase
4 include CurrentApiClient
7 @all_links_at_start = Link.all
8 @vm_uuid = virtual_machines(:testvm).uuid
11 test "activate a user after signing UA" do
12 authorize_with :inactive_but_signed_user_agreement
14 assert_response :success
15 me = JSON.parse(@response.body)
16 post :activate, uuid: me['uuid']
17 assert_response :success
18 assert_not_nil assigns(:object)
19 me = JSON.parse(@response.body)
20 assert_equal true, me['is_active']
23 test "refuse to activate a user before signing UA" do
24 authorize_with :inactive
26 assert_response :success
27 me = JSON.parse(@response.body)
28 post :activate, uuid: me['uuid']
31 assert_response :success
32 me = JSON.parse(@response.body)
33 assert_equal false, me['is_active']
36 test "activate an already-active user" do
37 authorize_with :active
39 assert_response :success
40 me = JSON.parse(@response.body)
41 post :activate, uuid: me['uuid']
42 assert_response :success
43 me = JSON.parse(@response.body)
44 assert_equal true, me['is_active']
47 test "create new user with user as input" do
50 first_name: "test_first_name",
51 last_name: "test_last_name",
52 email: "foo@example.com"
54 assert_response :success
55 created = JSON.parse(@response.body)
56 assert_equal 'test_first_name', created['first_name']
57 assert_not_nil created['uuid'], 'expected uuid for the newly created user'
58 assert_not_nil created['email'], 'expected non-nil email'
59 assert_nil created['identity_url'], 'expected no identity_url'
62 test "create user with user, vm and repo as input" do
64 repo_name = 'test_repo'
68 openid_prefix: 'https://www.google.com/accounts/o8/id',
70 uuid: 'zzzzz-tpzed-abcdefghijklmno',
71 first_name: "in_create_test_first_name",
72 last_name: "test_last_name",
73 email: "foo@example.com"
76 assert_response :success
77 response_items = JSON.parse(@response.body)['items']
79 created = find_obj_in_resp response_items, 'User', nil
81 assert_equal 'in_create_test_first_name', created['first_name']
82 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
83 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
84 assert_not_nil created['email'], 'expected non-nil email'
85 assert_nil created['identity_url'], 'expected no identity_url'
87 # arvados#user, repo link and link add user to 'All users' group
88 verify_num_links @all_links_at_start, 4
90 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
91 created['uuid'], created['email'], 'arvados#user', false, 'User'
93 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
94 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
96 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
97 'All users', created['uuid'], 'arvados#group', true, 'Group'
99 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
100 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
102 verify_system_group_permission_link_for created['uuid']
104 # invoke setup again with the same data
106 repo_name: repo_name,
108 openid_prefix: 'https://www.google.com/accounts/o8/id',
110 uuid: 'zzzzz-tpzed-abcdefghijklmno',
111 first_name: "in_create_test_first_name",
112 last_name: "test_last_name",
113 email: "foo@example.com"
117 response_items = JSON.parse(@response.body)['items']
119 created = find_obj_in_resp response_items, 'User', nil
120 assert_equal 'in_create_test_first_name', created['first_name']
121 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
122 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
123 assert_not_nil created['email'], 'expected non-nil email'
124 assert_nil created['identity_url'], 'expected no identity_url'
126 # arvados#user, repo link and link add user to 'All users' group
127 verify_num_links @all_links_at_start, 5
129 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
130 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
132 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
133 'All users', created['uuid'], 'arvados#group', true, 'Group'
135 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
136 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
138 verify_system_group_permission_link_for created['uuid']
141 test "setup user with bogus uuid and expect error" do
142 authorize_with :admin
146 repo_name: 'test_repo',
149 response_body = JSON.parse(@response.body)
150 response_errors = response_body['errors']
151 assert_not_nil response_errors, 'Expected error in response'
152 assert (response_errors.first.include? 'Path not found'), 'Expected 404'
155 test "setup user with bogus uuid in user and expect error" do
156 authorize_with :admin
159 user: {uuid: 'bogus_uuid'},
160 repo_name: 'test_repo',
162 openid_prefix: 'https://www.google.com/accounts/o8/id'
164 response_body = JSON.parse(@response.body)
165 response_errors = response_body['errors']
166 assert_not_nil response_errors, 'Expected error in response'
167 assert (response_errors.first.include? 'ArgumentError: Require user email'),
168 'Expected RuntimeError'
171 test "setup user with no uuid and user, expect error" do
172 authorize_with :admin
175 repo_name: 'test_repo',
177 openid_prefix: 'https://www.google.com/accounts/o8/id'
179 response_body = JSON.parse(@response.body)
180 response_errors = response_body['errors']
181 assert_not_nil response_errors, 'Expected error in response'
182 assert (response_errors.first.include? 'Required uuid or user'),
183 'Expected ArgumentError'
186 test "setup user with no uuid and email, expect error" do
187 authorize_with :admin
191 repo_name: 'test_repo',
193 openid_prefix: 'https://www.google.com/accounts/o8/id'
195 response_body = JSON.parse(@response.body)
196 response_errors = response_body['errors']
197 assert_not_nil response_errors, 'Expected error in response'
198 assert (response_errors.first.include? '<ArgumentError: Require user email'),
199 'Expected ArgumentError'
202 test "invoke setup with existing uuid, vm and repo and verify links" do
203 authorize_with :inactive
205 assert_response :success
206 inactive_user = JSON.parse(@response.body)
208 authorize_with :admin
211 uuid: inactive_user['uuid'],
212 repo_name: 'test_repo',
216 assert_response :success
218 response_items = JSON.parse(@response.body)['items']
219 resp_obj = find_obj_in_resp response_items, 'User', nil
221 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
222 assert_equal inactive_user['uuid'], resp_obj['uuid']
223 assert_equal inactive_user['email'], resp_obj['email'],
224 'expecting inactive user email'
226 # expect repo and vm links
227 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
228 'test_repo', resp_obj['uuid'], 'arvados#repository', true, 'Repository'
230 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
231 @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
234 test "invoke setup with existing uuid in user, verify response" do
235 authorize_with :inactive
237 assert_response :success
238 inactive_user = JSON.parse(@response.body)
240 authorize_with :admin
243 user: {uuid: inactive_user['uuid']},
244 openid_prefix: 'https://www.google.com/accounts/o8/id'
247 assert_response :success
249 response_items = JSON.parse(@response.body)['items']
250 resp_obj = find_obj_in_resp response_items, 'User', nil
252 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
253 assert_equal inactive_user['uuid'], resp_obj['uuid']
254 assert_equal inactive_user['email'], resp_obj['email'],
255 'expecting inactive user email'
258 test "invoke setup with existing uuid but different email, expect original email" do
259 authorize_with :inactive
261 assert_response :success
262 inactive_user = JSON.parse(@response.body)
264 authorize_with :admin
267 uuid: inactive_user['uuid'],
268 user: {email: 'junk_email'}
271 assert_response :success
273 response_items = JSON.parse(@response.body)['items']
274 resp_obj = find_obj_in_resp response_items, 'User', nil
276 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
277 assert_equal inactive_user['uuid'], resp_obj['uuid']
278 assert_equal inactive_user['email'], resp_obj['email'],
279 'expecting inactive user email'
282 test "setup user with valid email and repo as input" do
283 authorize_with :admin
286 repo_name: 'test_repo',
287 user: {email: 'foo@example.com'},
288 openid_prefix: 'https://www.google.com/accounts/o8/id'
291 assert_response :success
292 response_items = JSON.parse(@response.body)['items']
293 response_object = find_obj_in_resp response_items, 'User', nil
294 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
295 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
297 # four extra links; system_group, login, group and repo perms
298 verify_num_links @all_links_at_start, 4
301 test "setup user with fake vm and expect error" do
302 authorize_with :admin
305 repo_name: 'test_repo',
306 vm_uuid: 'no_such_vm',
307 user: {email: 'foo@example.com'},
308 openid_prefix: 'https://www.google.com/accounts/o8/id'
311 response_body = JSON.parse(@response.body)
312 response_errors = response_body['errors']
313 assert_not_nil response_errors, 'Expected error in response'
314 assert (response_errors.first.include? "No vm found for no_such_vm"),
315 'Expected RuntimeError: No vm found for no_such_vm'
318 test "setup user with valid email, repo and real vm as input" do
319 authorize_with :admin
322 repo_name: 'test_repo',
323 openid_prefix: 'https://www.google.com/accounts/o8/id',
325 user: {email: 'foo@example.com'}
328 assert_response :success
329 response_items = JSON.parse(@response.body)['items']
330 response_object = find_obj_in_resp response_items, 'User', nil
331 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
332 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
334 # five extra links; system_group, login, group, vm, repo
335 verify_num_links @all_links_at_start, 5
338 test "setup user with valid email, no vm and repo as input" do
339 authorize_with :admin
342 user: {email: 'foo@example.com'},
343 openid_prefix: 'https://www.google.com/accounts/o8/id'
346 assert_response :success
347 response_items = JSON.parse(@response.body)['items']
348 response_object = find_obj_in_resp response_items, 'User', nil
349 assert_not_nil response_object['uuid'], 'expected uuid for new user'
350 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
352 # three extra links; system_group, login, and group
353 verify_num_links @all_links_at_start, 3
356 test "setup user with email, first name, repo name and vm uuid" do
357 authorize_with :admin
360 openid_prefix: 'https://www.google.com/accounts/o8/id',
361 repo_name: 'test_repo',
364 first_name: 'test_first_name',
365 email: 'foo@example.com'
369 assert_response :success
370 response_items = JSON.parse(@response.body)['items']
371 response_object = find_obj_in_resp response_items, 'User', nil
372 assert_not_nil response_object['uuid'], 'expected uuid for new user'
373 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
374 assert_equal 'test_first_name', response_object['first_name'],
375 'expecting first name'
377 # five extra links; system_group, login, group, repo and vm
378 verify_num_links @all_links_at_start, 5
381 test "setup user twice with email and check two different objects created" do
382 authorize_with :admin
385 openid_prefix: 'https://www.google.com/accounts/o8/id',
386 repo_name: 'test_repo',
388 email: 'foo@example.com'
392 assert_response :success
393 response_items = JSON.parse(@response.body)['items']
394 response_object = find_obj_in_resp response_items, 'User', nil
395 assert_not_nil response_object['uuid'], 'expected uuid for new user'
396 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
397 # system_group, openid, group, and repo. No vm link.
398 verify_num_links @all_links_at_start, 4
402 user: {email: 'foo@example.com'},
403 openid_prefix: 'https://www.google.com/accounts/o8/id'
406 assert_response :success
407 response_items = JSON.parse(@response.body)['items']
408 response_object2 = find_obj_in_resp response_items, 'User', nil
409 assert_not_equal response_object['uuid'], response_object2['uuid'],
410 'expected same uuid as first create operation'
411 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
413 # +1 extra login link +1 extra system_group link pointing to the new User
414 verify_num_links @all_links_at_start, 6
417 test "setup user with openid prefix" do
418 authorize_with :admin
421 repo_name: 'test_repo',
422 openid_prefix: 'http://www.example.com/account',
424 first_name: "in_create_test_first_name",
425 last_name: "test_last_name",
426 email: "foo@example.com"
430 assert_response :success
432 response_items = JSON.parse(@response.body)['items']
433 created = find_obj_in_resp response_items, 'User', nil
435 assert_equal 'in_create_test_first_name', created['first_name']
436 assert_not_nil created['uuid'], 'expected uuid for new user'
437 assert_not_nil created['email'], 'expected non-nil email'
438 assert_nil created['identity_url'], 'expected no identity_url'
441 # four new links: system_group, arvados#user, repo, and 'All users' group.
442 verify_num_links @all_links_at_start, 4
444 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
445 created['uuid'], created['email'], 'arvados#user', false, 'User'
447 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
448 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
450 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
451 'All users', created['uuid'], 'arvados#group', true, 'Group'
453 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
454 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
457 test "invoke setup with no openid prefix, expect error" do
458 authorize_with :admin
461 repo_name: 'test_repo',
463 first_name: "in_create_test_first_name",
464 last_name: "test_last_name",
465 email: "foo@example.com"
469 response_body = JSON.parse(@response.body)
470 response_errors = response_body['errors']
471 assert_not_nil response_errors, 'Expected error in response'
472 assert (response_errors.first.include? 'openid_prefix parameter is missing'),
473 'Expected ArgumentError'
476 test "setup user with user, vm and repo and verify links" do
477 authorize_with :admin
481 first_name: "in_create_test_first_name",
482 last_name: "test_last_name",
483 email: "foo@example.com"
486 repo_name: 'test_repo',
487 openid_prefix: 'https://www.google.com/accounts/o8/id'
490 assert_response :success
492 response_items = JSON.parse(@response.body)['items']
493 created = find_obj_in_resp response_items, 'User', nil
495 assert_equal 'in_create_test_first_name', created['first_name']
496 assert_not_nil created['uuid'], 'expected uuid for new user'
497 assert_not_nil created['email'], 'expected non-nil email'
498 assert_nil created['identity_url'], 'expected no identity_url'
500 # five new links: system_group, arvados#user, repo, vm and 'All
502 verify_num_links @all_links_at_start, 5
504 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
505 created['uuid'], created['email'], 'arvados#user', false, 'User'
507 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
508 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
510 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
511 'All users', created['uuid'], 'arvados#group', true, 'Group'
513 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
514 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
517 test "create user as non admin user and expect error" do
518 authorize_with :active
521 user: {email: 'foo@example.com'}
524 response_body = JSON.parse(@response.body)
525 response_errors = response_body['errors']
526 assert_not_nil response_errors, 'Expected error in response'
527 assert (response_errors.first.include? 'PermissionDenied'),
528 'Expected PermissionDeniedError'
531 test "setup user as non admin user and expect error" do
532 authorize_with :active
535 openid_prefix: 'https://www.google.com/accounts/o8/id',
536 user: {email: 'foo@example.com'}
539 response_body = JSON.parse(@response.body)
540 response_errors = response_body['errors']
541 assert_not_nil response_errors, 'Expected error in response'
542 assert (response_errors.first.include? 'Forbidden'),
543 'Expected Forbidden error'
546 test "setup user in multiple steps and verify response" do
547 authorize_with :admin
550 openid_prefix: 'http://www.example.com/account',
552 email: "foo@example.com"
556 assert_response :success
557 response_items = JSON.parse(@response.body)['items']
558 created = find_obj_in_resp response_items, 'User', nil
560 assert_not_nil created['uuid'], 'expected uuid for new user'
561 assert_not_nil created['email'], 'expected non-nil email'
562 assert_equal created['email'], 'foo@example.com', 'expected input email'
564 # three new links: system_group, arvados#user, and 'All users' group.
565 verify_num_links @all_links_at_start, 3
567 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
568 created['uuid'], created['email'], 'arvados#user', false, 'User'
570 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
571 'All users', created['uuid'], 'arvados#group', true, 'Group'
573 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
574 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
576 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
577 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
579 # invoke setup with a repository
581 openid_prefix: 'http://www.example.com/account',
582 repo_name: 'new_repo',
583 uuid: created['uuid']
586 assert_response :success
588 response_items = JSON.parse(@response.body)['items']
589 created = find_obj_in_resp response_items, 'User', nil
591 assert_equal 'foo@example.com', created['email'], 'expected input email'
594 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
595 'All users', created['uuid'], 'arvados#group', true, 'Group'
597 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
598 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
600 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
601 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
603 # invoke setup with a vm_uuid
606 openid_prefix: 'http://www.example.com/account',
610 uuid: created['uuid']
613 assert_response :success
615 response_items = JSON.parse(@response.body)['items']
616 created = find_obj_in_resp response_items, 'User', nil
618 assert_equal created['email'], 'foo@example.com', 'expected original email'
621 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
622 'All users', created['uuid'], 'arvados#group', true, 'Group'
624 # since no repo name in input, we won't get any; even though user has one
625 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
626 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
628 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
629 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
632 test "setup and unsetup user" do
633 authorize_with :admin
636 repo_name: 'test_repo',
638 user: {email: 'foo@example.com'},
639 openid_prefix: 'https://www.google.com/accounts/o8/id'
642 assert_response :success
643 response_items = JSON.parse(@response.body)['items']
644 created = find_obj_in_resp response_items, 'User', nil
645 assert_not_nil created['uuid'], 'expected uuid for the new user'
646 assert_equal created['email'], 'foo@example.com', 'expected given email'
648 # five extra links: system_group, login, group, repo and vm
649 verify_num_links @all_links_at_start, 5
651 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
652 created['uuid'], created['email'], 'arvados#user', false, 'User'
654 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
655 'All users', created['uuid'], 'arvados#group', true, 'Group'
657 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
658 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
660 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
661 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
663 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
665 # now unsetup this user
666 post :unsetup, uuid: created['uuid']
667 assert_response :success
669 created2 = JSON.parse(@response.body)
670 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
671 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
673 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
676 test "unsetup active user" do
677 authorize_with :active
679 assert_response :success
680 active_user = JSON.parse(@response.body)
681 assert_not_nil active_user['uuid'], 'expected uuid for the active user'
682 assert active_user['is_active'], 'expected is_active for active user'
683 assert active_user['is_invited'], 'expected is_invited for active user'
685 verify_link_existence active_user['uuid'], active_user['email'],
686 false, false, false, true, true
688 authorize_with :admin
690 # now unsetup this user
691 post :unsetup, uuid: active_user['uuid']
692 assert_response :success
694 response_user = JSON.parse(@response.body)
695 assert_not_nil response_user['uuid'], 'expected uuid for the upsetup user'
696 assert_equal active_user['uuid'], response_user['uuid'], 'expected uuid not found'
697 assert !response_user['is_active'], 'expected user to be inactive'
698 assert !response_user['is_invited'], 'expected user to be uninvited'
700 verify_link_existence response_user['uuid'], response_user['email'],
701 false, false, false, false, false
704 test "setup user with send notification param false and verify no email" do
705 authorize_with :admin
708 openid_prefix: 'http://www.example.com/account',
709 send_notification_email: 'false',
711 email: "foo@example.com"
715 assert_response :success
716 response_items = JSON.parse(@response.body)['items']
717 created = find_obj_in_resp response_items, 'User', nil
718 assert_not_nil created['uuid'], 'expected uuid for the new user'
719 assert_equal created['email'], 'foo@example.com', 'expected given email'
721 setup_email = ActionMailer::Base.deliveries.last
722 assert_nil setup_email, 'expected no setup email'
725 test "setup user with send notification param true and verify email" do
726 authorize_with :admin
729 openid_prefix: 'http://www.example.com/account',
730 send_notification_email: 'true',
732 email: "foo@example.com"
736 assert_response :success
737 response_items = JSON.parse(@response.body)['items']
738 created = find_obj_in_resp response_items, 'User', nil
739 assert_not_nil created['uuid'], 'expected uuid for the new user'
740 assert_equal created['email'], 'foo@example.com', 'expected given email'
742 setup_email = ActionMailer::Base.deliveries.last
743 assert_not_nil setup_email, 'Expected email after setup'
745 assert_equal Rails.configuration.user_notifier_email_from, setup_email.from[0]
746 assert_equal 'foo@example.com', setup_email.to[0]
747 assert_equal 'Welcome to Curoverse', setup_email.subject
748 assert (setup_email.body.to_s.include? 'Your Arvados account has been set up'),
749 'Expected Your Arvados account has been set up in email body'
750 assert (setup_email.body.to_s.include? 'foo@example.com'),
751 'Expected user email in email body'
752 assert (setup_email.body.to_s.include? Rails.configuration.workbench_address),
753 'Expected workbench url in email body'
756 def verify_num_links (original_links, expected_additional_links)
758 assert_equal expected_additional_links, Link.all.size-original_links.size,
759 "Expected #{expected_additional_links.inspect} more links"
762 def find_obj_in_resp (response_items, object_type, head_kind=nil)
764 response_items.each { |x|
769 if object_type == 'User'
770 if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
774 else # looking for a link
775 if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
784 def verify_link(response_items, link_object_name, expect_link, link_class,
785 link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
787 link = find_obj_in_resp response_items, 'Link', link_object_name
790 assert_nil link, "Expected no link for #{link_object_name}"
794 assert_not_nil link, "Expected link for #{link_object_name}"
797 object = Object.const_get(class_name).where(name: head_uuid)
798 assert [] != object, "expected #{class_name} with name #{head_uuid}"
799 head_uuid = object.first[:uuid]
801 assert_equal link_class, link['link_class'],
802 "did not find expected link_class for #{link_object_name}"
804 assert_equal link_name, link['name'],
805 "did not find expected link_name for #{link_object_name}"
807 assert_equal tail_uuid, link['tail_uuid'],
808 "did not find expected tail_uuid for #{link_object_name}"
810 assert_equal head_kind, link['head_kind'],
811 "did not find expected head_kind for #{link_object_name}"
813 assert_equal head_uuid, link['head_uuid'],
814 "did not find expected head_uuid for #{link_object_name}"
817 def verify_link_existence uuid, email, expect_oid_login_perms,
818 expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
819 # verify that all links are deleted for the user
820 oid_login_perms = Link.where(tail_uuid: email,
821 link_class: 'permission',
822 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
823 if expect_oid_login_perms
824 assert oid_login_perms.any?, "expected oid_login_perms"
826 assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
829 repo_perms = Link.where(tail_uuid: uuid,
830 link_class: 'permission',
831 name: 'can_write').where("head_uuid like ?", Repository.uuid_like_pattern)
833 assert repo_perms.any?, "expected repo_perms"
835 assert !repo_perms.any?, "expected all repo_perms deleted"
838 vm_login_perms = Link.where(tail_uuid: uuid,
839 link_class: 'permission',
840 name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
842 assert vm_login_perms.any?, "expected vm_login_perms"
844 assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
847 group = Group.where(name: 'All users').select do |g|
848 g[:uuid].match /-f+$/
850 group_read_perms = Link.where(tail_uuid: uuid,
851 head_uuid: group[:uuid],
852 link_class: 'permission',
854 if expect_group_perms
855 assert group_read_perms.any?, "expected all users group read perms"
857 assert !group_read_perms.any?, "expected all users group perm deleted"
860 signed_uuids = Link.where(link_class: 'signature',
864 assert signed_uuids.any?, "expected signatures"
866 assert !signed_uuids.any?, "expected all signatures deleted"
871 def verify_system_group_permission_link_for user_uuid
872 assert_equal 1, Link.where(link_class: 'permission',
874 tail_uuid: system_group_uuid,
875 head_uuid: user_uuid).count