Merge branch 'master' into 3889-functional-testing
[arvados.git] / services / api / test / functional / arvados / v1 / users_controller_test.rb
index 55b967162dc6a30713de8ac4ec026e8f85f5c436..9c4d18b24152012f8161ec8ab0c0d1521c611413 100644 (file)
@@ -1,7 +1,9 @@
 require 'test_helper'
+require 'helpers/users_test_helper'
 
 class Arvados::V1::UsersControllerTest < ActionController::TestCase
   include CurrentApiClient
+  include UsersTestHelper
 
   setup do
     @all_links_at_start = Link.all
@@ -34,18 +36,20 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
                                 name: 'click',
                                 tail_uuid: users(:inactive).uuid,
                                 head_uuid: required_uuids).
-        collect(&:head_uuid)
+                          collect(&:head_uuid)
 
       assert_equal 0, signed_uuids.length
     end
 
     authorize_with :inactive
+    assert_equal false, users(:inactive).is_active
 
     post :activate, id: users(:inactive).uuid
     assert_response 403
 
-    response_body = JSON.parse(@response.body)
-    assert response_body['errors'].first.include? 'Cannot activate without user agreements'
+    resp = json_response
+    assert resp['errors'].first.include? 'Cannot activate without user agreements'
+    assert_nil resp['is_active']
   end
 
   test "activate an already-active user" do
@@ -360,7 +364,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     verify_num_links @all_links_at_start, 5
   end
 
-  test "setup user with an exising user email and check different object is created" do
+  test "setup user with an existing user email and check different object is created" do
     authorize_with :admin
     inactive_user = users(:inactive)
 
@@ -671,14 +675,14 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     check_non_admin_show
   end
 
-  test "non-admin user can limit index" do
-    g = act_as_system_user do
-      create :group
-    end
-    users = create_list :active_user, 4, join_groups: [g]
-    token = create :token, user: users[0]
+  [2, 4].each do |limit|
+    test "non-admin user can limit index to #{limit}" do
+      g = act_as_system_user do
+        create :group
+      end
+      users = create_list :active_user, 4, join_groups: [g]
+      token = create :token, user: users[0]
 
-    [2, 4].each do |limit|
       authorize_with_token token
       get(:index, limit: limit)
       check_non_admin_index
@@ -853,103 +857,4 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     }
     return return_obj
   end
-
-  def verify_link(response_items, link_object_name, expect_link, link_class,
-        link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name)
-
-    link = find_obj_in_resp response_items, 'Link', link_object_name
-
-    if !expect_link
-      assert_nil link, "Expected no link for #{link_object_name}"
-      return
-    end
-
-    assert_not_nil link, "Expected link for #{link_object_name}"
-
-    if fetch_object
-      object = Object.const_get(class_name).where(name: head_uuid)
-      assert [] != object, "expected #{class_name} with name #{head_uuid}"
-      head_uuid = object.first[:uuid]
-    end
-    assert_equal link_class, link['link_class'],
-        "did not find expected link_class for #{link_object_name}"
-
-    assert_equal link_name, link['name'],
-        "did not find expected link_name for #{link_object_name}"
-
-    assert_equal tail_uuid, link['tail_uuid'],
-        "did not find expected tail_uuid for #{link_object_name}"
-
-    assert_equal head_kind, link['head_kind'],
-        "did not find expected head_kind for #{link_object_name}"
-
-    assert_equal head_uuid, link['head_uuid'],
-        "did not find expected head_uuid for #{link_object_name}"
-  end
-
-  def verify_link_existence uuid, email, expect_oid_login_perms,
-      expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures
-    # verify that all links are deleted for the user
-    oid_login_perms = Link.where(tail_uuid: email,
-                                 link_class: 'permission',
-                                 name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern)
-    if expect_oid_login_perms
-      assert oid_login_perms.any?, "expected oid_login_perms"
-    else
-      assert !oid_login_perms.any?, "expected all oid_login_perms deleted"
-    end
-
-    repo_perms = Link.where(tail_uuid: uuid,
-                            link_class: 'permission',
-                            name: 'can_manage').where("head_uuid like ?", Repository.uuid_like_pattern)
-    if expect_repo_perms
-      assert repo_perms.any?, "expected repo_perms"
-    else
-      assert !repo_perms.any?, "expected all repo_perms deleted"
-    end
-
-    vm_login_perms = Link.
-      where(tail_uuid: uuid,
-            link_class: 'permission',
-            name: 'can_login').
-      where("head_uuid like ?",
-            VirtualMachine.uuid_like_pattern).
-      where('uuid <> ?',
-            links(:auto_setup_vm_login_username_can_login_to_test_vm).uuid)
-    if expect_vm_perms
-      assert vm_login_perms.any?, "expected vm_login_perms"
-    else
-      assert !vm_login_perms.any?, "expected all vm_login_perms deleted"
-    end
-
-    group = Group.where(name: 'All users').select do |g|
-      g[:uuid].match /-f+$/
-    end.first
-    group_read_perms = Link.where(tail_uuid: uuid,
-                                  head_uuid: group[:uuid],
-                                  link_class: 'permission',
-                                  name: 'can_read')
-    if expect_group_perms
-      assert group_read_perms.any?, "expected all users group read perms"
-    else
-      assert !group_read_perms.any?, "expected all users group perm deleted"
-    end
-
-    signed_uuids = Link.where(link_class: 'signature',
-                              tail_uuid: uuid)
-
-    if expect_signatures
-      assert signed_uuids.any?, "expected signatures"
-    else
-      assert !signed_uuids.any?, "expected all signatures deleted"
-    end
-
-  end
-
-  def verify_system_group_permission_link_for user_uuid
-    assert_equal 1, Link.where(link_class: 'permission',
-                               name: 'can_manage',
-                               tail_uuid: system_group_uuid,
-                               head_uuid: user_uuid).count
-  end
 end