2 require 'helpers/users_test_helper'
4 class UsersTest < ActionDispatch::IntegrationTest
5 include UsersTestHelper
7 test "setup user multiple times" do
8 repo_name = 'test_repo'
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 repo_name, 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 repo_name, 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#repository', false, 'permission', 'can_manage',
109 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
111 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
112 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
114 # invoke setup with a repository
115 post "/arvados/v1/users/setup", {
116 openid_prefix: 'http://www.example.com/account',
117 repo_name: 'new_repo',
118 uuid: created['uuid']
121 assert_response :success
123 response_items = json_response['items']
124 created = find_obj_in_resp response_items, 'arvados#user', nil
126 assert_equal 'foo@example.com', created['email'], 'expected input email'
129 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
130 'All users', created['uuid'], 'arvados#group', true, 'Group'
132 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
133 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
135 verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
136 nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
138 # invoke setup with a vm_uuid
139 post "/arvados/v1/users/setup", {
140 vm_uuid: virtual_machines(:testvm).uuid,
141 openid_prefix: 'http://www.example.com/account',
145 uuid: created['uuid']
148 assert_response :success
150 response_items = json_response['items']
151 created = find_obj_in_resp response_items, 'arvados#user', nil
153 assert_equal created['email'], 'foo@example.com', 'expected original email'
156 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
157 'All users', created['uuid'], 'arvados#group', true, 'Group'
159 # since no repo name in input, we won't get any; even though user has one
160 verify_link response_items, 'arvados#repository', false, 'permission', 'can_manage',
161 'new_repo', created['uuid'], 'arvados#repository', true, 'Repository'
163 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
164 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
167 test "setup and unsetup user" do
168 post "/arvados/v1/users/setup", {
169 repo_name: 'test_repo',
170 vm_uuid: virtual_machines(:testvm).uuid,
171 user: {email: 'foo@example.com'},
172 openid_prefix: 'https://www.google.com/accounts/o8/id'
175 assert_response :success
176 response_items = json_response['items']
177 created = find_obj_in_resp response_items, 'arvados#user', nil
178 assert_not_nil created['uuid'], 'expected uuid for the new user'
179 assert_equal created['email'], 'foo@example.com', 'expected given email'
181 # five extra links: system_group, login, group, repo and vm
182 verify_link response_items, 'arvados#user', true, 'permission', 'can_login',
183 created['uuid'], created['email'], 'arvados#user', false, 'arvados#user'
185 verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
186 'All users', created['uuid'], 'arvados#group', true, 'Group'
188 verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
189 'test_repo', created['uuid'], 'arvados#repository', true, 'Repository'
191 verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
192 virtual_machines(:testvm).uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
194 verify_link_existence created['uuid'], created['email'], true, true, true, true, false
196 post "/arvados/v1/users/#{created['uuid']}/unsetup", {}, auth(:admin)
198 assert_response :success
200 created2 = json_response
201 assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
202 assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
204 verify_link_existence created['uuid'], created['email'], false, false, false, false, false
207 def find_obj_in_resp (response_items, kind, head_kind=nil)
208 response_items.each do |x|
210 return x if (x['kind'] == kind && x['head_kind'] == head_kind)