2 require 'helpers/users_test_helper'
4 class UsersTest < ActionDispatch::IntegrationTest
5 include UsersTestHelper
7 test "setup user multiple times" do
8 repo_name = 'usertestrepo'
10 post "/arvados/v1/users/setup", {
12 openid_prefix: 'https://www.google.com/accounts/o8/id',
14 uuid: 'zzzzz-tpzed-abcdefghijklmno',
15 first_name: "in_create_test_first_name",
16 last_name: "test_last_name",
17 email: "foo@example.com"
21 assert_response :success
23 response_items = json_response['items']
25 created = find_obj_in_resp response_items, 'arvados#user', nil
27 assert_equal 'in_create_test_first_name', created['first_name']
28 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
29 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
30 assert_not_nil created['email'], 'expected non-nil email'
31 assert_nil created['identity_url'], 'expected no identity_url'
33 # arvados#user, repo link and link add user to 'All users' group
34 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
35 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
37 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
38 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
40 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
41 'All users', created['uuid'], 'arvados#group', true, 'Group'
43 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
44 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
46 verify_system_group_permission_link_for created['uuid']
48 # invoke setup again with the same data
49 post "/arvados/v1/users/setup", {
51 vm_uuid: virtual_machines(:testvm).uuid,
52 openid_prefix: 'https://www.google.com/accounts/o8/id',
54 uuid: 'zzzzz-tpzed-abcdefghijklmno',
55 first_name: "in_create_test_first_name",
56 last_name: "test_last_name",
57 email: "foo@example.com"
61 assert_response :success
63 response_items = json_response['items']
65 created = find_obj_in_resp response_items, 'arvados#user', nil
66 assert_equal 'in_create_test_first_name', created['first_name']
67 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
68 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
69 assert_not_nil created['email'], 'expected non-nil email'
70 assert_nil created['identity_url'], 'expected no identity_url'
72 # arvados#user, repo link and link add user to 'All users' group
73 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
74 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
76 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
77 'All users', created['uuid'], 'arvados#group', true, 'Group'
79 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
80 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
82 verify_system_group_permission_link_for created['uuid']
85 test "setup user in multiple steps and verify response" do
86 post "/arvados/v1/users/setup", {
87 openid_prefix: 'http://www.example.com/account',
89 email: "foo@example.com"
93 assert_response :success
94 response_items = json_response['items']
95 created = find_obj_in_resp response_items, 'arvados#user', nil
97 assert_not_nil created['uuid'], 'expected uuid for new user'
98 assert_not_nil created['email'], 'expected non-nil email'
99 assert_equal created['email'], 'foo@example.com', 'expected input email'
101 # three new links: system_group, arvados#user, and 'All users' group.
102 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
103 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
105 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
106 'All users', created['uuid'], 'arvados#group', true, 'Group'
108 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
109 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
111 # invoke setup with a repository
112 post "/arvados/v1/users/setup", {
113 openid_prefix: 'http://www.example.com/account',
114 repo_name: 'newusertestrepo',
115 uuid: created['uuid']
118 assert_response :success
120 response_items = json_response['items']
121 created = find_obj_in_resp response_items, 'arvados#user', nil
123 assert_equal 'foo@example.com', created['email'], 'expected input email'
126 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
127 'All users', created['uuid'], 'arvados#group', true, 'Group'
129 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
130 'foo/newusertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
132 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
133 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
135 # invoke setup with a vm_uuid
136 post "/arvados/v1/users/setup", {
137 vm_uuid: virtual_machines(:testvm).uuid,
138 openid_prefix: 'http://www.example.com/account',
142 uuid: created['uuid']
145 assert_response :success
147 response_items = json_response['items']
148 created = find_obj_in_resp response_items, 'arvados#user', nil
150 assert_equal created['email'], 'foo@example.com', 'expected original email'
153 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
154 'All users', created['uuid'], 'arvados#group', true, 'Group'
156 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
157 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
160 test "setup and unsetup user" do
161 post "/arvados/v1/users/setup", {
162 repo_name: 'newusertestrepo',
163 vm_uuid: virtual_machines(:testvm).uuid,
164 user: {email: 'foo@example.com'},
165 openid_prefix: 'https://www.google.com/accounts/o8/id'
168 assert_response :success
169 response_items = json_response['items']
170 created = find_obj_in_resp response_items, 'arvados#user', nil
171 assert_not_nil created['uuid'], 'expected uuid for the new user'
172 assert_equal created['email'], 'foo@example.com', 'expected given email'
174 # five extra links: system_group, login, group, repo and vm
175 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
176 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
178 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
179 'All users', created['uuid'], 'arvados#group', true, 'Group'
181 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
182 'foo/newusertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
184 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
185 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
187 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
189 post "/arvados/v1/users/#{created['uuid']}/unsetup", {}, auth(:admin)
191 assert_response :success
193 created2 = json_response
194 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
195 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
197 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
200 def find_obj_in_resp (response_items, kind, head_kind=nil)
201 response_items.each do |x|
203 return x if (x['kind'] == kind && x['head_kind'] == head_kind)