From fdda9ca65689423794a8378c1f28faca7dffddf0 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Sun, 23 Feb 2014 17:48:44 -0500 Subject: [PATCH] [FIXED JENKINS-16332] Ensure that User records are saved when the fullName is not recoverable from the id. Otherwise User.get(id).getFullName() after restarting Jenkins will produce the wrong result. --- changelog.html | 3 +++ core/src/main/java/hudson/model/User.java | 10 +++++++--- test/src/test/java/hudson/model/UserTest.java | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/changelog.html b/changelog.html index da9b4b1f6f..aaef3eefb5 100644 --- a/changelog.html +++ b/changelog.html @@ -62,6 +62,9 @@ Upcoming changes
  • Random class loading error mostly known to affect static analysis plugins. (issue 12124) +
  • + After restarting Jenkins, users known only from changelogs could be shown as First Last _first.last@some.org_, breaking mail delivery. + (issue 16332)
  • CLI build -s -v command caused 100% CPU usage on the master. (issue 20965) diff --git a/core/src/main/java/hudson/model/User.java b/core/src/main/java/hudson/model/User.java index e72c6fe3cb..3d9cdbb5b5 100644 --- a/core/src/main/java/hudson/model/User.java +++ b/core/src/main/java/hudson/model/User.java @@ -350,9 +350,13 @@ public class User extends AbstractModelObject implements AccessControlled, Descr if (LOGGER.isLoggable(Level.FINE) && !fullName.equals(prev.getFullName())) { LOGGER.log(Level.FINE, "mismatch on fullName (‘" + fullName + "’ vs. ‘" + prev.getFullName() + "’) for ‘" + id + "’", new Throwable()); } - } - if (LOGGER.isLoggable(Level.FINE) && id.equals(fullName) && fullName.matches(".+ _\\S+@\\S+_")) { - LOGGER.log(Level.FINE, "[JENKINS-16332] Suspicious fullName being stored: " + fullName, new Throwable()); + } else if (!id.equals(fullName) && !getConfigFileFor(id).exists()) { + // JENKINS-16332: since the fullName may not be recoverable from the id, and various code may store the id only, we must save the fullName + try { + u.save(); + } catch (IOException x) { + LOGGER.log(Level.WARNING, null, x); + } } } return u; diff --git a/test/src/test/java/hudson/model/UserTest.java b/test/src/test/java/hudson/model/UserTest.java index fe232fb60a..a8f37057a4 100644 --- a/test/src/test/java/hudson/model/UserTest.java +++ b/test/src/test/java/hudson/model/UserTest.java @@ -32,6 +32,7 @@ import hudson.security.AccessDeniedException2; import hudson.security.GlobalMatrixAuthorizationStrategy; import hudson.security.HudsonPrivateSecurityRealm; import hudson.security.Permission; +import hudson.tasks.MailAddressResolver; import java.io.IOException; import java.io.PrintStream; import java.util.Collections; @@ -266,6 +267,16 @@ public class UserTest { assertNotNull("User should be saved with all changes.", user.getProperty(SomeUserProperty.class)); } + @Bug(16332) + @Test public void unrecoverableFullName() throws Throwable { + User u = User.get("John Smith "); + assertEquals("jsmith@nowhere.net", MailAddressResolver.resolve(u)); + String id = u.getId(); + User.clear(); // simulate Jenkins restart + u = User.get(id); + assertEquals("jsmith@nowhere.net", MailAddressResolver.resolve(u)); + } + @Test public void testDelete() throws IOException { User user = User.get("John Smith", true, Collections.emptyMap()); -- GitLab