Replace tabs with spaces as per our coding standards
authorradhika chippada <radhika@radhika.curoverse>
Wed, 19 Mar 2014 21:03:07 +0000 (17:03 -0400)
committerradhika chippada <radhika@radhika.curoverse>
Wed, 19 Mar 2014 21:03:07 +0000 (17:03 -0400)
services/api/app/controllers/arvados/v1/users_controller.rb
services/api/script/setup-new-user.rb
services/api/test/functional/arvados/v1/users_controller_test.rb

index 303e6d785a0fb5678348b6e17f3a3b2c9ffc68af..84de9b85bffb5755d3a1a612d86c6617ccab2699 100644 (file)
@@ -88,198 +88,198 @@ class Arvados::V1::UsersController < ApplicationController
     show
   end
 
-       # create user object and all the needed links
+  # create user object and all the needed links
   def create
-               if params[:openid_prefix]               # check if default openid_prefix needs to be overridden
-                       openid_prefix = params[:openid_prefix]
-               else 
-                       openid_prefix = 'https://www.google.com/accounts/o8/id'         # default openid prefix
-               end
-               login_perm_props = {identity_url_prefix: openid_prefix}
+    if params[:openid_prefix]   # check if default openid_prefix needs to be overridden
+      openid_prefix = params[:openid_prefix]
+    else 
+      openid_prefix = 'https://www.google.com/accounts/o8/id'   # default openid prefix
+    end
+    login_perm_props = {identity_url_prefix: openid_prefix}
 
-               @object = model_class.new resource_attrs
+    @object = model_class.new resource_attrs
 
-               # If user_param is passed, lookup for user. If exists, skip create and only create any missing links. 
-               if params[:user_param]
-                       begin
-                               @object_found = find_user_from_input params[:user_param], params[:user_param]
-                 end
-                       if !@object_found
-                               @object = User.new              # when user_param is used, it will be used as user object
-                               @object[:email] = params[:user_param]                           
-                       need_to_create = true
-                       else
-                               @object = @object_found
-                       end
-               else            # need to create user for the given user data
-                       @object_found = find_user_from_input @object[:uuid], @object[:email]
-                       if !@object_found
-                       need_to_create = true           # use the user object sent in to create with the user
-                       else
-                               @object = @object_found
-                       end
-               end
+    # If user_param is passed, lookup for user. If exists, skip create and only create any missing links. 
+    if params[:user_param]
+      begin
+        @object_found = find_user_from_input params[:user_param], params[:user_param]
+      end
+      if !@object_found
+        @object = User.new    # when user_param is used, it will be used as user object
+        @object[:email] = params[:user_param]       
+        need_to_create = true
+      else
+        @object = @object_found
+      end
+    else    # need to create user for the given user data
+      @object_found = find_user_from_input @object[:uuid], @object[:email]
+      if !@object_found
+        need_to_create = true   # use the user object sent in to create with the user
+      else
+        @object = @object_found
+      end
+    end
 
-               # create if need be, and then create or update the links as needed 
-               if need_to_create
-                       if @object.save
-                               oid_login_perm = Link.where(tail_uuid: @object[:email],
-                                                       head_kind: 'arvados#user',
-                                                       link_class: 'permission',
-                                                       name: 'can_login')
+    # create if need be, and then create or update the links as needed 
+    if need_to_create
+      if @object.save
+        oid_login_perm = Link.where(tail_uuid: @object[:email],
+                                    head_kind: 'arvados#user',
+                                    link_class: 'permission',
+                                    name: 'can_login')
 
-                               if [] == oid_login_perm
-                                       # create openid login permission
-               oid_login_perm = Link.create(link_class: 'permission',
-                                                name: 'can_login',
-                                                tail_kind: 'email',
-                                          tail_uuid: @object[:email],
-                                          head_kind: 'arvados#user',
-                                          head_uuid: @object[:uuid],
-                                          properties: login_perm_props
-                                               )
-                                       logger.info { "openid login permission: " + oid_login_perm[:uuid] }
-                               end
-         else
-               raise "Save failed"
-               end
-               end
+        if [] == oid_login_perm
+          # create openid login permission
+          oid_login_perm = Link.create(link_class: 'permission',
+                                       name: 'can_login',
+                                       tail_kind: 'email',
+                                       tail_uuid: @object[:email],
+                                       head_kind: 'arvados#user',
+                                       head_uuid: @object[:uuid],
+                                       properties: login_perm_props
+                                      )
+          logger.info { "openid login permission: " + oid_login_perm[:uuid] }
+        end
+      else
+        raise "Save failed"
+      end
+    end
 
