20284: Fix test and update code comment. 20284-username-conflict-fix
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 27 Oct 2023 17:59:56 +0000 (13:59 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 27 Oct 2023 17:59:56 +0000 (13:59 -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 59de9d488e9f003433feb4e898750fa29eb4057e..2353f67c1a3978d611034e28e5e900cca1bcfc40 100644 (file)
@@ -35,8 +35,13 @@ class Arvados::V1::UsersController < ApplicationController
           loginCluster = Rails.configuration.Login.LoginCluster
           if u.uuid[0..4] == loginCluster && !needupdate[:username].nil?
             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.
+            # The username of this record conflicts with an existing,
+            # different user record.  This can happen because the
+            # username changed upstream on the login cluster, or
+            # because we're federated with another cluster with a user
+            # by the same username.  The login cluster is the source
+            # of truth, so change the username on the conflicting
+            # record and retry the update operation.
             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")
index fd1674a05af6286c417913dca3451b2a695c27d5..6a9cb74195e025301f2af475787be63a39e32445 100644 (file)
@@ -1043,8 +1043,8 @@ The Arvados team.
     existinguuid = 'remot-tpzed-foobarbazwazqux'
     newuuid = 'remot-tpzed-newnarnazwazqux'
     unchanginguuid = 'remot-tpzed-nochangingattrs'
-    conflictinguuid1 = 'remot-tpzed-conflictingname'
-    conflictinguuid2 = 'remot-tpzed-conflictingname'
+    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'}})
@@ -1077,7 +1077,7 @@ The Arvados team.
                 'email' => 'root@conflictingname1.example.com',
                 'username' => 'active'
               },
-              conflictinguuid1 => {
+              conflictinguuid2 => {
                 'email' => 'root@conflictingname2.example.com',
                 'username' => 'federatedactive'
               },