jenkins-bot has submitted this change and it was merged.

Change subject: forceRenameUsers: Replace _ in database name with -
......................................................................


forceRenameUsers: Replace _ in database name with -

Underscores (_) are not valid in usernames, and are normally replaced
with spaces. But those look funny to some people, so use dashes (-)
instead. Also canonicalize the username so we don't end up with invalid
usernames in the database.

Change-Id: I56e83a23e25f90358b18e51d2d3d9679e0158c55
---
M includes/CentralAuthPlugin.php
M maintenance/forceRenameUsers.php
M tests/CentralAuthPluginUsingDatabaseTest.php
3 files changed, 29 insertions(+), 19 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/CentralAuthPlugin.php b/includes/CentralAuthPlugin.php
index fb903a9..a9bcd74 100644
--- a/includes/CentralAuthPlugin.php
+++ b/includes/CentralAuthPlugin.php
@@ -51,23 +51,25 @@
                if ( !$passwordMatch && $wgCentralAuthCheckSULMigration ) {
                        // Check to see if this is a user who was affected by a 
global username
                        // collision during a forced migration to central auth 
accounts.
-                       $renamedUsername = $username . '~' . wfWikiID();
-                       wfDebugLog( 'CentralAuth',
-                               "CentralAuthMigration: Checking for migration 
of '{$username}' to '{$renamedUsername}'"
-                       );
+                       $renamedUsername = User::getCanonicalName( $username . 
'~' . str_replace( '_', '-', wfWikiID() ) );
+                       if ( $renamedUsername !== false ) {
+                               wfDebugLog( 'CentralAuth',
+                                       "CentralAuthMigration: Checking for 
migration of '{$username}' to '{$renamedUsername}'"
+                               );
 
-                       $renamed = new CentralAuthUser( $renamedUsername );
-                       $passwordMatch = self::checkPassword( $renamed, 
$password );
+                               $renamed = new CentralAuthUser( 
$renamedUsername );
+                               $passwordMatch = self::checkPassword( $renamed, 
$password );
 
-                       // Remember that the user was authenticated under a 
different name.
-                       if ( $passwordMatch ) {
-                               $this->sulMigrationName = $renamedUsername;
+                               // Remember that the user was authenticated 
under a different name.
+                               if ( $passwordMatch ) {
+                                       $this->sulMigrationName = 
$renamedUsername;
+                               }
+
+                               // Since we are falling back to check a force 
migrated user, we are done
+                               // regardless of password match status. We 
don't want to try to
+                               // automigrate or check detached accounts.
+                               return $passwordMatch;
                        }
-
-                       // Since we are falling back to check a force migrated 
user, we are done
-                       // regardless of password match status. We don't want 
to try to
-                       // automigrate or check detached accounts.
-                       return $passwordMatch;
                }
 
                if ( !$central->exists() ) {
diff --git a/maintenance/forceRenameUsers.php b/maintenance/forceRenameUsers.php
index 8d92b56..42bd405 100644
--- a/maintenance/forceRenameUsers.php
+++ b/maintenance/forceRenameUsers.php
@@ -65,7 +65,15 @@
        protected function rename( $row, DatabaseBase $dbw ) {
                $wiki = $row->utr_wiki;
                $name = $row->utr_name;
-               $newNamePrefix = "$name~$wiki";
+               $newNamePrefix = User::getCanonicalName(
+                       // Some database names have _'s in them, replace with 
dashes -
+                       $name . '~' . str_replace( '_', '-', $wiki ),
+                       'usable'
+               );
+               if ( !$newNamePrefix ) {
+                       $this->log( "ERROR: New name '$name~$wiki' is not 
valid" );
+                       return;
+               }
                $this->log( "Beginning rename of $newNamePrefix" );
                $newCAUser = new CentralAuthUser( $newNamePrefix );
                $count = 0;
diff --git a/tests/CentralAuthPluginUsingDatabaseTest.php 
b/tests/CentralAuthPluginUsingDatabaseTest.php
index 55ed6dc..24c9fdb 100644
--- a/tests/CentralAuthPluginUsingDatabaseTest.php
+++ b/tests/CentralAuthPluginUsingDatabaseTest.php
@@ -90,7 +90,7 @@
 
                // Global user who was renamed when migrated
                $u = new CentralAuthTestUser(
-                       'GlobalUser~' . self::safeWfWikiID(),
+                       'GlobalUser~' . str_replace( '_', '-', 
self::safeWfWikiID() ),
                        'GURP@ssword',
                        array( 'gu_id' => '1006' ),
                        array(
@@ -208,7 +208,7 @@
                        ),
                        array(
                                'GlobalUser', 'GURP@ssword', true,
-                               true, 'GlobalUser~' . self::safeWfWikiID(),
+                               true, 'GlobalUser~' . str_replace( '_', '-', 
self::safeWfWikiID() ),
                                'wgCentralAuthCheckSULMigration enabled; 
correct password',
                        ),
                        array(
@@ -248,7 +248,7 @@
        public function provideUpdateUserRenameAnnotation() {
                return array(
                        array(
-                               'GlobalUser', false, 'GlobalUser~' . 
self::safeWfWikiID(),
+                               'GlobalUser', false, 'GlobalUser~' . 
str_replace( '_', '-', self::safeWfWikiID() ),
                                false, false,
                                'wgCentralAuthCheckSULMigration disabled; 
sulMigrationName set',
                        ),
@@ -258,7 +258,7 @@
                                'wgCentralAuthCheckSULMigration disabled; 
sulMigrationName unset',
                        ),
                        array(
-                               'GlobalUser', true, 'GlobalUser~' . 
self::safeWfWikiID(),
+                               'GlobalUser', true, 'GlobalUser~' . 
str_replace( '_', '-', self::safeWfWikiID() ),
                                true, true,
                                'wgCentralAuthCheckSULMigration enabled; 
sulMigrationName set',
                        ),

-- 
To view, visit https://gerrit.wikimedia.org/r/204827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I56e83a23e25f90358b18e51d2d3d9679e0158c55
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to