3153: when deriving unique name, look for all can_login links, not just the vm_uuid...
[arvados.git] / services / api / test / unit / user_test.rb
index 6402fb4dad685e5febec441aafab4a6993927b66..c410787a116b30524f0254ee3a7a3c8694cfc3ef 100644 (file)
@@ -159,10 +159,10 @@ class UserTest < ActiveSupport::TestCase
     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_repo@example.com', false, true, true],  # existing repository name 'auto_setup_repo'
     [false, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_repo@example.com', false, false, true],  # existing repository name 'auto_setup_repo', but we are not creating repo or login link
 
-    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', true, true, true], # existing vm login name
-    [true, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', true, false, true], # existing vm login name
-    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', false, true, true], # existing vm login name
-    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'xyz_can_login_to_vm@example.com', false, false, true], # existing vm login name, but we are not creating repo or login link
+    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_vm_login@example.com', true, true, true], # existing vm login name
+    [true, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_vm_login@example.com', true, false, true], # existing vm login name
+    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_vm_login@example.com', false, true, true], # existing vm login name
+    [false, 'active-notify@example.com', 'inactive-notify@example.com', 'auto_setup_vm_login@example.com', false, false, true], # existing vm login name, but we are not creating repo or login link
 
     [true, 'active-notify@example.com', 'inactive-notify@example.com', '*!*@example.com', true, false, false], # username is invalid format
     [false, 'active-notify@example.com', 'inactive-notify@example.com', '*!*@example.com', false, false, true], # since no repo and vm login, username is ok (not validated)
@@ -496,10 +496,18 @@ class UserTest < ActiveSupport::TestCase
           ensure
             assert_equal true, repo_names.any?, 'Repository name for username foo is not unique'
           end
-        end    
+        end
         verify_link_exists true, repo_uuids, user.uuid, 'permission', 'can_manage', nil, nil
       end
 
+      # if username is existing vm login name, make sure the username used to generate any repo is unique
+      if username == 'auto_setup_vm_login'
+        if repo_names.any?
+          assert repo_names.first.start_with? 'auto_setup_vm_login'
+          assert_not_nil /\d$/.match(repo_names.first)
+        end
+      end
+
       # check vm uuid
       vm_uuid = Rails.configuration.auto_setup_new_users_with_vm_uuid
       if vm_uuid
@@ -515,7 +523,7 @@ class UserTest < ActiveSupport::TestCase
 
     new_user_email_subject = "#{Rails.configuration.email_subject_prefix}New user created notification"
     if Rails.configuration.auto_setup_new_users
-      new_user_email_subject = valid_username ? "#{Rails.configuration.email_subject_prefix}New user created and setup notification" : 
+      new_user_email_subject = valid_username ? "#{Rails.configuration.email_subject_prefix}New user created and setup notification" :
                                                 "#{Rails.configuration.email_subject_prefix}New user created, but not setup notification"
     end