-               # create links
-               create_user_repo_link params[:repo_name]
-               create_vm_login_permission_link params[:vm_uuid], params[:repo_name]
-               create_user_group_link 
+    # create links
+    create_user_repo_link params[:repo_name]
+    create_vm_login_permission_link params[:vm_uuid], params[:repo_name]
+    create_user_group_link 
 
-               show
+    show
   end
 
-       protected 
+  protected 
 
-       # find the user from the given user parameters
-       def find_user_from_input(user_uuid, user_email)
-               if user_uuid
-                       found_object = User.find_by_uuid user_uuid
-               end
+  # find the user from the given user parameters
+  def find_user_from_input(user_uuid, user_email)
+    if user_uuid
+      found_object = User.find_by_uuid user_uuid
+    end
 
-               if !found_object
-                       begin
-                               if !user_email
-                                       return
-                               end
+    if !found_object
+      begin
+        if !user_email
+          return
+        end
 
-                               if !user_email.match(/\w\@\w+\.\w+/)
-                                       logger.warn ("Given user param is not valid email format: #{user_email}")
-                                       raise ArgumentError.new "User param is not of valid email format. Stop"
-                               else
+        if !user_email.match(/\w\@\w+\.\w+/)
+          logger.warn ("Given user param is not valid email format: #{user_email}")
+          raise ArgumentError.new "User param is not of valid email format. Stop"
+        else
           found_objects = User.where('email=?', user_email)  
-                                       if found_objects.size > 1
-                                               logger.warn ("Found #{found_objects.size} users with email #{user_email}. Stop.")
-                                               raise ArgumentError.new "Found #{found_objects.size} users with email #{user_email}. Stop."
-                                       elsif found_objects.size == 1
-                                               found_object = found_objects.first
-                                       end
+          if found_objects.size > 1
+            logger.warn ("Found #{found_objects.size} users with email #{user_email}. Stop.")
+            raise ArgumentError.new "Found #{found_objects.size} users with email #{user_email}. Stop."
+          elsif found_objects.size == 1
+            found_object = found_objects.first
+          end
         end
-               end
-               end
+      end
+    end
 
-               return found_object
-       end
-       
-       # link the repo_name passed
-       def create_user_repo_link(repo_name)
-               if not repo_name
-                       logger.warn ("Repository name not given for #{@object[:uuid]}. Skip creating the link")
-                       return
-               end
+    return found_object
+  end
+  
+  # link the repo_name passed
+  def create_user_repo_link(repo_name)
+    if not repo_name
+      logger.warn ("Repository name not given for #{@object[:uuid]}. Skip creating the link")
+      return
+    end
 
-               # Check for an existing repository with the same name we're about to use.
-               repo = (repositories = Repository.where(name: repo_name)) != nil ? repositories.first : nil
-               if repo
-               logger.warn "Repository already exists with name #{repo_name}: #{repo[:uuid]}. Will link to user."
+    # Check for an existing repository with the same name we're about to use.
+    repo = (repositories = Repository.where(name: repo_name)) != nil ? repositories.first : nil
+    if repo
+      logger.warn "Repository already exists with name #{repo_name}: #{repo[:uuid]}. Will link to user."
 
