test "respond 401 if given token exists but user record is missing" do
authorize_with :valid_token_deleted_user
- get :current, {format: :json}
+ get :current, format: :json
assert_response 401
end
assert_nil updated['username'], 'expected no username'
end
- test "create user with user, vm and repo as input" do
+ test "create user with user and vm as input" do
authorize_with :admin
- repo_name = 'usertestrepo'
post :setup, params: {
- repo_name: repo_name,
user: {
uuid: 'zzzzz-tpzed-abcdefghijklmno',
first_name: "in_create_test_first_name",
assert_not_nil created['email'], 'expected non-nil email'
assert_nil created['identity_url'], 'expected no identity_url'
- # repo link and link add user to 'All users' group
- verify_links_added 3
-
- verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
- "foo/#{repo_name}", created['uuid'], 'arvados#repository', true, 'Repository'
+ # added links: vm permission, 'all users' group
+ verify_links_added 2
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', created['uuid'], 'arvados#group', true, 'Group'
verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
post :setup, params: {
uuid: 'bogus_uuid',
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid
}
response_body = JSON.parse(@response.body)
post :setup, params: {
user: {uuid: 'bogus_uuid'},
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid,
}
response_body = JSON.parse(@response.body)
authorize_with :admin
post :setup, params: {
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid,
}
response_body = JSON.parse(@response.body)
post :setup, params: {
user: {},
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid,
}
response_body = JSON.parse(@response.body)
'Expected ArgumentError'
end
- test "invoke setup with existing uuid, vm and repo and verify links" do
+ test "invoke setup with existing uuid and vm permission, and verify links" do
authorize_with :admin
inactive_user = users(:inactive)
post :setup, params: {
uuid: users(:inactive).uuid,
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid
}
assert_equal inactive_user['email'], resp_obj['email'],
'expecting inactive user email'
- # expect repo and vm links
- verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
- 'inactiveuser/usertestrepo', resp_obj['uuid'], 'arvados#repository', true, 'Repository'
-
+ # expect vm permission link
verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
@vm_uuid, resp_obj['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
end
'expecting inactive user email'
end
- test "setup user with valid email and repo as input" do
+ test "setup user with valid email and repo(ignored) as input" do
authorize_with :admin
post :setup, params: {
assert_not_nil response_object['uuid'], 'expected uuid for the new user'
assert_equal response_object['email'], 'foo@example.com', 'expected given email'
- # three extra links; system_group, group and repo perms
- verify_links_added 3
+ # added links: system_group, 'all users' group.
+ verify_links_added 2
end
test "setup user with fake vm and expect error" do
authorize_with :admin
post :setup, params: {
- repo_name: 'usertestrepo',
vm_uuid: 'no_such_vm',
user: {email: 'foo@example.com'},
}
'Expected RuntimeError: No vm found for no_such_vm'
end
- test "setup user with valid email, repo and real vm as input" do
+ test "setup user with valid email and real vm as input" do
authorize_with :admin
post :setup, params: {
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid,
user: {email: 'foo@example.com'}
}
assert_not_nil response_object['uuid'], 'expected uuid for the new user'
assert_equal response_object['email'], 'foo@example.com', 'expected given email'
- # four extra links; system_group, group, vm, repo
- verify_links_added 4
+ # added links; system_group, 'all users' group, vm.
+ verify_links_added 3
end
test "setup user with valid email, no vm and no repo as input" do
assert_not_nil response_object['uuid'], 'expected uuid for new user'
assert_equal response_object['email'], 'foo@example.com', 'expected given email'
- # two extra links; system_group, and group
+ # added links; system_group, 'all users' group.
verify_links_added 2
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', response_object['uuid'], 'arvados#group', true, 'Group'
- verify_link response_items, 'arvados#repository', false, 'permission', 'can_manage',
- 'foo/usertestrepo', response_object['uuid'], 'arvados#repository', true, 'Repository'
-
verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
nil, response_object['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
end
- test "setup user with email, first name, repo name and vm uuid" do
+ test "setup user with email, first name, and vm uuid" do
authorize_with :admin
post :setup, params: {
- repo_name: 'usertestrepo',
vm_uuid: @vm_uuid,
user: {
first_name: 'test_first_name',
assert_equal 'test_first_name', response_object['first_name'],
'expecting first name'
- # four extra links; system_group, group, repo and vm
- verify_links_added 4
+ # added links: system_group, 'all users' group, vm.
+ verify_links_added 3
end
test "setup user with an existing user email and check different object is created" do
inactive_user = users(:inactive)
post :setup, params: {
- repo_name: 'usertestrepo',
user: {
email: inactive_user['email']
}
assert_not_equal response_object['uuid'], inactive_user['uuid'],
'expected different uuid after create operation'
assert_equal inactive_user['email'], response_object['email'], 'expected given email'
- # system_group, group, and repo. No vm link.
- verify_links_added 3
+ # added links: system_group, 'all users' group.
+ verify_links_added 2
end
test "setup user with openid prefix" do
authorize_with :admin
post :setup, params: {
- repo_name: 'usertestrepo',
user: {
first_name: "in_create_test_first_name",
last_name: "test_last_name",
assert_not_nil created['email'], 'expected non-nil email'
assert_nil created['identity_url'], 'expected no identity_url'
- # verify links
- # three new links: system_group, repo, and 'All users' group.
- verify_links_added 3
-
- verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
- 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
+ # added links: system_group, 'all users' group.
+ verify_links_added 2
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', created['uuid'], 'arvados#group', true, 'Group'
verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
end
- test "setup user with user, vm and repo and verify links" do
+ test "setup user with user and vm, and verify links" do
authorize_with :admin
post :setup, params: {
email: "foo@example.com"
},
vm_uuid: @vm_uuid,
- repo_name: 'usertestrepo',
}
assert_response :success
assert_not_nil created['email'], 'expected non-nil email'
assert_nil created['identity_url'], 'expected no identity_url'
- # four new links: system_group, repo, vm and 'All users' group link
- verify_links_added 4
+ # added links: system_group, 'all users' group, vm
+ verify_links_added 3
# system_group isn't part of the response. See User#add_system_group_permission_link
- verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
- 'foo/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
-
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', created['uuid'], 'arvados#group', true, 'Group'
verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
'Expected Forbidden error'
end
- test "setup active user with repo and no vm" do
+ test "setup active user with no vm" do
authorize_with :admin
active_user = users(:active)
- # invoke setup with a repository
post :setup, params: {
- repo_name: 'usertestrepo',
uuid: active_user['uuid']
}
assert_equal active_user[:email], created['email'], 'expected input email'
- # verify links
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ # verify links
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', created['uuid'], 'arvados#group', true, 'Group'
- verify_link response_items, 'arvados#repository', true, 'permission', 'can_manage',
- 'active/usertestrepo', created['uuid'], 'arvados#repository', true, 'Repository'
-
verify_link response_items, 'arvados#virtualMachine', false, 'permission', 'can_login',
nil, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
end
test "setup active user with vm and no repo" do
authorize_with :admin
active_user = users(:active)
- repos_query = Repository.where(owner_uuid: active_user.uuid)
- repo_link_query = Link.where(tail_uuid: active_user.uuid,
- link_class: "permission", name: "can_manage")
- repos_count = repos_query.count
- repo_link_count = repo_link_query.count
- # invoke setup with a repository
post :setup, params: {
vm_uuid: @vm_uuid,
uuid: active_user['uuid'],
assert_equal active_user['email'], created['email'], 'expected original email'
# verify links
- verify_link response_items, 'arvados#group', true, 'permission', 'can_read',
+ verify_link response_items, 'arvados#group', true, 'permission', 'can_write',
'All users', created['uuid'], 'arvados#group', true, 'Group'
- assert_equal(repos_count, repos_query.count)
- assert_equal(repo_link_count, repo_link_query.count)
-
verify_link response_items, 'arvados#virtualMachine', true, 'permission', 'can_login',
@vm_uuid, created['uuid'], 'arvados#virtualMachine', false, 'VirtualMachine'
end
authorize_with :admin
active_user = users(:active)
- # invoke setup with a repository
put :update, params: {
id: active_user['uuid'],
user: {
assert_equal active_user['uuid'], json_response['uuid']
updated = User.where(uuid: active_user['uuid']).first
assert_equal(true, updated.is_active)
- assert_equal({read: true}, updated.group_permissions[all_users_group_uuid])
+ assert_equal({read: true, write: true}, updated.group_permissions[all_users_group_uuid])
end
test "non-admin user can get basic information about readable users" do
get(:index)
check_non_admin_index
check_readable_users_index [:spectator], [:inactive, :active]
+ json_response["items"].each do |u|
+ if u["uuid"] == users(:spectator).uuid
+ assert_equal true, u["can_write"]
+ assert_equal true, u["can_manage"]
+ end
+ end
end
test "non-admin user gets only safe attributes from users#show" do
['dst', :project_viewer_trustedclient]].each do |which_scoped, auth|
test "refuse to merge with scoped #{which_scoped} token" do
act_as_system_user do
- api_client_authorizations(auth).update_attributes(scopes: ["GET /", "POST /", "PUT /"])
+ api_client_authorizations(auth).update(scopes: ["GET /", "POST /", "PUT /"])
end
authorize_with(:active_trustedclient)
post(:merge, params: {
existinguuid = 'remot-tpzed-foobarbazwazqux'
newuuid = 'remot-tpzed-newnarnazwazqux'
unchanginguuid = 'remot-tpzed-nochangingattrs'
+ conflictinguuid1 = 'remot-tpzed-conflictingnam1'
+ conflictinguuid2 = 'remot-tpzed-conflictingnam2'
act_as_system_user do
User.create!(uuid: existinguuid, email: 'root@existing.example.com')
User.create!(uuid: unchanginguuid, email: 'root@unchanging.example.com', prefs: {'foo' => {'bar' => 'baz'}})
end
assert_equal(1, Log.where(object_uuid: unchanginguuid).count)
+ Rails.configuration.Login.LoginCluster = 'remot'
+
authorize_with(:admin)
patch(:batch_update,
params: {
'is_active' => true,
'is_admin' => true,
'prefs' => {'foo' => 'bar'},
+ 'is_invited' => true
},
newuuid => {
'first_name' => 'noot',
'email' => 'root@remot.example.com',
'username' => '',
+ 'is_invited' => true
},
unchanginguuid => {
'email' => 'root@unchanging.example.com',
'prefs' => {'foo' => {'bar' => 'baz'}},
+ 'is_invited' => true
+ },
+ conflictinguuid1 => {
+ 'email' => 'root@conflictingname1.example.com',
+ 'username' => 'active',
+ 'is_invited' => true
+ },
+ conflictinguuid2 => {
+ 'email' => 'root@conflictingname2.example.com',
+ 'username' => 'federatedactive',
+ 'is_invited' => true
},
}})
assert_response(:success)
assert_equal(1, Log.where(object_uuid: unchanginguuid).count)
end
- NON_ADMIN_USER_DATA = ["uuid", "kind", "is_active", "email", "first_name",
- "last_name", "username"].sort
+ test 'batch update does not produce spurious log events' do
+ # test for bug #21304
+
+ existinguuid = 'remot-tpzed-foobarbazwazqux'
+ act_as_system_user do
+ User.create!(uuid: existinguuid,
+ first_name: 'root',
+ is_active: true,
+ )
+ end
+ assert_equal(1, Log.where(object_uuid: existinguuid).count)
+
+ Rails.configuration.Login.LoginCluster = 'remot'
+
+ authorize_with(:admin)
+ patch(:batch_update,
+ params: {
+ updates: {
+ existinguuid => {
+ 'first_name' => 'root',
+ 'email' => '',
+ 'username' => '',
+ 'is_active' => true,
+ 'is_invited' => true
+ },
+ }})
+ assert_response(:success)
+
+ assert_equal(1, Log.where(object_uuid: existinguuid).count)
+ end
+
+ NON_ADMIN_USER_DATA = ["uuid", "kind", "is_active", "is_admin", "is_invited", "email", "first_name",
+ "last_name", "username", "can_write", "can_manage"].sort
def check_non_admin_index
assert_response :success