1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 require 'helpers/users_test_helper'
8 class Arvados::V1::UsersControllerTest < ActionController::TestCase
9 include CurrentApiClient
10 include UsersTestHelper
13 @initial_link_count = Link.count
14 @vm_uuid = virtual_machines(:testvm).uuid
15 ActionMailer::Base.deliveries = []
18 test "activate a user after signing UA" do
19 authorize_with :inactive_but_signed_user_agreement
20 post :activate, id: users(:inactive_but_signed_user_agreement).uuid
21 assert_response :success
22 assert_not_nil assigns(:object)
23 me = JSON.parse(@response.body)
24 assert_equal true, me['is_active']
27 test "refuse to activate a user before signing UA" do
29 required_uuids = Link.where("owner_uuid = ? and link_class = ? and name = ? and tail_uuid = ? and head_uuid like ?",
34 Collection.uuid_like_pattern).
37 assert required_uuids.length > 0
39 signed_uuids = Link.where(owner_uuid: system_user_uuid,
40 link_class: 'signature',
42 tail_uuid: users(:inactive).uuid,
43 head_uuid: required_uuids).
46 assert_equal 0, signed_uuids.length
49 authorize_with :inactive
50 assert_equal false, users(:inactive).is_active
52 post :activate, id: users(:inactive).uuid
56 assert resp['errors'].first.include? 'Cannot activate without user agreements'
57 assert_nil resp['is_active']
60 test "activate an already-active user" do
61 authorize_with :active
62 post :activate, id: users(:active).uuid
63 assert_response :success
64 me = JSON.parse(@response.body)
65 assert_equal true, me['is_active']
68 test "respond 401 if given token exists but user record is missing" do
69 authorize_with :valid_token_deleted_user
70 get :current, {format: :json}
74 test "create new user with user as input" do
77 first_name: "test_first_name",
78 last_name: "test_last_name",
79 email: "foo@example.com"
81 assert_response :success
82 created = JSON.parse(@response.body)
83 assert_equal 'test_first_name', created['first_name']
84 assert_not_nil created['uuid'], 'expected uuid for the newly created user'
85 assert_not_nil created['email'], 'expected non-nil email'
86 assert_nil created['identity_url'], 'expected no identity_url'
89 test "create user with user, vm and repo as input" do
91 repo_name = 'usertestrepo'
95 openid_prefix: 'https://www.google.com/accounts/o8/id',
97 uuid: 'zzzzz-tpzed-abcdefghijklmno',
98 first_name: "in_create_test_first_name",
99 last_name: "test_last_name",
100 email: "foo@example.com"
103 assert_response :success
104 response_items = JSON.parse(@response.body)['items']
106 created = find_obj_in_resp response_items, 'User', nil
108 assert_equal 'in_create_test_first_name', created['first_name']
109 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
110 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
111 assert_not_nil created['email'], 'expected non-nil email'
112 assert_nil created['identity_url'], 'expected no identity_url'
114 # arvados#user, repo link and link add user to 'All users' group
117 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
118 created['uuid'], created['email'], 'arvados#user', false, 'User'
120 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
121 "foo/#{repo_name}", created['uuid'], 'arvados#repository', true, 'Repository'
123 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
124 'All users', created['uuid'], 'arvados#group', true, 'Group'
126 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
127 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
129 verify_system_group_permission_link_for created['uuid']
132 test "setup user with bogus uuid and expect error" do
133 authorize_with :admin
137 repo_name: 'usertestrepo',
140 response_body = JSON.parse(@response.body)
141 response_errors = response_body['errors']
142 assert_not_nil response_errors, 'Expected error in response'
143 assert (response_errors.first.include? 'Path not found'), 'Expected 404'
146 test "setup user with bogus uuid in user and expect error" do
147 authorize_with :admin
150 user: {uuid: 'bogus_uuid'},
151 repo_name: 'usertestrepo',
153 openid_prefix: 'https://www.google.com/accounts/o8/id'
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? 'ArgumentError: Require user email'),
159 'Expected RuntimeError'
162 test "setup user with no uuid and user, expect error" do
163 authorize_with :admin
166 repo_name: 'usertestrepo',
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? 'Required uuid or user'),
174 'Expected ArgumentError'
177 test "setup user with no uuid and email, expect error" do
178 authorize_with :admin
182 repo_name: 'usertestrepo',
184 openid_prefix: 'https://www.google.com/accounts/o8/id'
186 response_body = JSON.parse(@response.body)
187 response_errors = response_body['errors']
188 assert_not_nil response_errors, 'Expected error in response'
189 assert (response_errors.first.include? '<ArgumentError: Require user email'),
190 'Expected ArgumentError'
193 test "invoke setup with existing uuid, vm and repo and verify links" do
194 authorize_with :admin
195 inactive_user = users(:inactive)
198 uuid: users(:inactive).uuid,
199 repo_name: 'usertestrepo',
203 assert_response :success
205 response_items = JSON.parse(@response.body)['items']
206 resp_obj = find_obj_in_resp response_items, 'User', nil
208 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
209 assert_equal inactive_user['uuid'], resp_obj['uuid']
210 assert_equal inactive_user['email'], resp_obj['email'],
211 'expecting inactive user email'
213 # expect repo and vm links
214 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
215 'inactiveuser/usertestrepo', resp_obj['uuid'], 'arvados#repository', true, 'Repository'
217 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
218 @vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
221 test "invoke setup with existing uuid but different email, expect original email" do
222 authorize_with :admin
223 inactive_user = users(:inactive)
226 uuid: inactive_user['uuid'],
227 user: {email: 'junk_email'}
230 assert_response :success
232 response_items = JSON.parse(@response.body)['items']
233 resp_obj = find_obj_in_resp response_items, 'User', nil
235 assert_not_nil resp_obj['uuid'], 'expected uuid for the new user'
236 assert_equal inactive_user['uuid'], resp_obj['uuid']
237 assert_equal inactive_user['email'], resp_obj['email'],
238 'expecting inactive user email'
241 test "setup user with valid email and repo as input" do
242 authorize_with :admin
245 repo_name: 'usertestrepo',
246 user: {email: 'foo@example.com'},
247 openid_prefix: 'https://www.google.com/accounts/o8/id'
250 assert_response :success
251 response_items = JSON.parse(@response.body)['items']
252 response_object = find_obj_in_resp response_items, 'User', nil
253 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
254 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
256 # four extra links; system_group, login, group and repo perms
260 test "setup user with fake vm and expect error" do
261 authorize_with :admin
264 repo_name: 'usertestrepo',
265 vm_uuid: 'no_such_vm',
266 user: {email: 'foo@example.com'},
267 openid_prefix: 'https://www.google.com/accounts/o8/id'
270 response_body = JSON.parse(@response.body)
271 response_errors = response_body['errors']
272 assert_not_nil response_errors, 'Expected error in response'
273 assert (response_errors.first.include? "No vm found for no_such_vm"),
274 'Expected RuntimeError: No vm found for no_such_vm'
277 test "setup user with valid email, repo and real vm as input" do
278 authorize_with :admin
281 repo_name: 'usertestrepo',
282 openid_prefix: 'https://www.google.com/accounts/o8/id',
284 user: {email: 'foo@example.com'}
287 assert_response :success
288 response_items = JSON.parse(@response.body)['items']
289 response_object = find_obj_in_resp response_items, 'User', nil
290 assert_not_nil response_object['uuid'], 'expected uuid for the new user'
291 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
293 # five extra links; system_group, login, group, vm, repo
297 test "setup user with valid email, no vm and no repo as input" do
298 authorize_with :admin
301 user: {email: 'foo@example.com'},
302 openid_prefix: 'https://www.google.com/accounts/o8/id'
305 assert_response :success
306 response_items = JSON.parse(@response.body)['items']
307 response_object = find_obj_in_resp response_items, 'User', nil
308 assert_not_nil response_object['uuid'], 'expected uuid for new user'
309 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
311 # three extra links; system_group, login, and group
314 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
315 response_object['uuid'], response_object['email'], 'arvados#user', false, 'User'
317 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
318 'All users', response_object['uuid'], 'arvados#group', true, 'Group'
320 verify_link response_items, 'arvados#repository', false, 'permission', 'can_manage',
321 'foo/usertestrepo', response_object['uuid'], 'arvados#repository', true, 'Repository'
323 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
324 nil, response_object['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
327 test "setup user with email, first name, repo name and vm uuid" do
328 authorize_with :admin
331 openid_prefix: 'https://www.google.com/accounts/o8/id',
332 repo_name: 'usertestrepo',
335 first_name: 'test_first_name',
336 email: 'foo@example.com'
340 assert_response :success
341 response_items = JSON.parse(@response.body)['items']
342 response_object = find_obj_in_resp response_items, 'User', nil
343 assert_not_nil response_object['uuid'], 'expected uuid for new user'
344 assert_equal response_object['email'], 'foo@example.com', 'expected given email'
345 assert_equal 'test_first_name', response_object['first_name'],
346 'expecting first name'
348 # five extra links; system_group, login, group, repo and vm
352 test "setup user with an existing user email and check different object is created" do
353 authorize_with :admin
354 inactive_user = users(:inactive)
357 openid_prefix: 'https://www.google.com/accounts/o8/id',
358 repo_name: 'usertestrepo',
360 email: inactive_user['email']
364 assert_response :success
365 response_items = JSON.parse(@response.body)['items']
366 response_object = find_obj_in_resp response_items, 'User', nil
367 assert_not_nil response_object['uuid'], 'expected uuid for new user'
368 assert_not_equal response_object['uuid'], inactive_user['uuid'],
369 'expected different uuid after create operation'
370 assert_equal inactive_user['email'], response_object['email'], 'expected given email'
371 # system_group, openid, group, and repo. No vm link.
375 test "setup user with openid prefix" do
376 authorize_with :admin
379 repo_name: 'usertestrepo',
380 openid_prefix: 'http://www.example.com/account',
382 first_name: "in_create_test_first_name",
383 last_name: "test_last_name",
384 email: "foo@example.com"
388 assert_response :success
390 response_items = JSON.parse(@response.body)['items']
391 created = find_obj_in_resp response_items, 'User', nil
393 assert_equal 'in_create_test_first_name', created['first_name']
394 assert_not_nil created['uuid'], 'expected uuid for new user'
395 assert_not_nil created['email'], 'expected non-nil email'
396 assert_nil created['identity_url'], 'expected no identity_url'
399 # four new links: system_group, arvados#user, repo, and 'All users' group.
402 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
403 created['uuid'], created['email'], 'arvados#user', false, 'User'
405 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
406 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
408 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
409 'All users', created['uuid'], 'arvados#group', true, 'Group'
411 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
412 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
415 test "invoke setup with no openid prefix, expect error" do
416 authorize_with :admin
419 repo_name: 'usertestrepo',
421 first_name: "in_create_test_first_name",
422 last_name: "test_last_name",
423 email: "foo@example.com"
427 response_body = JSON.parse(@response.body)
428 response_errors = response_body['errors']
429 assert_not_nil response_errors, 'Expected error in response'
430 assert (response_errors.first.include? 'openid_prefix parameter is missing'),
431 'Expected ArgumentError'
434 test "setup user with user, vm and repo and verify links" do
435 authorize_with :admin
439 first_name: "in_create_test_first_name",
440 last_name: "test_last_name",
441 email: "foo@example.com"
444 repo_name: 'usertestrepo',
445 openid_prefix: 'https://www.google.com/accounts/o8/id'
448 assert_response :success
450 response_items = JSON.parse(@response.body)['items']
451 created = find_obj_in_resp response_items, 'User', nil
453 assert_equal 'in_create_test_first_name', created['first_name']
454 assert_not_nil created['uuid'], 'expected uuid for new user'
455 assert_not_nil created['email'], 'expected non-nil email'
456 assert_nil created['identity_url'], 'expected no identity_url'
458 # five new links: system_group, arvados#user, repo, vm and 'All
462 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
463 created['uuid'], created['email'], 'arvados#user', false, 'User'
465 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
466 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
468 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
469 'All users', created['uuid'], 'arvados#group', true, 'Group'
471 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
472 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
475 test "create user as non admin user and expect error" do
476 authorize_with :active
479 user: {email: 'foo@example.com'}
482 response_body = JSON.parse(@response.body)
483 response_errors = response_body['errors']
484 assert_not_nil response_errors, 'Expected error in response'
485 assert (response_errors.first.include? 'PermissionDenied'),
486 'Expected PermissionDeniedError'
489 test "setup user as non admin user and expect error" do
490 authorize_with :active
493 openid_prefix: 'https://www.google.com/accounts/o8/id',
494 user: {email: 'foo@example.com'}
497 response_body = JSON.parse(@response.body)
498 response_errors = response_body['errors']
499 assert_not_nil response_errors, 'Expected error in response'
500 assert (response_errors.first.include? 'Forbidden'),
501 'Expected Forbidden error'
504 test "setup active user with repo and no vm" do
505 authorize_with :admin
506 active_user = users(:active)
508 # invoke setup with a repository
510 repo_name: 'usertestrepo',
511 uuid: active_user['uuid']
514 assert_response :success
516 response_items = JSON.parse(@response.body)['items']
517 created = find_obj_in_resp response_items, 'User', nil
519 assert_equal active_user[:email], created['email'], 'expected input email'
522 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
523 'All users', created['uuid'], 'arvados#group', true, 'Group'
525 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
526 'active/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
528 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
529 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
532 test "setup active user with vm and no repo" do
533 authorize_with :admin
534 active_user = users(:active)
535 repos_query = Repository.where(owner_uuid: active_user.uuid)
536 repo_link_query = Link.where(tail_uuid: active_user.uuid,
537 link_class: "permission", name: "can_manage")
538 repos_count = repos_query.count
539 repo_link_count = repo_link_query.count
541 # invoke setup with a repository
544 uuid: active_user['uuid'],
548 assert_response :success
550 response_items = JSON.parse(@response.body)['items']
551 created = find_obj_in_resp response_items, 'User', nil
553 assert_equal active_user['email'], created['email'], 'expected original email'
556 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
557 'All users', created['uuid'], 'arvados#group', true, 'Group'
559 assert_equal(repos_count, repos_query.count)
560 assert_equal(repo_link_count, repo_link_query.count)
562 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
563 @vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
566 test "unsetup active user" do
567 active_user = users(:active)
568 assert_not_nil active_user['uuid'], 'expected uuid for the active user'
569 assert active_user['is_active'], 'expected is_active for active user'
571 verify_link_existence active_user['uuid'], active_user['email'],
572 false, true, true, true, true
574 authorize_with :admin
576 # now unsetup this user
577 post :unsetup, id: active_user['uuid']
578 assert_response :success
580 response_user = JSON.parse(@response.body)
581 assert_not_nil response_user['uuid'], 'expected uuid for the upsetup user'
582 assert_equal active_user['uuid'], response_user['uuid'], 'expected uuid not found'
583 assert !response_user['is_active'], 'expected user to be inactive'
584 assert !response_user['is_invited'], 'expected user to be uninvited'
586 verify_link_existence response_user['uuid'], response_user['email'],
587 false, false, false, false, false
589 active_user = User.find_by_uuid(users(:active).uuid)
590 readable_groups = active_user.groups_i_can(:read)
591 all_users_group = Group.all.collect(&:uuid).select { |g| g.match(/-f+$/) }
592 refute_includes(readable_groups, all_users_group,
593 "active user can read All Users group after being deactivated")
594 assert_equal(false, active_user.is_invited,
595 "active user is_invited after being deactivated & reloaded")
598 test "setup user with send notification param false and verify no email" do
599 authorize_with :admin
602 openid_prefix: 'http://www.example.com/account',
603 send_notification_email: 'false',
605 email: "foo@example.com"
609 assert_response :success
610 response_items = JSON.parse(@response.body)['items']
611 created = find_obj_in_resp response_items, 'User', nil
612 assert_not_nil created['uuid'], 'expected uuid for the new user'
613 assert_equal created['email'], 'foo@example.com', 'expected given email'
615 setup_email = ActionMailer::Base.deliveries.last
616 assert_nil setup_email, 'expected no setup email'
619 test "setup user with send notification param true and verify email" do
620 authorize_with :admin
623 openid_prefix: 'http://www.example.com/account',
624 send_notification_email: 'true',
626 email: "foo@example.com"
630 assert_response :success
631 response_items = JSON.parse(@response.body)['items']
632 created = find_obj_in_resp response_items, 'User', nil
633 assert_not_nil created['uuid'], 'expected uuid for the new user'
634 assert_equal created['email'], 'foo@example.com', 'expected given email'
636 setup_email = ActionMailer::Base.deliveries.last
637 assert_not_nil setup_email, 'Expected email after setup'
639 assert_equal Rails.configuration.user_notifier_email_from, setup_email.from[0]
640 assert_equal 'foo@example.com', setup_email.to[0]
641 assert_equal 'Welcome to Curoverse - shell account enabled', setup_email.subject
642 assert (setup_email.body.to_s.include? 'Your Arvados shell account has been set up'),
643 'Expected Your Arvados shell account has been set up in email body'
644 assert (setup_email.body.to_s.include? "#{Rails.configuration.workbench_address}users/#{created['uuid']}/virtual_machines"), 'Expected virtual machines url in email body'
647 test "setup inactive user by changing is_active to true" do
648 authorize_with :admin
649 active_user = users(:active)
651 # invoke setup with a repository
653 id: active_user['uuid'],
658 assert_response :success
659 assert_equal active_user['uuid'], json_response['uuid']
660 updated = User.where(uuid: active_user['uuid']).first
661 assert_equal(true, updated.is_active)
662 assert_equal({read: true}, updated.group_permissions[all_users_group_uuid])
665 test "non-admin user can get basic information about readable users" do
666 authorize_with :spectator
668 check_non_admin_index
669 check_readable_users_index [:spectator], [:inactive, :active]
672 test "non-admin user gets only safe attributes from users#show" do
673 g = act_as_system_user do
676 users = create_list :active_user, 2, join_groups: [g]
677 token = create :token, user: users[0]
678 authorize_with_token token
679 get :show, id: users[1].uuid
683 [2, 4].each do |limit|
684 test "non-admin user can limit index to #{limit}" do
685 g = act_as_system_user do
688 users = create_list :active_user, 4, join_groups: [g]
689 token = create :token, user: users[0]
691 authorize_with_token token
692 get(:index, limit: limit)
693 check_non_admin_index
694 assert_equal(limit, json_response["items"].size,
695 "non-admin index limit was ineffective")
699 test "admin has full index powers" do
700 authorize_with :admin
701 check_inactive_user_findable
704 test "reader token can grant admin index powers" do
705 authorize_with :spectator
706 check_inactive_user_findable(reader_tokens: [api_token(:admin)])
709 test "admin can filter on user.is_active" do
710 authorize_with :admin
711 get(:index, filters: [["is_active", "=", "true"]])
712 assert_response :success
713 check_readable_users_index [:active, :spectator], [:inactive]
716 test "admin can search where user.is_active" do
717 authorize_with :admin
718 get(:index, where: {is_active: true})
719 assert_response :success
720 check_readable_users_index [:active, :spectator], [:inactive]
723 test "update active_no_prefs user profile and expect notification email" do
724 authorize_with :admin
727 id: users(:active_no_prefs).uuid,
729 prefs: {:profile => {'organization' => 'example.com'}}
732 assert_response :success
735 ActionMailer::Base.deliveries.andand.each do |email|
736 if email.subject == "Profile created by #{users(:active_no_prefs).email}"
741 assert_equal true, found_email, 'Expected email after creating profile'
744 test "update active_no_prefs_profile user profile and expect notification email" do
745 authorize_with :admin
748 user[:prefs] = users(:active_no_prefs_profile_no_getting_started_shown).prefs
749 user[:prefs][:profile] = {:profile => {'organization' => 'example.com'}}
751 id: users(:active_no_prefs_profile_no_getting_started_shown).uuid,
754 assert_response :success
757 ActionMailer::Base.deliveries.andand.each do |email|
758 if email.subject == "Profile created by #{users(:active_no_prefs_profile_no_getting_started_shown).email}"
763 assert_equal true, found_email, 'Expected email after creating profile'
766 test "update active user profile and expect no notification email" do
767 authorize_with :admin
770 id: users(:active).uuid,
772 prefs: {:profile => {'organization' => 'anotherexample.com'}}
775 assert_response :success
778 ActionMailer::Base.deliveries.andand.each do |email|
779 if email.subject == "Profile created by #{users(:active).email}"
784 assert_equal false, found_email, 'Expected no email after updating profile'
787 test "user API response includes writable_by" do
788 authorize_with :active
790 assert_response :success
791 assert_includes(json_response["writable_by"], users(:active).uuid,
792 "user's writable_by should include self")
793 assert_includes(json_response["writable_by"], users(:active).owner_uuid,
794 "user's writable_by should include its owner_uuid")
800 ].each do |auth_user, expect_success|
801 test "update_uuid as #{auth_user}" do
802 authorize_with auth_user
803 orig_uuid = users(:active).uuid
806 new_uuid: 'zbbbb-tpzed-abcde12345abcde',
809 assert_response :success
810 assert_empty User.where(uuid: orig_uuid)
813 assert_not_empty User.where(uuid: orig_uuid)
819 NON_ADMIN_USER_DATA = ["uuid", "kind", "is_active", "email", "first_name",
822 def check_non_admin_index
823 assert_response :success
824 response_items = json_response["items"]
825 assert_not_nil response_items
826 response_items.each do |user_data|
827 check_non_admin_item user_data
828 assert(user_data["is_active"], "non-admin index returned inactive user")
832 def check_non_admin_show
833 assert_response :success
834 check_non_admin_item json_response
837 def check_non_admin_item user_data
838 assert_equal(NON_ADMIN_USER_DATA, user_data.keys.sort,
839 "data in response had missing or extra attributes")
840 assert_equal("arvados#user", user_data["kind"])
844 def check_readable_users_index expect_present, expect_missing
845 response_uuids = json_response["items"].map { |u| u["uuid"] }
846 expect_present.each do |user_key|
847 assert_includes(response_uuids, users(user_key).uuid,
848 "#{user_key} missing from index")
850 expect_missing.each do |user_key|
851 refute_includes(response_uuids, users(user_key).uuid,
852 "#{user_key} included in index")
856 def check_inactive_user_findable(params={})
857 inactive_user = users(:inactive)
858 get(:index, params.merge(filters: [["email", "=", inactive_user.email]]))
859 assert_response :success
860 user_list = json_response["items"]
861 assert_equal(1, user_list.andand.count)
862 # This test needs to check a column non-admins have no access to,
863 # to ensure that admins see all user information.
864 assert_equal(inactive_user.identity_url, user_list.first["identity_url"],
865 "admin's filtered index did not return inactive user")
868 def verify_links_added more
869 assert_equal @initial_link_count+more, Link.count,
870 "Started with #{@initial_link_count} links, expected #{more} more"
873 def find_obj_in_resp (response_items, object_type, head_kind=nil)
875 response_items.each { |x|
880 if object_type == 'User'
881 if ArvadosModel::resource_class_for_uuid(x['uuid']) == User
885 else # looking for a link
886 if x['head_uuid'] and ArvadosModel::resource_class_for_uuid(x['head_uuid']).kind == head_kind