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, id: 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
25 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
30 Collection.uuid_like_pattern).
33 assert required_uuids.length > 0
35 signed_uuids = Link.where(owner_uuid: system_user_uuid,
36 link_class: 'signature',
38 tail_uuid: users(:inactive).uuid,
39 head_uuid: required_uuids).
42 assert_equal 0, signed_uuids.length
45 authorize_with :inactive
48 assert_response :success
49 me = JSON.parse(@response.body)
50 assert_equal false, me['is_active']
52 post :activate, id: me['uuid']
56 assert_response :success
57 me = JSON.parse(@response.body)
58 assert_equal false, me['is_active']
61 test "activate an already-active user" do
62 authorize_with :active
64 assert_response :success
65 me = JSON.parse(@response.body)
66 post :activate, id: me['uuid']
67 assert_response :success
68 me = JSON.parse(@response.body)
69 assert_equal true, me['is_active']
72 test "respond 401 if given token exists but user record is missing" do
73 authorize_with :valid_token_deleted_user
74 get :current, {format: :json}
78 test "create new user with user as input" do
81 first_name: "test_first_name",
82 last_name: "test_last_name",
83 email: "foo@example.com"
85 assert_response :success
86 created = JSON.parse(@response.body)
87 assert_equal 'test_first_name', created['first_name']
88 assert_not_nil created['uuid'], 'expected uuid for the newly created user'
89 assert_not_nil created['email'], 'expected non-nil email'
90 assert_nil created['identity_url'], 'expected no identity_url'
93 test "create user with user, vm and repo as input" do
95 repo_name = 'test_repo'
99 openid_prefix: 'https://www.google.com/accounts/o8/id',
101 uuid: 'zzzzz-tpzed-abcdefghijklmno',
102 first_name: "in_create_test_first_name",
103 last_name: "test_last_name",
104 email: "foo@example.com"
107 assert_response :success
108 response_items = JSON.parse(@response.body)['items']
110 created = find_obj_in_resp response_items, 'User', nil
112 assert_equal 'in_create_test_first_name', created['first_name']
113 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
114 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
115 assert_not_nil created['email'], 'expected non-nil email'
116 assert_nil created['identity_url'], 'expected no identity_url'
118 # arvados#user, repo link and link add user to 'All users' group
119 verify_num_links @all_links_at_start, 4
121 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
122 created['uuid'], created['email'], 'arvados#user', false, 'User'
124 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
125 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
127 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
128 'All users', created['uuid'], 'arvados#group', true, 'Group'
130 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
131 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
133 verify_system_group_permission_link_for created['uuid']
135 # invoke setup again with the same data
137 repo_name: repo_name,
139 openid_prefix: 'https://www.google.com/accounts/o8/id',
141 uuid: 'zzzzz-tpzed-abcdefghijklmno',
142 first_name: "in_create_test_first_name",
143 last_name: "test_last_name",
144 email: "foo@example.com"
148 response_items = JSON.parse(@response.body)['items']
150 created = find_obj_in_resp response_items, 'User', nil
151 assert_equal 'in_create_test_first_name', created['first_name']
152 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
153 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
154 assert_not_nil created['email'], 'expected non-nil email'
155 assert_nil created['identity_url'], 'expected no identity_url'
157 # arvados#user, repo link and link add user to 'All users' group
158 verify_num_links @all_links_at_start, 5
160 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
161 repo_name, created['uuid'], 'arvados#repository', true, 'Repository'
163 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
164 'All users', created['uuid'], 'arvados#group', true, 'Group'
166 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
167 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
169 verify_system_group_permission_link_for created['uuid']
172 test "setup user with bogus uuid and expect error" do
173 authorize_with :admin
177 repo_name: 'test_repo',
180 response_body = JSON.parse(@response.body)
181 response_errors = response_body['errors']
182 assert_not_nil response_errors, 'Expected error in response'
183 assert (response_errors.first.include? 'Path not found'), 'Expected 404'
186 test "setup user with bogus uuid in user and expect error" do
187 authorize_with :admin
190 user: {uuid: 'bogus_uuid'},
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 RuntimeError'
202 test "setup user with no uuid and user, expect error" do
203 authorize_with :admin
206 repo_name: 'test_repo',
208 openid_prefix: 'https://www.google.com/accounts/o8/id'
210 response_body = JSON.parse(@response.body)
211 response_errors = response_body['errors']
212 assert_not_nil response_errors, 'Expected error in response'
213 assert (response_errors.first.include? 'Required uuid or user'),
214 'Expected ArgumentError'
217 test "setup user with no uuid and email, expect error" do
218 authorize_with :admin
222 repo_name: 'test_repo',
224 openid_prefix: 'https://www.google.com/accounts/o8/id'
226 response_body = JSON.parse(@response.body)
227 response_errors = response_body['errors']
228 assert_not_nil response_errors, 'Expected error in response'
229 assert (response_errors.first.include? '<ArgumentError: Require user email'),
230 'Expected ArgumentError'
233 test "invoke setup with existing uuid, vm and repo and verify links" do
234 authorize_with :inactive
236 assert_response :success
237 inactive_user = JSON.parse(@response.body)
239 authorize_with :admin
242 uuid: inactive_user['uuid'],
243 repo_name: 'test_repo',
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'
257 # expect repo and vm links
258 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
259 'test_repo', resp_obj['uuid'], 'arvados#repository', true, 'Repository'
261 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
262 @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
265 test "invoke setup with existing uuid in user, verify response" do
266 authorize_with :inactive
268 assert_response :success
269 inactive_user = JSON.parse(@response.body)
271 authorize_with :admin
274 user: {uuid: inactive_user['uuid']},
275 openid_prefix: 'https://www.google.com/accounts/o8/id'
278 assert_response :success
280 response_items = JSON.parse(@response.body)['items']
281 resp_obj = find_obj_in_resp response_items, 'User', nil
283 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
284 assert_equal inactive_user['uuid'], resp_obj['uuid']
285 assert_equal inactive_user['email'], resp_obj['email'],
286 'expecting inactive user email'
289 test "invoke setup with existing uuid but different email, expect original email" do
290 authorize_with :inactive
292 assert_response :success
293 inactive_user = JSON.parse(@response.body)
295 authorize_with :admin
298 uuid: inactive_user['uuid'],
299 user: {email: 'junk_email'}
302 assert_response :success
304 response_items = JSON.parse(@response.body)['items']
305 resp_obj = find_obj_in_resp response_items, 'User', nil
307 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
308 assert_equal inactive_user['uuid'], resp_obj['uuid']
309 assert_equal inactive_user['email'], resp_obj['email'],
310 'expecting inactive user email'
313 test "setup user with valid email and repo as input" do
314 authorize_with :admin
317 repo_name: 'test_repo',
318 user: {email: 'foo@example.com'},
319 openid_prefix: 'https://www.google.com/accounts/o8/id'
322 assert_response :success
323 response_items = JSON.parse(@response.body)['items']
324 response_object = find_obj_in_resp response_items, 'User', nil
325 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
326 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
328 # four extra links; system_group, login, group and repo perms
329 verify_num_links @all_links_at_start, 4
332 test "setup user with fake vm and expect error" do
333 authorize_with :admin
336 repo_name: 'test_repo',
337 vm_uuid: 'no_such_vm',
338 user: {email: 'foo@example.com'},
339 openid_prefix: 'https://www.google.com/accounts/o8/id'
342 response_body = JSON.parse(@response.body)
343 response_errors = response_body['errors']
344 assert_not_nil response_errors, 'Expected error in response'
345 assert (response_errors.first.include? "No vm found for no_such_vm"),
346 'Expected RuntimeError: No vm found for no_such_vm'
349 test "setup user with valid email, repo and real vm as input" do
350 authorize_with :admin
353 repo_name: 'test_repo',
354 openid_prefix: 'https://www.google.com/accounts/o8/id',
356 user: {email: 'foo@example.com'}
359 assert_response :success
360 response_items = JSON.parse(@response.body)['items']
361 response_object = find_obj_in_resp response_items, 'User', nil
362 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
363 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
365 # five extra links; system_group, login, group, vm, repo
366 verify_num_links @all_links_at_start, 5
369 test "setup user with valid email, no vm and repo as input" do
370 authorize_with :admin
373 user: {email: 'foo@example.com'},
374 openid_prefix: 'https://www.google.com/accounts/o8/id'
377 assert_response :success
378 response_items = JSON.parse(@response.body)['items']
379 response_object = find_obj_in_resp response_items, 'User', nil
380 assert_not_nil response_object['uuid'], 'expected uuid for new user'
381 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
383 # three extra links; system_group, login, and group
384 verify_num_links @all_links_at_start, 3
387 test "setup user with email, first name, repo name and vm uuid" do
388 authorize_with :admin
391 openid_prefix: 'https://www.google.com/accounts/o8/id',
392 repo_name: 'test_repo',
395 first_name: 'test_first_name',
396 email: 'foo@example.com'
400 assert_response :success
401 response_items = JSON.parse(@response.body)['items']
402 response_object = find_obj_in_resp response_items, 'User', nil
403 assert_not_nil response_object['uuid'], 'expected uuid for new user'
404 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
405 assert_equal 'test_first_name', response_object['first_name'],
406 'expecting first name'
408 # five extra links; system_group, login, group, repo and vm
409 verify_num_links @all_links_at_start, 5
412 test "setup user twice with email and check two different objects created" do
413 authorize_with :admin
416 openid_prefix: 'https://www.google.com/accounts/o8/id',
417 repo_name: 'test_repo',
419 email: 'foo@example.com'
423 assert_response :success
424 response_items = JSON.parse(@response.body)['items']
425 response_object = find_obj_in_resp response_items, 'User', nil
426 assert_not_nil response_object['uuid'], 'expected uuid for new user'
427 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
428 # system_group, openid, group, and repo. No vm link.
429 verify_num_links @all_links_at_start, 4
433 user: {email: 'foo@example.com'},
434 openid_prefix: 'https://www.google.com/accounts/o8/id'
437 assert_response :success
438 response_items = JSON.parse(@response.body)['items']
439 response_object2 = find_obj_in_resp response_items, 'User', nil
440 assert_not_equal response_object['uuid'], response_object2['uuid'],
441 'expected same uuid as first create operation'
442 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
444 # +1 extra can_read 'all users' group link
445 # +1 extra system_group can_manage link pointing to the new User
446 # +1 extra can_login permission link
447 # no repo link, no vm link
448 verify_num_links @all_links_at_start, 7
451 test "setup user with openid prefix" do
452 authorize_with :admin
455 repo_name: 'test_repo',
456 openid_prefix: 'http://www.example.com/account',
458 first_name: "in_create_test_first_name",
459 last_name: "test_last_name",
460 email: "foo@example.com"
464 assert_response :success
466 response_items = JSON.parse(@response.body)['items']
467 created = find_obj_in_resp response_items, 'User', nil
469 assert_equal 'in_create_test_first_name', created['first_name']
470 assert_not_nil created['uuid'], 'expected uuid for new user'
471 assert_not_nil created['email'], 'expected non-nil email'
472 assert_nil created['identity_url'], 'expected no identity_url'
475 # four new links: system_group, arvados#user, repo, and 'All users' group.
476 verify_num_links @all_links_at_start, 4
478 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
479 created['uuid'], created['email'], 'arvados#user', false, 'User'
481 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
482 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
484 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
485 'All users', created['uuid'], 'arvados#group', true, 'Group'
487 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
488 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
491 test "invoke setup with no openid prefix, expect error" do
492 authorize_with :admin
495 repo_name: 'test_repo',
497 first_name: "in_create_test_first_name",
498 last_name: "test_last_name",
499 email: "foo@example.com"
503 response_body = JSON.parse(@response.body)
504 response_errors = response_body['errors']
505 assert_not_nil response_errors, 'Expected error in response'
506 assert (response_errors.first.include? 'openid_prefix parameter is missing'),
507 'Expected ArgumentError'
510 test "setup user with user, vm and repo and verify links" do
511 authorize_with :admin
515 first_name: "in_create_test_first_name",
516 last_name: "test_last_name",
517 email: "foo@example.com"
520 repo_name: 'test_repo',
521 openid_prefix: 'https://www.google.com/accounts/o8/id'
524 assert_response :success
526 response_items = JSON.parse(@response.body)['items']
527 created = find_obj_in_resp response_items, 'User', nil
529 assert_equal 'in_create_test_first_name', created['first_name']
530 assert_not_nil created['uuid'], 'expected uuid for new user'
531 assert_not_nil created['email'], 'expected non-nil email'
532 assert_nil created['identity_url'], 'expected no identity_url'
534 # five new links: system_group, arvados#user, repo, vm and 'All
536 verify_num_links @all_links_at_start, 5
538 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
539 created['uuid'], created['email'], 'arvados#user', false, 'User'
541 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
542 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
544 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
545 'All users', created['uuid'], 'arvados#group', true, 'Group'
547 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
548 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
551 test "create user as non admin user and expect error" do
552 authorize_with :active
555 user: {email: 'foo@example.com'}
558 response_body = JSON.parse(@response.body)
559 response_errors = response_body['errors']
560 assert_not_nil response_errors, 'Expected error in response'
561 assert (response_errors.first.include? 'PermissionDenied'),
562 'Expected PermissionDeniedError'
565 test "setup user as non admin user and expect error" do
566 authorize_with :active
569 openid_prefix: 'https://www.google.com/accounts/o8/id',
570 user: {email: 'foo@example.com'}
573 response_body = JSON.parse(@response.body)
574 response_errors = response_body['errors']
575 assert_not_nil response_errors, 'Expected error in response'
576 assert (response_errors.first.include? 'Forbidden'),
577 'Expected Forbidden error'
580 test "setup user in multiple steps and verify response" do
581 authorize_with :admin
584 openid_prefix: 'http://www.example.com/account',
586 email: "foo@example.com"
590 assert_response :success
591 response_items = JSON.parse(@response.body)['items']
592 created = find_obj_in_resp response_items, 'User', nil
594 assert_not_nil created['uuid'], 'expected uuid for new user'
595 assert_not_nil created['email'], 'expected non-nil email'
596 assert_equal created['email'], 'foo@example.com', 'expected input email'
598 # three new links: system_group, arvados#user, and 'All users' group.
599 verify_num_links @all_links_at_start, 3
601 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
602 created['uuid'], created['email'], 'arvados#user', false, 'User'
604 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
605 'All users', created['uuid'], 'arvados#group', true, 'Group'
607 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
608 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
610 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
611 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
613 # invoke setup with a repository
615 openid_prefix: 'http://www.example.com/account',
616 repo_name: 'new_repo',
617 uuid: created['uuid']
620 assert_response :success
622 response_items = JSON.parse(@response.body)['items']
623 created = find_obj_in_resp response_items, 'User', nil
625 assert_equal 'foo@example.com', created['email'], 'expected input email'
628 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
629 'All users', created['uuid'], 'arvados#group', true, 'Group'
631 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
632 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
634 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
635 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
637 # invoke setup with a vm_uuid
640 openid_prefix: 'http://www.example.com/account',
644 uuid: created['uuid']
647 assert_response :success
649 response_items = JSON.parse(@response.body)['items']
650 created = find_obj_in_resp response_items, 'User', nil
652 assert_equal created['email'], 'foo@example.com', 'expected original email'
655 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
656 'All users', created['uuid'], 'arvados#group', true, 'Group'
658 # since no repo name in input, we won't get any; even though user has one
659 verify_link response_items, 'arvados#repository', false, 'permission', 'can_write',
660 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
662 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
663 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
666 test "setup and unsetup user" do
667 authorize_with :admin
670 repo_name: 'test_repo',
672 user: {email: 'foo@example.com'},
673 openid_prefix: 'https://www.google.com/accounts/o8/id'
676 assert_response :success
677 response_items = JSON.parse(@response.body)['items']
678 created = find_obj_in_resp response_items, 'User', nil
679 assert_not_nil created['uuid'], 'expected uuid for the new user'
680 assert_equal created['email'], 'foo@example.com', 'expected given email'
682 # five extra links: system_group, login, group, repo and vm
683 verify_num_links @all_links_at_start, 5
685 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
686 created['uuid'], created['email'], 'arvados#user', false, 'User'
688 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
689 'All users', created['uuid'], 'arvados#group', true, 'Group'
691 verify_link response_items, 'arvados#repository', true, 'permission', 'can_write',
692 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
694 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
695 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
697 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
699 # now unsetup this user
700 post :unsetup, id: created['uuid']
701 assert_response :success
703 created2 = JSON.parse(@response.body)
704 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
705 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
707 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
710 test "unsetup active user" do
711 authorize_with :active
713 assert_response :success
714 active_user = JSON.parse(@response.body)
715 assert_not_nil active_user['uuid'], 'expected uuid for the active user'
716 assert active_user['is_active'], 'expected is_active for active user'
717 assert active_user['is_invited'], 'expected is_invited for active user'
719 verify_link_existence active_user['uuid'], active_user['email'],
720 false, false, false, true, true
722 authorize_with :admin
724 # now unsetup this user
725 post :unsetup, id: active_user['uuid']
726 assert_response :success
728 response_user = JSON.parse(@response.body)
729 assert_not_nil response_user['uuid'], 'expected uuid for the upsetup user'
730 assert_equal active_user['uuid'], response_user['uuid'], 'expected uuid not found'
731 assert !response_user['is_active'], 'expected user to be inactive'
732 assert !response_user['is_invited'], 'expected user to be uninvited'
734 verify_link_existence response_user['uuid'], response_user['email'],
735 false, false, false, false, false
738 test "setup user with send notification param false and verify no email" do
739 authorize_with :admin
742 openid_prefix: 'http://www.example.com/account',
743 send_notification_email: 'false',
745 email: "foo@example.com"
749 assert_response :success
750 response_items = JSON.parse(@response.body)['items']
751 created = find_obj_in_resp response_items, 'User', nil
752 assert_not_nil created['uuid'], 'expected uuid for the new user'
753 assert_equal created['email'], 'foo@example.com', 'expected given email'
755 setup_email = ActionMailer::Base.deliveries.last
756 assert_nil setup_email, 'expected no setup email'
759 test "setup user with send notification param true and verify email" do
760 authorize_with :admin
763 openid_prefix: 'http://www.example.com/account',
764 send_notification_email: 'true',
766 email: "foo@example.com"
770 assert_response :success
771 response_items = JSON.parse(@response.body)['items']
772 created = find_obj_in_resp response_items, 'User', nil
773 assert_not_nil created['uuid'], 'expected uuid for the new user'
774 assert_equal created['email'], 'foo@example.com', 'expected given email'
776 setup_email = ActionMailer::Base.deliveries.last
777 assert_not_nil setup_email, 'Expected email after setup'
779 assert_equal Rails.configuration.user_notifier_email_from, setup_email.from[0]
780 assert_equal 'foo@example.com', setup_email.to[0]
781 assert_equal 'Welcome to Curoverse', setup_email.subject
782 assert (setup_email.body.to_s.include? 'Your Arvados account has been set up'),
783 'Expected Your Arvados account has been set up in email body'
784 assert (setup_email.body.to_s.include? 'foo@example.com'),
785 'Expected user email in email body'
786 assert (setup_email.body.to_s.include? Rails.configuration.workbench_address),
787 'Expected workbench url in email body'
790 def verify_num_links (original_links, expected_additional_links)
792 assert_equal expected_additional_links, Link.all.size-original_links.size,
793 "Expected #{expected_additional_links.inspect} more links"
796 def find_obj_in_resp (response_items, object_type, head_kind=nil)
798 response_items.each { |x|
803 if object_type == 'User'
804 if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
808 else # looking for a link
809 if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind
818 def verify_link(response_items, link_object_name, expect_link, link_class,
819 link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
821 link = find_obj_in_resp response_items, 'Link', link_object_name
824 assert_nil link, "Expected no link for #{link_object_name}"
828 assert_not_nil link, "Expected link for #{link_object_name}"
831 object = Object.const_get(class_name).where(name: head_uuid)
832 assert [] != object, "expected #{class_name} with name #{head_uuid}"
833 head_uuid = object.first[:uuid]
835 assert_equal link_class, link['link_class'],
836 "did not find expected link_class for #{link_object_name}"
838 assert_equal link_name, link['name'],
839 "did not find expected link_name for #{link_object_name}"
841 assert_equal tail_uuid, link['tail_uuid'],
842 "did not find expected tail_uuid for #{link_object_name}"
844 assert_equal head_kind, link['head_kind'],
845 "did not find expected head_kind for #{link_object_name}"
847 assert_equal head_uuid, link['head_uuid'],
848 "did not find expected head_uuid for #{link_object_name}"
851 def verify_link_existence uuid, email, expect_oid_login_perms,
852 expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
853 # verify that all links are deleted for the user
854 oid_login_perms = Link.where(tail_uuid: email,
855 link_class: 'permission',
856 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
857 if expect_oid_login_perms
858 assert oid_login_perms.any?, "expected oid_login_perms"
860 assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
863 repo_perms = Link.where(tail_uuid: uuid,
864 link_class: 'permission',
865 name: 'can_write').where("head_uuid like ?", Repository.uuid_like_pattern)
867 assert repo_perms.any?, "expected repo_perms"
869 assert !repo_perms.any?, "expected all repo_perms deleted"
872 vm_login_perms = Link.where(tail_uuid: uuid,
873 link_class: 'permission',
874 name: 'can_login').where("head_uuid like ?", VirtualMachine.uuid_like_pattern)
876 assert vm_login_perms.any?, "expected vm_login_perms"
878 assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
881 group = Group.where(name: 'All users').select do |g|
882 g[:uuid].match /-f+$/
884 group_read_perms = Link.where(tail_uuid: uuid,
885 head_uuid: group[:uuid],
886 link_class: 'permission',
888 if expect_group_perms
889 assert group_read_perms.any?, "expected all users group read perms"
891 assert !group_read_perms.any?, "expected all users group perm deleted"
894 signed_uuids = Link.where(link_class: 'signature',
898 assert signed_uuids.any?, "expected signatures"
900 assert !signed_uuids.any?, "expected all signatures deleted"
905 def verify_system_group_permission_link_for user_uuid
906 assert_equal 1, Link.where(link_class: 'permission',
908 tail_uuid: system_group_uuid,
909 head_uuid: user_uuid).count
912 test 'get user-owned objects' do
913 authorize_with :active
915 id: users(:active).uuid,
919 assert_response :success
920 assert_operator 2, :<=, json_response['items_available']
921 assert_operator 2, :<=, json_response['items'].count
922 kinds = json_response['items'].collect { |i| i['kind'] }.uniq
923 expect_kinds = %w'arvados#group arvados#specimen arvados#pipelineTemplate arvados#job'
924 assert_equal expect_kinds, (expect_kinds & kinds)
927 [false, true].each do |inc_ind|
928 test "get all pages of user-owned #{'and -linked ' if inc_ind}objects" do
929 authorize_with :active
932 items_available = nil
936 # Behaving badly here, using the same controller multiple
937 # times within a test.
940 id: users(:active).uuid,
941 include_linked: inc_ind,
946 assert_response :success
947 assert_operator(0, :<, json_response['items'].count,
948 "items_available=#{items_available} but received 0 "\
949 "items with offset=#{offset}")
950 items_available ||= json_response['items_available']
951 assert_equal(items_available, json_response['items_available'],
952 "items_available changed between page #{offset/limit} "\
953 "and page #{1+offset/limit}")
954 json_response['items'].each do |item|
956 assert_equal(nil, uuid_received[uuid],
957 "Received '#{uuid}' again on page #{1+offset/limit}")
958 uuid_received[uuid] = true
959 owner_received[item['owner_uuid']] = true
962 assert_equal users(:active).uuid, item['owner_uuid']
965 break if offset >= items_available
968 assert_operator 0, :<, (json_response.keys - [users(:active).uuid]).count,
969 "Set include_linked=true but did not receive any non-owned items"
974 %w(offset limit).each do |arg|
975 ['foo', '', '1234five', '0x10', '-8'].each do |val|
976 test "Raise error on bogus #{arg} parameter #{val.inspect}" do
977 authorize_with :active
979 :id => users(:active).uuid,