-                       # Look for existing repository access (perhaps using a different repository/user name).
-                       repo_perms = Link.where(tail_uuid: @object[:uuid],
-                               head_kind: 'arvados#repository',
-                               head_uuid: repo[:uuid],
-                               link_class: 'permission',
-                               name: 'can_write')
-                       if [] != repo_perms
-                       logger.warn "User already has repository access " + repo_perms.collect { |p| p[:uuid] }.inspect
-                               return
-                       end
-               end
+      # Look for existing repository access (perhaps using a different repository/user name).
+      repo_perms = Link.where(tail_uuid: @object[:uuid],
+                              head_kind: 'arvados#repository',
+                              head_uuid: repo[:uuid],
+                              link_class: 'permission',
+                              name: 'can_write')
+      if [] != repo_perms
+        logger.warn "User already has repository access " + repo_perms.collect { |p| p[:uuid] }.inspect
+        return
+      end
+    end
 
-               repo ||= Repository.create(name: repo_name)             # create repo, if does not already exist
-               logger.info { "repo uuid: " + repo[:uuid] }
+    repo ||= Repository.create(name: repo_name)   # create repo, if does not already exist
+    logger.info { "repo uuid: " + repo[:uuid] }
 
-               repo_perm = Link.create(tail_kind: 'arvados#user',
+    repo_perm = Link.create(tail_kind: 'arvados#user',
                             tail_uuid: @object[:uuid],
                             head_kind: 'arvados#repository',
                             head_uuid: repo[:uuid],
                             link_class: 'permission',
                             name: 'can_write')
-               logger.info { "repo permission: " + repo_perm[:uuid] }
-       end
+    logger.info { "repo permission: " + repo_perm[:uuid] }
+  end
 
-       # create login permission for the given vm_uuid, if it does not already exist
-       def create_vm_login_permission_link(vm_uuid, repo_name)
-               # Look up the given virtual machine just to make sure it really exists.
-               begin
-                       vm = (vms = VirtualMachine.where(uuid: vm_uuid)) != nil ? vms.first : nil
-                       if not vm
-                         logger.warn "Could not look up virtual machine with uuid #{vm_uuid.inspect}"
-                               return
-                       end
+  # create login permission for the given vm_uuid, if it does not already exist
+  def create_vm_login_permission_link(vm_uuid, repo_name)
+    # Look up the given virtual machine just to make sure it really exists.
+    begin
+      vm = (vms = VirtualMachine.where(uuid: vm_uuid)) != nil ? vms.first : nil
+      if not vm
+        logger.warn "Could not look up virtual machine with uuid #{vm_uuid.inspect}"
+        return
+      end
 
-                       logger.info { "vm uuid: " + vm[:uuid] }
+      logger.info { "vm uuid: " + vm[:uuid] }
 
-                       login_perm = Link.where(tail_uuid: @object[:uuid],
+      login_perm = Link.where(tail_uuid: @object[:uuid],
                               head_uuid: vm[:uuid],
-                               head_kind: 'arvados#virtualMachine',
-                               link_class: 'permission',
-                               name: 'can_login')
-                       if [] == login_perm
-                               login_perm = Link.create(tail_kind: 'arvados#user',
-                                      tail_uuid: @object[:uuid],
-                                      head_kind: 'arvados#virtualMachine',
-                                      head_uuid: vm[:uuid],
-                                      link_class: 'permission',
-                                      name: 'can_login',
-                                      properties: {username: repo_name})
-                               logger.info { "login permission: " + login_perm[:uuid] }
-                       end
-               end
-       end
+                              head_kind: 'arvados#virtualMachine',
+                              link_class: 'permission',
+                              name: 'can_login')
+      if [] == login_perm
+        login_perm = Link.create(tail_kind: 'arvados#user',
+                                 tail_uuid: @object[:uuid],
+                                 head_kind: 'arvados#virtualMachine',
+                                 head_uuid: vm[:uuid],
+                                 link_class: 'permission',
+                                 name: 'can_login',
+                                 properties: {username: repo_name})
+        logger.info { "login permission: " + login_perm[:uuid] }
+      end
+    end
+  end
 
-       # add the user to the 'All users' group
-       def create_user_group_link
-               # Look up the "All users" group (we expect uuid *-*-fffffffffffffff).
-               group = Group.where(name: 'All users').select do |g|
-                       g[:uuid].match /-f+$/
-               end.first
+  # add the user to the 'All users' group
+  def create_user_group_link
+    # Look up the "All users" group (we expect uuid *-*-fffffffffffffff).
+    group = Group.where(name: 'All users').select do |g|
+      g[:uuid].match /-f+$/
+    end.first
 
-               if not group
-               logger.warn "Could not look up the 'All users' group with uuid '*-*-fffffffffffffff'. Skip."
-                       return
-               else
-                       logger.info { "\"All users\" group uuid: " + group[:uuid] }
+    if not group
+      logger.warn "Could not look up the 'All users' group with uuid '*-*-fffffffffffffff'. Skip."
+      return
+    else
+      logger.info { "\"All users\" group uuid: " + group[:uuid] }
 
-                       group_perm = Link.where(tail_uuid: @object[:uuid],
-                                                                                                                       head_uuid: group[:uuid],
-                               head_kind: 'arvados#group',
-                               link_class: 'permission',
-                               name: 'can_read')
+      group_perm = Link.where(tail_uuid: @object[:uuid],
+                              head_uuid: group[:uuid],
+                              head_kind: 'arvados#group',
+                              link_class: 'permission',
+                              name: 'can_read')
 
-                       if [] == group_perm
-                               group_perm = Link.create(tail_kind: 'arvados#user',
-                                    tail_uuid: @object[:uuid],
-                                    head_kind: 'arvados#group',
-                                    head_uuid: group[:uuid],
-                                    link_class: 'permission',
-                                    name: 'can_read')
-                               logger.info { "group permission: " + group_perm[:uuid] }
-                       end
-               end
-       end
+      if [] == group_perm
+        group_perm = Link.create(tail_kind: 'arvados#user',
+                                 tail_uuid: @object[:uuid],
+                                 head_kind: 'arvados#group',
+                                 head_uuid: group[:uuid],
+                                 link_class: 'permission',
+                                 name: 'can_read')
+        logger.info { "group permission: " + group_perm[:uuid] }
+      end
+    end
+  end
 
 end
index 72e18040a531b296bb7277916a670533db7a2e09..38c9903483c2a90b0a596f1bc3785776ddeed574 100755 (executable)
@@ -37,9 +37,8 @@ require 'arvados'
 arv = Arvados.new(api_version: 'v1')
 
 begin
-       new_user = arv.user.create(user_param: user_arg, repo_name: user_repo_name, vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix, user: {})
-       log.warn new_user
+  new_user = arv.user.create(user_param: user_arg, repo_name: user_repo_name, vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix, user: {})
+  log.warn new_user
 rescue Exception => e #Arvados::TransactionFailedError
-       log.warn e.message
+  log.warn e.message
 end
-
index a7bdb7cb1006e94f7bd75001f18472ca19bb980e..748d28157434f5133334d415a4b637bd8e4d4f88 100644 (file)
@@ -2,13 +2,13 @@ require 'test_helper'
 
 class Arvados::V1::UsersControllerTest < ActionController::TestCase
 
-       setup do
-               @all_users_at_start = User.all
-               @all_groups_at_start = Group.all
-               @all_links_at_start = Link.all
+  setup do
+    @all_users_at_start = User.all
+    @all_groups_at_start = Group.all
+    @all_links_at_start = Link.all
 
-               @vm_uuid = virtual_machines(:testvm).uuid
-       end
+    @vm_uuid = virtual_machines(:testvm).uuid
+  end
 
   test "activate a user after signing UA" do
     authorize_with :inactive_but_signed_user_agreement
@@ -51,7 +51,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     post :create, user: {
       first_name: "test_first_name",
       last_name: "test_last_name",
-                       email: "test@abc.com"
+      email: "test@abc.com"
     }
     assert_response :success
     created = JSON.parse(@response.body)
@@ -61,84 +61,84 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     assert_nil created['identity_url'], 'even though email is provided, expected no identity_url since users_controller only creates user at this time'
   end
 
-       test "create user with user, vm and repo as input" do
+  test "create user with user, vm and repo as input" do
     authorize_with :admin
-               repo_name = 'test_repo'
+    repo_name = 'test_repo'
 
     post :create, {
       repo_name: repo_name,
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {
-                   uuid: "is_this_correct",                
-                               first_name: "in_create_test_first_name",
-                   last_name: "test_last_name",
-                               email: "test@abc.com"
+        uuid: "is_this_correct",        
+        first_name: "in_create_test_first_name",
+        last_name: "test_last_name",
+        email: "test@abc.com"
       }
     }
     assert_response :success
     created = JSON.parse(@response.body)
     assert_equal 'in_create_test_first_name', created['first_name']
     assert_not_nil created['uuid'], 'expected non-null uuid for the newly created user'
-               assert_equal 'is_this_correct', created['uuid']
+    assert_equal 'is_this_correct', created['uuid']
     assert_not_nil created['email'], 'since email was given, expected non-nil email'
     assert_nil created['identity_url'], 'even though email isprovided, expected no identity_url since users_controller only creates user' 
 
-               # since no such vm exists, expect only three new links: oid_login_perm, repo link and link add user to 'All users' group
-               verify_num_links @all_links_at_start, 3
+    # since no such vm exists, expect only three new links: oid_login_perm, repo link and link add user to 'All users' group
+    verify_num_links @all_links_at_start, 3
 
-               verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
+    verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
 
-               verify_link_exists_for_type 'Repository', 'permission', 'can_write', repo_name, created['uuid'], 'arvados#repository', true
+    verify_link_exists_for_type 'Repository', 'permission', 'can_write', repo_name, created['uuid'], 'arvados#repository', true
 
-               verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
-       end
+    verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
+  end
 
-       test "create user with user_param, vm and repo as input" do
+  test "create user with user_param, vm and repo as input" do
     authorize_with :admin
 
     post :create, {
       user_param: 'not_an_existing_uuid_and_not_email_format',
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {}
     }
 
     response_body = JSON.parse(@response.body)
     response_errors = response_body['errors']
-               assert_not_nil response_errors, 'Expected error in response'
-               incorrectly_formatted = response_errors.first.include?('ArgumentError: User param is not of valid email format')
-               assert incorrectly_formatted, 'Expected not valid email format error'
-       end
+    assert_not_nil response_errors, 'Expected error in response'
+    incorrectly_formatted = response_errors.first.include?('ArgumentError: User param is not of valid email format')
+    assert incorrectly_formatted, 'Expected not valid email format error'
+  end
 
-       test "create user with existing uuid user_param, vm and repo as input" do
-               authorize_with :inactive
+  test "create user with existing uuid user_param, vm and repo as input" do
+    authorize_with :inactive
     get :current
     assert_response :success
     inactive_user = JSON.parse(@response.body)
-               
+    
     authorize_with :admin
 
     post :create, {
       user_param: inactive_user['uuid'],
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {}
     }
 
     assert_response :success
     response_object = JSON.parse(@response.body)
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
-               assert_equal inactive_user['uuid'], response_object['uuid']
+    assert_equal inactive_user['uuid'], response_object['uuid']
     assert_equal inactive_user['email'], response_object['email'], 'expecting inactive user email'
-       end
+  end
 
-       test "create user with valid email user_param, vm and repo as input" do
+  test "create user with valid email user_param, vm and repo as input" do
     authorize_with :admin
 
     post :create, {
       user_param: 'abc@xyz.com',
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {}
     }
 
@@ -146,9 +146,9 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     response_object = JSON.parse(@response.body)
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-       end
+  end
 
-       test "create user with valid email user_param, no vm and repo as input" do
+  test "create user with valid email user_param, no vm and repo as input" do
     authorize_with :admin
 
     post :create, {
@@ -156,23 +156,23 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       user: {}
     }
 
-    assert_response :success           
+    assert_response :success    
     response_object = JSON.parse(@response.body)
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-       end
+  end
 
-       test "create user with user_param and non-empty user which will be ignored" do
+  test "create user with user_param and non-empty user which will be ignored" do
     authorize_with :admin
 
     post :create, {
       user_param: 'abc@xyz.com',
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {
         first_name: 'test_first_name',
-                               email: 'will_be_ignored@xyz.com'
-                       }
+        email: 'will_be_ignored@xyz.com'
+      }
     }
 
     assert_response :success
