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 "respond 401 if given token exists but user record is missing" do
48 authorize_with :valid_token_deleted_user
49 get :current, {format: :json}
53 test "create new user with user as input" do
56 first_name: "test_first_name",
57 last_name: "test_last_name",
58 email: "foo@example.com"
60 assert_response :success
61 created = JSON.parse(@response.body)
62 assert_equal 'test_first_name', created['first_name']
63 assert_not_nil created['uuid'], 'expected uuid for the newly created user'
64 assert_not_nil created['email'], 'expected non-nil email'
65 assert_nil created['identity_url'], 'expected no identity_url'
68 test "create user with user, vm and repo as input" do
70 repo_name = 'test_repo'
74 openid_prefix: 'https://www.google.com/accounts/o8/id',
76 uuid: 'zzzzz-tpzed-abcdefghijklmno',
77 first_name: "in_create_test_first_name",
78 last_name: "test_last_name",
79 email: "foo@example.com"
82 assert_response :success
83 response_items = JSON.parse(@response.body)['items']
85 created = find_obj_in_resp response_items, 'User', nil
87 assert_equal 'in_create_test_first_name', created['first_name']
88 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
89 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
90 assert_not_nil created['email'], 'expected non-nil email'
91 assert_nil created['identity_url'], 'expected no identity_url'
93 # arvados#user, repo link and link add user to 'All users' group
94 verify_num_links @all_links_at_start, 4
96 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
97 created['uuid'], created['email'], 'arvados#user', false, 'User'
99 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
100 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
102 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
103 'All users', created['uuid'], 'arvados#group', true, 'Group'
105 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
106 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
108 verify_system_group_permission_link_for created['uuid']
110 # invoke setup again with the same data
112 repo_name: repo_name,
114 openid_prefix: 'https://www.google.com/accounts/o8/id',
116 uuid: 'zzzzz-tpzed-abcdefghijklmno',
117 first_name: "in_create_test_first_name",
118 last_name: "test_last_name",
119 email: "foo@example.com"
123 response_items = JSON.parse(@response.body)['items']
125 created = find_obj_in_resp response_items, 'User', nil
126 assert_equal 'in_create_test_first_name', created['first_name']
127 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
128 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
129 assert_not_nil created['email'], 'expected non-nil email'
130 assert_nil created['identity_url'], 'expected no identity_url'
132 # arvados#user, repo link and link add user to 'All users' group
133 verify_num_links @all_links_at_start, 5
135 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
136 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
138 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
139 'All users', created['uuid'], 'arvados#group', true, 'Group'
141 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
142 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
144 verify_system_group_permission_link_for created['uuid']
147 test "setup user with bogus uuid and expect error" do
148 authorize_with :admin
152 repo_name: 'test_repo',
155 response_body = JSON.parse(@response.body)
156 response_errors = response_body['errors']
157 assert_not_nil response_errors, 'Expected error in response'
158 assert (response_errors.first.include? 'Path not found'), 'Expected 404'
161 test "setup user with bogus uuid in user and expect error" do
162 authorize_with :admin
165 user: {uuid: 'bogus_uuid'},
166 repo_name: 'test_repo',
168 openid_prefix: 'https://www.google.com/accounts/o8/id'
170 response_body = JSON.parse(@response.body)
171 response_errors = response_body['errors']
172 assert_not_nil response_errors, 'Expected error in response'
173 assert (response_errors.first.include? 'ArgumentError: Require user email'),
174 'Expected RuntimeError'
177 test "setup user with no uuid and user, expect error" do
178 authorize_with :admin
181 repo_name: 'test_repo',
183 openid_prefix: 'https://www.google.com/accounts/o8/id'
185 response_body = JSON.parse(@response.body)
186 response_errors = response_body['errors']
187 assert_not_nil response_errors, 'Expected error in response'
188 assert (response_errors.first.include? 'Required uuid or user'),
189 'Expected ArgumentError'
192 test "setup user with no uuid and email, expect error" do
193 authorize_with :admin
197 repo_name: 'test_repo',
199 openid_prefix: 'https://www.google.com/accounts/o8/id'
201 response_body = JSON.parse(@response.body)
202 response_errors = response_body['errors']
203 assert_not_nil response_errors, 'Expected error in response'
204 assert (response_errors.first.include? '<ArgumentError: Require user email'),
205 'Expected ArgumentError'
208 test "invoke setup with existing uuid, vm and repo and verify links" do
209 authorize_with :inactive
211 assert_response :success
212 inactive_user = JSON.parse(@response.body)
214 authorize_with :admin
217 uuid: inactive_user['uuid'],
218 repo_name: 'test_repo',
222 assert_response :success
224 response_items = JSON.parse(@response.body)['items']
225 resp_obj = find_obj_in_resp response_items, 'User', nil
227 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
228 assert_equal inactive_user['uuid'], resp_obj['uuid']
229 assert_equal inactive_user['email'], resp_obj['email'],
230 'expecting inactive user email'
232 # expect repo and vm links
233 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
234 'test_repo', resp_obj['uuid'], 'arvados#repository', true, 'Repository'
236 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
237 @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
240 test "invoke setup with existing uuid in user, verify response" do
241 authorize_with :inactive
243 assert_response :success
244 inactive_user = JSON.parse(@response.body)
246 authorize_with :admin
249 user: {uuid: inactive_user['uuid']},
250 openid_prefix: 'https://www.google.com/accounts/o8/id'
253 assert_response :success
255 response_items = JSON.parse(@response.body)['items']
256 resp_obj = find_obj_in_resp response_items, 'User', nil
258 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
259 assert_equal inactive_user['uuid'], resp_obj['uuid']
260 assert_equal inactive_user['email'], resp_obj['email'],
261 'expecting inactive user email'
264 test "invoke setup with existing uuid but different email, expect original email" do
265 authorize_with :inactive
267 assert_response :success
268 inactive_user = JSON.parse(@response.body)
270 authorize_with :admin
273 uuid: inactive_user['uuid'],
274 user: {email: 'junk_email'}
277 assert_response :success
279 response_items = JSON.parse(@response.body)['items']
280 resp_obj = find_obj_in_resp response_items, 'User', nil
282 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
283 assert_equal inactive_user['uuid'], resp_obj['uuid']
284 assert_equal inactive_user['email'], resp_obj['email'],
285 'expecting inactive user email'
288 test "setup user with valid email and repo as input" do
289 authorize_with :admin
292 repo_name: 'test_repo',
293 user: {email: 'foo@example.com'},
294 openid_prefix: 'https://www.google.com/accounts/o8/id'
297 assert_response :success
298 response_items = JSON.parse(@response.body)['items']
299 response_object = find_obj_in_resp response_items, 'User', nil
300 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
301 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
303 # four extra links; system_group, login, group and repo perms
304 verify_num_links @all_links_at_start, 4
307 test "setup user with fake vm and expect error" do
308 authorize_with :admin
311 repo_name: 'test_repo',
312 vm_uuid: 'no_such_vm',
313 user: {email: 'foo@example.com'},
314 openid_prefix: 'https://www.google.com/accounts/o8/id'
317 response_body = JSON.parse(@response.body)
318 response_errors = response_body['errors']
319 assert_not_nil response_errors, 'Expected error in response'
320 assert (response_errors.first.include? "No vm found for no_such_vm"),
321 'Expected RuntimeError: No vm found for no_such_vm'
324 test "setup user with valid email, repo and real vm as input" do
325 authorize_with :admin
328 repo_name: 'test_repo',
329 openid_prefix: 'https://www.google.com/accounts/o8/id',
331 user: {email: 'foo@example.com'}
334 assert_response :success
335 response_items = JSON.parse(@response.body)['items']
336 response_object = find_obj_in_resp response_items, 'User', nil
337 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
338 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
340 # five extra links; system_group, login, group, vm, repo
341 verify_num_links @all_links_at_start, 5
344 test "setup user with valid email, no vm and repo as input" do
345 authorize_with :admin
348 user: {email: 'foo@example.com'},
349 openid_prefix: 'https://www.google.com/accounts/o8/id'
352 assert_response :success
353 response_items = JSON.parse(@response.body)['items']
354 response_object = find_obj_in_resp response_items, 'User', nil
355 assert_not_nil response_object['uuid'], 'expected uuid for new user'
356 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
358 # three extra links; system_group, login, and group
359 verify_num_links @all_links_at_start, 3
362 test "setup user with email, first name, repo name and vm uuid" do
363 authorize_with :admin
366 openid_prefix: 'https://www.google.com/accounts/o8/id',
367 repo_name: 'test_repo',
370 first_name: 'test_first_name',
371 email: 'foo@example.com'
375 assert_response :success
376 response_items = JSON.parse(@response.body)['items']
377 response_object = find_obj_in_resp response_items, 'User', nil
378 assert_not_nil response_object['uuid'], 'expected uuid for new user'
379 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
380 assert_equal 'test_first_name', response_object['first_name'],
381 'expecting first name'
383 # five extra links; system_group, login, group, repo and vm
384 verify_num_links @all_links_at_start, 5
387 test "setup user twice with email and check two different objects created" do
388 authorize_with :admin
391 openid_prefix: 'https://www.google.com/accounts/o8/id',
392 repo_name: 'test_repo',
394 email: 'foo@example.com'
398 assert_response :success
399 response_items = JSON.parse(@response.body)['items']
400 response_object = find_obj_in_resp response_items, 'User', nil
401 assert_not_nil response_object['uuid'], 'expected uuid for new user'
402 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
403 # system_group, openid, group, and repo. No vm link.
404 verify_num_links @all_links_at_start, 4
408 user: {email: 'foo@example.com'},
409 openid_prefix: 'https://www.google.com/accounts/o8/id'
412 assert_response :success
413 response_items = JSON.parse(@response.body)['items']
414 response_object2 = find_obj_in_resp response_items, 'User', nil
415 assert_not_equal response_object['uuid'], response_object2['uuid'],
416 'expected same uuid as first create operation'
417 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
419 # +1 extra can_read 'all users' group link
420 # +1 extra system_group can_manage link pointing to the new User
421 # +1 extra can_login permission link
422 # no repo link, no vm link
423 verify_num_links @all_links_at_start, 7
426 test "setup user with openid prefix" do
427 authorize_with :admin
430 repo_name: 'test_repo',
431 openid_prefix: 'http://www.example.com/account',
433 first_name: "in_create_test_first_name",
434 last_name: "test_last_name",
435 email: "foo@example.com"
439 assert_response :success
441 response_items = JSON.parse(@response.body)['items']
442 created = find_obj_in_resp response_items, 'User', nil
444 assert_equal 'in_create_test_first_name', created['first_name']
445 assert_not_nil created['uuid'], 'expected uuid for new user'
446 assert_not_nil created['email'], 'expected non-nil email'
447 assert_nil created['identity_url'], 'expected no identity_url'
450 # four new links: system_group, arvados#user, repo, and 'All users' group.
451 verify_num_links @all_links_at_start, 4
453 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
454 created['uuid'], created['email'], 'arvados#user', false, 'User'
456 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
457 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
459 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
460 'All users', created['uuid'], 'arvados#group', true, 'Group'
462 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
463 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
466 test "invoke setup with no openid prefix, expect error" do
467 authorize_with :admin
470 repo_name: 'test_repo',
472 first_name: "in_create_test_first_name",
473 last_name: "test_last_name",
474 email: "foo@example.com"
478 response_body = JSON.parse(@response.body)
479 response_errors = response_body['errors']
480 assert_not_nil response_errors, 'Expected error in response'
481 assert (response_errors.first.include? 'openid_prefix parameter is missing'),
482 'Expected ArgumentError'
485 test "setup user with user, vm and repo and verify links" do
486 authorize_with :admin
490 first_name: "in_create_test_first_name",
491 last_name: "test_last_name",
492 email: "foo@example.com"
495 repo_name: 'test_repo',
496 openid_prefix: 'https://www.google.com/accounts/o8/id'
499 assert_response :success
501 response_items = JSON.parse(@response.body)['items']
502 created = find_obj_in_resp response_items, 'User', nil
504 assert_equal 'in_create_test_first_name', created['first_name']
505 assert_not_nil created['uuid'], 'expected uuid for new user'
506 assert_not_nil created['email'], 'expected non-nil email'
507 assert_nil created['identity_url'], 'expected no identity_url'
509 # five new links: system_group, arvados#user, repo, vm and 'All
511 verify_num_links @all_links_at_start, 5
513 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
514 created['uuid'], created['email'], 'arvados#user', false, 'User'
516 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
517 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
519 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
520 'All users', created['uuid'], 'arvados#group', true, 'Group'
522 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
523 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
526 test "create user as non admin user and expect error" do
527 authorize_with :active
530 user: {email: 'foo@example.com'}
533 response_body = JSON.parse(@response.body)
534 response_errors = response_body['errors']
535 assert_not_nil response_errors, 'Expected error in response'
536 assert (response_errors.first.include? 'PermissionDenied'),
537 'Expected PermissionDeniedError'
540 test "setup user as non admin user and expect error" do
541 authorize_with :active
544 openid_prefix: 'https://www.google.com/accounts/o8/id',
545 user: {email: 'foo@example.com'}
548 response_body = JSON.parse(@response.body)
549 response_errors = response_body['errors']
550 assert_not_nil response_errors, 'Expected error in response'
551 assert (response_errors.first.include? 'Forbidden'),
552 'Expected Forbidden error'
555 test "setup user in multiple steps and verify response" do
556 authorize_with :admin
559 openid_prefix: 'http://www.example.com/account',
561 email: "foo@example.com"
565 assert_response :success
566 response_items = JSON.parse(@response.body)['items']
567 created = find_obj_in_resp response_items, 'User', nil
569 assert_not_nil created['uuid'], 'expected uuid for new user'
570 assert_not_nil created['email'], 'expected non-nil email'
571 assert_equal created['email'], 'foo@example.com', 'expected input email'
573 # three new links: system_group, arvados#user, and 'All users' group.
574 verify_num_links @all_links_at_start, 3
576 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
577 created['uuid'], created['email'], 'arvados#user', false, 'User'
579 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
580 'All users', created['uuid'], 'arvados#group', true, 'Group'
582 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
583 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
585 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
586 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
588 # invoke setup with a repository
590 openid_prefix: 'http://www.example.com/account',
591 repo_name: 'new_repo',
592 uuid: created['uuid']
595 assert_response :success
597 response_items = JSON.parse(@response.body)['items']
598 created = find_obj_in_resp response_items, 'User', nil
600 assert_equal 'foo@example.com', created['email'], 'expected input email'
603 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
604 'All users', created['uuid'], 'arvados#group', true, 'Group'
606 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
607 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
609 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
610 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
612 # invoke setup with a vm_uuid
615 openid_prefix: 'http://www.example.com/account',
619 uuid: created['uuid']
622 assert_response :success
624 response_items = JSON.parse(@response.body)['items']
625 created = find_obj_in_resp response_items, 'User', nil
627 assert_equal created['email'], 'foo@example.com', 'expected original email'
630 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
631 'All users', created['uuid'], 'arvados#group', true, 'Group'
633 # since no repo name in input, we won't get any; even though user has one
634 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
635 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
637 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
638 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
641 test "setup and unsetup user" do
642 authorize_with :admin
645 repo_name: 'test_repo',
647 user: {email: 'foo@example.com'},
648 openid_prefix: 'https://www.google.com/accounts/o8/id'
651 assert_response :success
652 response_items = JSON.parse(@response.body)['items']
653 created = find_obj_in_resp response_items, 'User', nil
654 assert_not_nil created['uuid'], 'expected uuid for the new user'
655 assert_equal created['email'], 'foo@example.com', 'expected given email'
657 # five extra links: system_group, login, group, repo and vm
658 verify_num_links @all_links_at_start, 5
660 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
661 created['uuid'], created['email'], 'arvados#user', false, 'User'
663 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
664 'All users', created['uuid'], 'arvados#group', true, 'Group'
666 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
667 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
669 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
670 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
672 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
674 # now unsetup this user
675 post :unsetup, uuid: created['uuid']
676 assert_response :success
678 created2 = JSON.parse(@response.body)
679 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
680 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
682 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
685 test "unsetup active user" do
686 authorize_with :active
688 assert_response :success
689 active_user = JSON.parse(@response.body)
690 assert_not_nil active_user['uuid'], 'expected uuid for the active user'
691 assert active_user['is_active'], 'expected is_active for active user'
692 assert active_user['is_invited'], 'expected is_invited for active user'
694 verify_link_existence active_user['uuid'], active_user['email'],
695 false, false, false, true, true
697 authorize_with :admin
699 # now unsetup this user
700 post :unsetup, uuid: active_user['uuid']
701 assert_response :success
703 response_user = JSON.parse(@response.body)
704 assert_not_nil response_user['uuid'], 'expected uuid for the upsetup user'
705 assert_equal active_user['uuid'], response_user['uuid'], 'expected uuid not found'
706 assert !response_user['is_active'], 'expected user to be inactive'
707 assert !response_user['is_invited'], 'expected user to be uninvited'
709 verify_link_existence response_user['uuid'], response_user['email'],
710 false, false, false, false, false
713 test "setup user with send notification param false and verify no email" do
714 authorize_with :admin
717 openid_prefix: 'http://www.example.com/account',
718 send_notification_email: 'false',
720 email: "foo@example.com"
724 assert_response :success
725 response_items = JSON.parse(@response.body)['items']
726 created = find_obj_in_resp response_items, 'User', nil
727 assert_not_nil created['uuid'], 'expected uuid for the new user'
728 assert_equal created['email'], 'foo@example.com', 'expected given email'
730 setup_email = ActionMailer::Base.deliveries.last
731 assert_nil setup_email, 'expected no setup email'
734 test "setup user with send notification param true and verify email" do
735 authorize_with :admin
738 openid_prefix: 'http://www.example.com/account',
739 send_notification_email: 'true',
741 email: "foo@example.com"
745 assert_response :success
746 response_items = JSON.parse(@response.body)['items']
747 created = find_obj_in_resp response_items, 'User', nil
748 assert_not_nil created['uuid'], 'expected uuid for the new user'
749 assert_equal created['email'], 'foo@example.com', 'expected given email'
751 setup_email = ActionMailer::Base.deliveries.last
752 assert_not_nil setup_email, 'Expected email after setup'
754 assert_equal Rails.configuration.user_notifier_email_from, setup_email.from[0]
755 assert_equal 'foo@example.com', setup_email.to[0]
756 assert_equal 'Welcome to Curoverse', setup_email.subject
757 assert (setup_email.body.to_s.include? 'Your Arvados account has been set up'),
758 'Expected Your Arvados account has been set up in email body'
759 assert (setup_email.body.to_s.include? 'foo@example.com'),
760 'Expected user email in email body'
761 assert (setup_email.body.to_s.include? Rails.configuration.workbench_address),
762 'Expected workbench url in email body'
765 def verify_num_links (original_links, expected_additional_links)
767 assert_equal expected_additional_links, Link.all.size-original_links.size,
768 "Expected #{expected_additional_links.inspect} more links"
771 def find_obj_in_resp (response_items, object_type, head_kind=nil)
773 response_items.each { |x|
778 if object_type == 'User'
779 if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
783 else # looking for a link
784 if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
793 def verify_link(response_items, link_object_name, expect_link, link_class,
794 link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
796 link = find_obj_in_resp response_items, 'Link', link_object_name
799 assert_nil link, "Expected no link for #{link_object_name}"
803 assert_not_nil link, "Expected link for #{link_object_name}"
806 object = Object.const_get(class_name).where(name: head_uuid)
807 assert [] != object, "expected #{class_name} with name #{head_uuid}"
808 head_uuid = object.first[:uuid]
810 assert_equal link_class, link['link_class'],
811 "did not find expected link_class for #{link_object_name}"
813 assert_equal link_name, link['name'],
814 "did not find expected link_name for #{link_object_name}"
816 assert_equal tail_uuid, link['tail_uuid'],
817 "did not find expected tail_uuid for #{link_object_name}"
819 assert_equal head_kind, link['head_kind'],
820 "did not find expected head_kind for #{link_object_name}"
822 assert_equal head_uuid, link['head_uuid'],
823 "did not find expected head_uuid for #{link_object_name}"
826 def verify_link_existence uuid, email, expect_oid_login_perms,
827 expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
828 # verify that all links are deleted for the user
829 oid_login_perms = Link.where(tail_uuid: email,
830 link_class: 'permission',
831 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
832 if expect_oid_login_perms
833 assert oid_login_perms.any?, "expected oid_login_perms"
835 assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
838 repo_perms = Link.where(tail_uuid: uuid,
839 link_class: 'permission',
840 name: 'can_write').where("head_uuid like ?", Repository.uuid_like_pattern)
842 assert repo_perms.any?, "expected repo_perms"
844 assert !repo_perms.any?, "expected all repo_perms deleted"
847 vm_login_perms = Link.where(tail_uuid: uuid,
848 link_class: 'permission',
849 name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
851 assert vm_login_perms.any?, "expected vm_login_perms"
853 assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
856 group = Group.where(name: 'All users').select do |g|
857 g[:uuid].match /-f+$/
859 group_read_perms = Link.where(tail_uuid: uuid,
860 head_uuid: group[:uuid],
861 link_class: 'permission',
863 if expect_group_perms
864 assert group_read_perms.any?, "expected all users group read perms"
866 assert !group_read_perms.any?, "expected all users group perm deleted"
869 signed_uuids = Link.where(link_class: 'signature',
873 assert signed_uuids.any?, "expected signatures"
875 assert !signed_uuids.any?, "expected all signatures deleted"
880 def verify_system_group_permission_link_for user_uuid
881 assert_equal 1, Link.where(link_class: 'permission',
883 tail_uuid: system_group_uuid,
884 head_uuid: user_uuid).count