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 login link +1 extra system_group link pointing to the new User
420 verify_num_links @all_links_at_start, 6
423 test "setup user with openid prefix" do
424 authorize_with :admin
427 repo_name: 'test_repo',
428 openid_prefix: 'http://www.example.com/account',
430 first_name: "in_create_test_first_name",
431 last_name: "test_last_name",
432 email: "foo@example.com"
436 assert_response :success
438 response_items = JSON.parse(@response.body)['items']
439 created = find_obj_in_resp response_items, 'User', nil
441 assert_equal 'in_create_test_first_name', created['first_name']
442 assert_not_nil created['uuid'], 'expected uuid for new user'
443 assert_not_nil created['email'], 'expected non-nil email'
444 assert_nil created['identity_url'], 'expected no identity_url'
447 # four new links: system_group, arvados#user, repo, and 'All users' group.
448 verify_num_links @all_links_at_start, 4
450 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
451 created['uuid'], created['email'], 'arvados#user', false, 'User'
453 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
454 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
456 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
457 'All users', created['uuid'], 'arvados#group', true, 'Group'
459 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
460 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
463 test "invoke setup with no openid prefix, expect error" do
464 authorize_with :admin
467 repo_name: 'test_repo',
469 first_name: "in_create_test_first_name",
470 last_name: "test_last_name",
471 email: "foo@example.com"
475 response_body = JSON.parse(@response.body)
476 response_errors = response_body['errors']
477 assert_not_nil response_errors, 'Expected error in response'
478 assert (response_errors.first.include? 'openid_prefix parameter is missing'),
479 'Expected ArgumentError'
482 test "setup user with user, vm and repo and verify links" do
483 authorize_with :admin
487 first_name: "in_create_test_first_name",
488 last_name: "test_last_name",
489 email: "foo@example.com"
492 repo_name: 'test_repo',
493 openid_prefix: 'https://www.google.com/accounts/o8/id'
496 assert_response :success
498 response_items = JSON.parse(@response.body)['items']
499 created = find_obj_in_resp response_items, 'User', nil
501 assert_equal 'in_create_test_first_name', created['first_name']
502 assert_not_nil created['uuid'], 'expected uuid for new user'
503 assert_not_nil created['email'], 'expected non-nil email'
504 assert_nil created['identity_url'], 'expected no identity_url'
506 # five new links: system_group, arvados#user, repo, vm and 'All
508 verify_num_links @all_links_at_start, 5
510 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
511 created['uuid'], created['email'], 'arvados#user', false, 'User'
513 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
514 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
516 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
517 'All users', created['uuid'], 'arvados#group', true, 'Group'
519 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
520 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
523 test "create user as non admin user and expect error" do
524 authorize_with :active
527 user: {email: 'foo@example.com'}
530 response_body = JSON.parse(@response.body)
531 response_errors = response_body['errors']
532 assert_not_nil response_errors, 'Expected error in response'
533 assert (response_errors.first.include? 'PermissionDenied'),
534 'Expected PermissionDeniedError'
537 test "setup user as non admin user and expect error" do
538 authorize_with :active
541 openid_prefix: 'https://www.google.com/accounts/o8/id',
542 user: {email: 'foo@example.com'}
545 response_body = JSON.parse(@response.body)
546 response_errors = response_body['errors']
547 assert_not_nil response_errors, 'Expected error in response'
548 assert (response_errors.first.include? 'Forbidden'),
549 'Expected Forbidden error'
552 test "setup user in multiple steps and verify response" do
553 authorize_with :admin
556 openid_prefix: 'http://www.example.com/account',
558 email: "foo@example.com"
562 assert_response :success
563 response_items = JSON.parse(@response.body)['items']
564 created = find_obj_in_resp response_items, 'User', nil
566 assert_not_nil created['uuid'], 'expected uuid for new user'
567 assert_not_nil created['email'], 'expected non-nil email'
568 assert_equal created['email'], 'foo@example.com', 'expected input email'
570 # three new links: system_group, arvados#user, and 'All users' group.
571 verify_num_links @all_links_at_start, 3
573 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
574 created['uuid'], created['email'], 'arvados#user', false, 'User'
576 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
577 'All users', created['uuid'], 'arvados#group', true, 'Group'
579 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
580 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
582 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
583 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
585 # invoke setup with a repository
587 openid_prefix: 'http://www.example.com/account',
588 repo_name: 'new_repo',
589 uuid: created['uuid']
592 assert_response :success
594 response_items = JSON.parse(@response.body)['items']
595 created = find_obj_in_resp response_items, 'User', nil
597 assert_equal 'foo@example.com', created['email'], 'expected input email'
600 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
601 'All users', created['uuid'], 'arvados#group', true, 'Group'
603 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
604 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
606 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
607 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
609 # invoke setup with a vm_uuid
612 openid_prefix: 'http://www.example.com/account',
616 uuid: created['uuid']
619 assert_response :success
621 response_items = JSON.parse(@response.body)['items']
622 created = find_obj_in_resp response_items, 'User', nil
624 assert_equal created['email'], 'foo@example.com', 'expected original email'
627 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
628 'All users', created['uuid'], 'arvados#group', true, 'Group'
630 # since no repo name in input, we won't get any; even though user has one
631 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
632 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
634 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
635 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
638 test "setup and unsetup user" do
639 authorize_with :admin
642 repo_name: 'test_repo',
644 user: {email: 'foo@example.com'},
645 openid_prefix: 'https://www.google.com/accounts/o8/id'
648 assert_response :success
649 response_items = JSON.parse(@response.body)['items']
650 created = find_obj_in_resp response_items, 'User', nil
651 assert_not_nil created['uuid'], 'expected uuid for the new user'
652 assert_equal created['email'], 'foo@example.com', 'expected given email'
654 # five extra links: system_group, login, group, repo and vm
655 verify_num_links @all_links_at_start, 5
657 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
658 created['uuid'], created['email'], 'arvados#user', false, 'User'
660 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
661 'All users', created['uuid'], 'arvados#group', true, 'Group'
663 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
664 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
666 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
667 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
669 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
671 # now unsetup this user
672 post :unsetup, uuid: created['uuid']
673 assert_response :success
675 created2 = JSON.parse(@response.body)
676 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
677 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
679 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
682 test "unsetup active user" do
683 authorize_with :active
685 assert_response :success
686 active_user = JSON.parse(@response.body)
687 assert_not_nil active_user['uuid'], 'expected uuid for the active user'
688 assert active_user['is_active'], 'expected is_active for active user'
689 assert active_user['is_invited'], 'expected is_invited for active user'
691 verify_link_existence active_user['uuid'], active_user['email'],
692 false, false, false, true, true
694 authorize_with :admin
696 # now unsetup this user
697 post :unsetup, uuid: active_user['uuid']
698 assert_response :success
700 response_user = JSON.parse(@response.body)
701 assert_not_nil response_user['uuid'], 'expected uuid for the upsetup user'
702 assert_equal active_user['uuid'], response_user['uuid'], 'expected uuid not found'
703 assert !response_user['is_active'], 'expected user to be inactive'
704 assert !response_user['is_invited'], 'expected user to be uninvited'
706 verify_link_existence response_user['uuid'], response_user['email'],
707 false, false, false, false, false
710 test "setup user with send notification param false and verify no email" do
711 authorize_with :admin
714 openid_prefix: 'http://www.example.com/account',
715 send_notification_email: 'false',
717 email: "foo@example.com"
721 assert_response :success
722 response_items = JSON.parse(@response.body)['items']
723 created = find_obj_in_resp response_items, 'User', nil
724 assert_not_nil created['uuid'], 'expected uuid for the new user'
725 assert_equal created['email'], 'foo@example.com', 'expected given email'
727 setup_email = ActionMailer::Base.deliveries.last
728 assert_nil setup_email, 'expected no setup email'
731 test "setup user with send notification param true and verify email" do
732 authorize_with :admin
735 openid_prefix: 'http://www.example.com/account',
736 send_notification_email: 'true',
738 email: "foo@example.com"
742 assert_response :success
743 response_items = JSON.parse(@response.body)['items']
744 created = find_obj_in_resp response_items, 'User', nil
745 assert_not_nil created['uuid'], 'expected uuid for the new user'
746 assert_equal created['email'], 'foo@example.com', 'expected given email'
748 setup_email = ActionMailer::Base.deliveries.last
749 assert_not_nil setup_email, 'Expected email after setup'
751 assert_equal Rails.configuration.user_notifier_email_from, setup_email.from[0]
752 assert_equal 'foo@example.com', setup_email.to[0]
753 assert_equal 'Welcome to Curoverse', setup_email.subject
754 assert (setup_email.body.to_s.include? 'Your Arvados account has been set up'),
755 'Expected Your Arvados account has been set up in email body'
756 assert (setup_email.body.to_s.include? 'foo@example.com'),
757 'Expected user email in email body'
758 assert (setup_email.body.to_s.include? Rails.configuration.workbench_address),
759 'Expected workbench url in email body'
762 def verify_num_links (original_links, expected_additional_links)
764 assert_equal expected_additional_links, Link.all.size-original_links.size,
765 "Expected #{expected_additional_links.inspect} more links"
768 def find_obj_in_resp (response_items, object_type, head_kind=nil)
770 response_items.each { |x|
775 if object_type == 'User'
776 if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
780 else # looking for a link
781 if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
790 def verify_link(response_items, link_object_name, expect_link, link_class,
791 link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
793 link = find_obj_in_resp response_items, 'Link', link_object_name
796 assert_nil link, "Expected no link for #{link_object_name}"
800 assert_not_nil link, "Expected link for #{link_object_name}"
803 object = Object.const_get(class_name).where(name: head_uuid)
804 assert [] != object, "expected #{class_name} with name #{head_uuid}"
805 head_uuid = object.first[:uuid]
807 assert_equal link_class, link['link_class'],
808 "did not find expected link_class for #{link_object_name}"
810 assert_equal link_name, link['name'],
811 "did not find expected link_name for #{link_object_name}"
813 assert_equal tail_uuid, link['tail_uuid'],
814 "did not find expected tail_uuid for #{link_object_name}"
816 assert_equal head_kind, link['head_kind'],
817 "did not find expected head_kind for #{link_object_name}"
819 assert_equal head_uuid, link['head_uuid'],
820 "did not find expected head_uuid for #{link_object_name}"
823 def verify_link_existence uuid, email, expect_oid_login_perms,
824 expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
825 # verify that all links are deleted for the user
826 oid_login_perms = Link.where(tail_uuid: email,
827 link_class: 'permission',
828 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
829 if expect_oid_login_perms
830 assert oid_login_perms.any?, "expected oid_login_perms"
832 assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
835 repo_perms = Link.where(tail_uuid: uuid,
836 link_class: 'permission',
837 name: 'can_write').where("head_uuid like ?", Repository.uuid_like_pattern)
839 assert repo_perms.any?, "expected repo_perms"
841 assert !repo_perms.any?, "expected all repo_perms deleted"
844 vm_login_perms = Link.where(tail_uuid: uuid,
845 link_class: 'permission',
846 name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
848 assert vm_login_perms.any?, "expected vm_login_perms"
850 assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
853 group = Group.where(name: 'All users').select do |g|
854 g[:uuid].match /-f+$/
856 group_read_perms = Link.where(tail_uuid: uuid,
857 head_uuid: group[:uuid],
858 link_class: 'permission',
860 if expect_group_perms
861 assert group_read_perms.any?, "expected all users group read perms"
863 assert !group_read_perms.any?, "expected all users group perm deleted"
866 signed_uuids = Link.where(link_class: 'signature',
870 assert signed_uuids.any?, "expected signatures"
872 assert !signed_uuids.any?, "expected all signatures deleted"
877 def verify_system_group_permission_link_for user_uuid
878 assert_equal 1, Link.where(link_class: 'permission',
880 tail_uuid: system_group_uuid,
881 head_uuid: user_uuid).count