From 2b80a6e203f7c02fc2763b13e33715535f5e121f Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Tue, 18 Jan 2022 16:11:42 +0100 Subject: [PATCH] Confirm that UMOMNEE2 is translated to UMOMNEE in legacy API --- test/src/test/java/hudson/model/UserTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/src/test/java/hudson/model/UserTest.java b/test/src/test/java/hudson/model/UserTest.java index d4900d0286c5..a3e35cf2f6c1 100644 --- a/test/src/test/java/hudson/model/UserTest.java +++ b/test/src/test/java/hudson/model/UserTest.java @@ -55,6 +55,8 @@ import hudson.security.GroupDetails; import hudson.security.HudsonPrivateSecurityRealm; import hudson.security.Permission; +import hudson.security.SecurityRealm; +import hudson.security.UserMayOrMayNotExistException; import hudson.security.UserMayOrMayNotExistException2; import hudson.tasks.MailAddressResolver; import java.io.File; @@ -775,4 +777,26 @@ public WebResponse getResponse(WebRequest request) throws IOException { assertThat(failingResources, empty()); } + @Test + public void legacyCallerGetsUserMayOrMayNotExistException() { + final SecurityRealm realm = new NonEnumeratingAcegiSecurityRealm(); + assertThrows(UserMayOrMayNotExistException.class, () -> realm.loadUserByUsername("unknown")); + + final SecurityRealm realm2 = new NonEnumeratingSpringSecurityRealm(); + assertThrows(UserMayOrMayNotExistException.class, () -> realm2.loadUserByUsername("unknown")); + } + + private static class NonEnumeratingAcegiSecurityRealm extends AbstractPasswordBasedSecurityRealm { + @Override + public org.acegisecurity.userdetails.UserDetails loadUserByUsername(String username) throws org.acegisecurity.userdetails.UsernameNotFoundException { + throw new UserMayOrMayNotExistException(username + " not found"); + } + } + + private static class NonEnumeratingSpringSecurityRealm extends AbstractPasswordBasedSecurityRealm { + @Override + public UserDetails loadUserByUsername2(String username) throws UsernameNotFoundException { + throw new UserMayOrMayNotExistException2(username + " not found"); + } + } }