20284: username updates from login cluster always take precidence
authorPeter Amstutz <peter.amstutz@curii.com>
Thu, 26 Oct 2023 17:37:00 +0000 (13:37 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Thu, 26 Oct 2023 17:37:00 +0000 (13:37 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

services/api/app/controllers/arvados/v1/users_controller.rb
services/api/test/functional/arvados/v1/users_controller_test.rb

index b872c0bbab275655d76c00b3991a5e299574feab..59de9d488e9f003433feb4e898750fa29eb4057e 100644 (file)
@@ -37,8 +37,8 @@ class Arvados::V1::UsersController < ApplicationController
             local_user = User.find_by_username(needupdate[:username])
             # A cached user record from the LoginCluster is stale, reset its username
             # and retry the update operation.
-            if local_user.andand.uuid[0..4] == loginCluster && local_user.uuid != u.uuid
-              new_username = "#{needupdate[:username]}conflict#{rand(99999999)}"
+            if local_user.uuid != u.uuid
+              new_username = "#{needupdate[:username]}#{rand(99999999)}"
               Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying")
               local_user.update!({username: new_username})
               retry
index 8bffac8dd1e1aabc4ead73afcfc577ffdd3c98dd..fd1674a05af6286c417913dca3451b2a695c27d5 100644 (file)
@@ -1043,12 +1043,16 @@ The Arvados team.
     existinguuid = 'remot-tpzed-foobarbazwazqux'
     newuuid = 'remot-tpzed-newnarnazwazqux'
     unchanginguuid = 'remot-tpzed-nochangingattrs'
+    conflictinguuid1 = 'remot-tpzed-conflictingname'
+    conflictinguuid2 = 'remot-tpzed-conflictingname'
     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: {
@@ -1069,6 +1073,14 @@ The Arvados team.
                 'email' => 'root@unchanging.example.com',
                 'prefs' => {'foo' => {'bar' => 'baz'}},
               },
+              conflictinguuid1 => {
+                'email' => 'root@conflictingname1.example.com',
+                'username' => 'active'
+              },
+              conflictinguuid1 => {
+                'email' => 'root@conflictingname2.example.com',
+                'username' => 'federatedactive'
+              },
             }})
     assert_response(:success)