@@ -180,15 +180,15 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting user_param as email'
     assert_nil response_object['first_name'], 'expecting no first name since it will be reset when user_param is used'
-       end
+  end
 
-       test "create user twice with user param and check links are not recreated" do
+  test "create user twice with user param and check links are not recreated" do
     authorize_with :admin
 
     post :create, {
       user_param: 'abc@xyz.com',
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {}
     }
 
@@ -196,13 +196,13 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     response_object = JSON.parse(@response.body)
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-               verify_num_links @all_links_at_start, 3         # openid, group, and repo links. no vm link
+    verify_num_links @all_links_at_start, 3   # openid, group, and repo links. no vm link
 
-               # create again
+    # create again
     post :create, {
       user_param: 'abc@xyz.com',
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
+      vm_uuid: 'no_such_vm',
       user: {}
     }
 
@@ -210,48 +210,48 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     response_object2 = JSON.parse(@response.body)
     assert_equal response_object['uuid'], response_object2['uuid'], 'expected same uuid as first create operation'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-               verify_num_links @all_links_at_start, 3         # openid, group, and repo links. no vm link
-       end
+    verify_num_links @all_links_at_start, 3   # openid, group, and repo links. no vm link
+  end
 
-       test "create user twice with user object as input and check links are not recreated" do
+  test "create user twice with user object as input and check links are not recreated" do
     authorize_with :admin
 
     post :create, {
       repo_name: 'test_repo',
       user: {
-                               email: 'abc@xyz.com'
-                       }
+        email: 'abc@xyz.com'
+      }
     }
 
     assert_response :success
     response_object = JSON.parse(@response.body)
     assert_not_nil response_object['uuid'], 'expected non-null uuid for the newly created user'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-               verify_num_links @all_links_at_start, 3         # openid, group, and repo links. no vm link
