1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 require 'helpers/users_test_helper'
8 class UsersTest < ActionDispatch::IntegrationTest
9 include UsersTestHelper
11 test "setup user multiple times" do
12 repo_name = 'usertestrepo'
14 post "/arvados/v1/users/setup", {
16 openid_prefix: 'https://www.google.com/accounts/o8/id',
18 uuid: 'zzzzz-tpzed-abcdefghijklmno',
19 first_name: "in_create_test_first_name",
20 last_name: "test_last_name",
21 email: "foo@example.com"
25 assert_response :success
27 response_items = json_response['items']
29 created = find_obj_in_resp response_items, 'arvados#user', nil
31 assert_equal 'in_create_test_first_name', created['first_name']
32 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
33 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
34 assert_not_nil created['email'], 'expected non-nil email'
35 assert_nil created['identity_url'], 'expected no identity_url'
37 # arvados#user, repo link and link add user to 'All users' group
38 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
39 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
41 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
42 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
44 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
45 'All users', created['uuid'], 'arvados#group', true, 'Group'
47 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
48 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
50 verify_system_group_permission_link_for created['uuid']
52 # invoke setup again with the same data
53 post "/arvados/v1/users/setup", {
55 vm_uuid: virtual_machines(:testvm).uuid,
56 openid_prefix: 'https://www.google.com/accounts/o8/id',
58 uuid: 'zzzzz-tpzed-abcdefghijklmno',
59 first_name: "in_create_test_first_name",
60 last_name: "test_last_name",
61 email: "foo@example.com"
64 assert_response 422 # cannot create another user with same UUID
66 # invoke setup on the same user
67 post "/arvados/v1/users/setup", {
69 vm_uuid: virtual_machines(:testvm).uuid,
70 openid_prefix: 'https://www.google.com/accounts/o8/id',
71 uuid: 'zzzzz-tpzed-abcdefghijklmno',
74 response_items = json_response['items']
76 created = find_obj_in_resp response_items, 'arvados#user', nil
77 assert_equal 'in_create_test_first_name', created['first_name']
78 assert_not_nil created['uuid'], 'expected non-null uuid for the new user'
79 assert_equal 'zzzzz-tpzed-abcdefghijklmno', created['uuid']
80 assert_not_nil created['email'], 'expected non-nil email'
81 assert_nil created['identity_url'], 'expected no identity_url'
83 # arvados#user, repo link and link add user to 'All users' group
84 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
85 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
87 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
88 'All users', created['uuid'], 'arvados#group', true, 'Group'
90 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
91 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
93 verify_system_group_permission_link_for created['uuid']
96 test "setup user in multiple steps and verify response" do
97 post "/arvados/v1/users/setup", {
98 openid_prefix: 'http://www.example.com/account',
100 email: "foo@example.com"
104 assert_response :success
105 response_items = json_response['items']
106 created = find_obj_in_resp response_items, 'arvados#user', nil
108 assert_not_nil created['uuid'], 'expected uuid for new user'
109 assert_not_nil created['email'], 'expected non-nil email'
110 assert_equal created['email'], 'foo@example.com', 'expected input email'
112 # three new links: system_group, arvados#user, and 'All users' group.
113 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
114 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
116 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
117 'All users', created['uuid'], 'arvados#group', true, 'Group'
119 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
120 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
122 # invoke setup with a repository
123 post "/arvados/v1/users/setup", {
124 openid_prefix: 'http://www.example.com/account',
125 repo_name: 'newusertestrepo',
126 uuid: created['uuid']
129 assert_response :success
131 response_items = json_response['items']
132 created = find_obj_in_resp response_items, 'arvados#user', nil
134 assert_equal 'foo@example.com', created['email'], 'expected input email'
137 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
138 'All users', created['uuid'], 'arvados#group', true, 'Group'
140 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
141 'foo/newusertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
143 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
144 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
146 # invoke setup with a vm_uuid
147 post "/arvados/v1/users/setup", {
148 vm_uuid: virtual_machines(:testvm).uuid,
149 openid_prefix: 'http://www.example.com/account',
153 uuid: created['uuid']
156 assert_response :success
158 response_items = json_response['items']
159 created = find_obj_in_resp response_items, 'arvados#user', nil
161 assert_equal created['email'], 'foo@example.com', 'expected original email'
164 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
165 'All users', created['uuid'], 'arvados#group', true, 'Group'
167 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
168 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
171 test "setup and unsetup user" do
172 post "/arvados/v1/users/setup", {
173 repo_name: 'newusertestrepo',
174 vm_uuid: virtual_machines(:testvm).uuid,
175 user: {email: 'foo@example.com'},
176 openid_prefix: 'https://www.google.com/accounts/o8/id'
179 assert_response :success
180 response_items = json_response['items']
181 created = find_obj_in_resp response_items, 'arvados#user', nil
182 assert_not_nil created['uuid'], 'expected uuid for the new user'
183 assert_equal created['email'], 'foo@example.com', 'expected given email'
185 # five extra links: system_group, login, group, repo and vm
186 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
187 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
189 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
190 'All users', created['uuid'], 'arvados#group', true, 'Group'
192 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
193 'foo/newusertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
195 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
196 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
198 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
200 post "/arvados/v1/users/#{created['uuid']}/unsetup", {}, auth(:admin)
202 assert_response :success
204 created2 = json_response
205 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
206 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
208 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
211 def find_obj_in_resp (response_items, kind, head_kind=nil)
212 response_items.each do |x|
214 return x if (x['kind'] == kind && x['head_kind'] == head_kind)
220 test 'merge active into project_viewer account' do
221 post('/arvados/v1/groups', {
223 group_class: 'project',
224 name: "active user's stuff",
226 }, auth(:project_viewer))
227 assert_response(:success)
228 project_uuid = json_response['uuid']
230 post('/arvados/v1/users/merge', {
231 new_user_token: api_client_authorizations(:project_viewer_trustedclient).api_token,
232 new_owner_uuid: project_uuid,
233 redirect_to_new_user: true,
234 }, auth(:active_trustedclient))
235 assert_response(:success)
237 get('/arvados/v1/users/current', {}, auth(:active))
238 assert_response(:success)
239 assert_equal(users(:project_viewer).uuid, json_response['uuid'])
241 get('/arvados/v1/authorized_keys/' + authorized_keys(:active).uuid, {}, auth(:active))
242 assert_response(:success)
243 assert_equal(users(:project_viewer).uuid, json_response['owner_uuid'])
244 assert_equal(users(:project_viewer).uuid, json_response['authorized_user_uuid'])
246 get('/arvados/v1/repositories/' + repositories(:foo).uuid, {}, auth(:active))
247 assert_response(:success)
248 assert_equal(users(:project_viewer).uuid, json_response['owner_uuid'])
250 get('/arvados/v1/groups/' + groups(:aproject).uuid, {}, auth(:active))
251 assert_response(:success)
252 assert_equal(project_uuid, json_response['owner_uuid'])