+    verify_num_links @all_links_at_start, 3   # openid, group, and repo links. no vm link
 
-               # create again
-         post :create, user: {
-                       email: 'abc@xyz.com'
+    # create again
+    post :create, user: {
+      email: 'abc@xyz.com'
     }
 
     assert_response :success
     response_object2 = JSON.parse(@response.body)
     assert_equal response_object['uuid'], response_object2['uuid'], 'expected same uuid as first create operation'
     assert_equal response_object['email'], 'abc@xyz.com', 'expecting given email'
-               verify_num_links @all_links_at_start, 3         # openid, group, and repo links. no vm link
-       end
+    verify_num_links @all_links_at_start, 3   # openid, group, and repo links. no vm link
+  end
 
-       test "create user with openid prefix" do
+  test "create user with openid prefix" do
     authorize_with :admin
 
     post :create, {
       repo_name: 'test_repo',
-                       vm_uuid: 'no_such_vm',
-                       openid_prefix: 'http://www.xyz.com/account',
+      vm_uuid: 'no_such_vm',
+      openid_prefix: 'http://www.xyz.com/account',
       user: {
-                               first_name: "in_create_test_first_name",
-                   last_name: "test_last_name",
-                               email: "test@abc.com"
+        first_name: "in_create_test_first_name",
+        last_name: "test_last_name",
+        email: "test@abc.com"
       }
     }
     assert_response :success
@@ -261,27 +261,27 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     assert_not_nil created['email'], 'since email was given, expected non-nil email'
     assert_nil created['identity_url'], 'even though email is provided, expected no identity_url since users_controller only creates user' 
 
-               # verify links
-               # expect 3 new links: oid_login_perm, repo link, and link add user to 'All users' group. No vm link since the vm_uuid passed in is not in system
-               verify_num_links @all_links_at_start, 3
+    # verify links
+    # expect 3 new links: oid_login_perm, repo link, and link add user to 'All users' group. No vm link since the vm_uuid passed in is not in system
+    verify_num_links @all_links_at_start, 3
 
-               verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
+    verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
 
-               verify_link_exists_for_type 'Repository', 'permission', 'can_write', 'test_repo', created['uuid'], 'arvados#repository', true
+    verify_link_exists_for_type 'Repository', 'permission', 'can_write', 'test_repo', created['uuid'], 'arvados#repository', true
 
-               verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
-       end
+    verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
+  end
 
-       test "create user with user, vm and repo and verify links" do
+  test "create user with user, vm and repo and verify links" do
     authorize_with :admin
 
     post :create, {
       repo_name: 'test_repo',
-                       vm_uuid: @vm_uuid,
+      vm_uuid: @vm_uuid,
       user: {
-                               first_name: "in_create_test_first_name",
-                   last_name: "test_last_name",
-                               email: "test@abc.com"
+        first_name: "in_create_test_first_name",
+        last_name: "test_last_name",
+        email: "test@abc.com"
       }
     }
     assert_response :success
@@ -291,37 +291,37 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     assert_not_nil created['email'], 'since email was given, expected non-nil email'
     assert_nil created['identity_url'], 'even though email is provided, expected no identity_url since users_controller only creates user' 
 
-               # expect 4 new links: oid_login_perm, repo link, vm link and link add user to 'All users' group. 
-               verify_num_links @all_links_at_start, 4
+    # expect 4 new links: oid_login_perm, repo link, vm link and link add user to 'All users' group. 
+    verify_num_links @all_links_at_start, 4
 
-               verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
+    verify_link_exists_for_type 'User', 'permission', 'can_login', created['uuid'], created['email'], 'arvados#user', false
 
-               verify_link_exists_for_type 'Repository', 'permission', 'can_write', 'test_repo', created['uuid'], 'arvados#repository', true
+    verify_link_exists_for_type 'Repository', 'permission', 'can_write', 'test_repo', created['uuid'], 'arvados#repository', true
 
-               verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
+    verify_link_exists_for_type 'Group', 'permission', 'can_read', 'All users', created['uuid'], 'arvados#group', true
 
-               verify_link_exists_for_type 'VirtualMachine', 'permission', 'can_login', @vm_uuid, created['uuid'], 'arvados#virtualMachine', false
-       end
-
-       def verify_num_links (original_links, expected_num_additional_links)
-               links_now = Link.all
-               assert_equal original_links.size+expected_num_additional_links, Link.all.size, 
-                                                       "Expected #{expected_num_additional_links.inspect} more links"
-       end
+    verify_link_exists_for_type 'VirtualMachine', 'permission', 'can_login', @vm_uuid, created['uuid'], 'arvados#virtualMachine', false
+  end
 
-       def verify_link_exists_for_type(class_name, link_class, link_name, head_uuid, tail_uuid, head_kind, fetch_object)
-               if fetch_object
-                       object = Object.const_get(class_name).where(name: head_uuid)
-                       assert [] != object, "expected a #{class_name.inspect} with the name #{head_uuid.inspect}"
-                       head_uuid = object.first[:uuid]
-               end
+  def verify_num_links (original_links, expected_num_additional_links)
+    links_now = Link.all
+    assert_equal original_links.size+expected_num_additional_links, Link.all.size, 
+              "Expected #{expected_num_additional_links.inspect} more links"
+  end
 
-               links = Link.where(link_class: link_class,
-                                        name: link_name,
-                                                tail_uuid: tail_uuid,
-                                                head_uuid: head_uuid,
-                                              head_kind: head_kind)
-               assert links.size > 0, "expected one or more links with the given criteria #{class_name} with #{head_uuid}"
-       end
+  def verify_link_exists_for_type(class_name, link_class, link_name, head_uuid, tail_uuid, head_kind, fetch_object)
+    if fetch_object
+      object = Object.const_get(class_name).where(name: head_uuid)
+      assert [] != object, "expected a #{class_name.inspect} with the name #{head_uuid.inspect}"
+      head_uuid = object.first[:uuid]
+    end
+
+    links = Link.where(link_class: link_class,
+                       name: link_name,
+                       tail_uuid: tail_uuid,
+                       head_uuid: head_uuid,
+                       head_kind: head_kind)
+    assert links.size > 0, "expected one or more links with the given criteria #{class_name} with #{head_uuid}"
+  end
 
 end