Skip to content

Commit

Permalink
Merge pull request jenkinsci#6189 from daniel-beck/test-UMOMNEE
Browse files Browse the repository at this point in the history
Confirm that UMOMNEE2 is translated to UMOMNEE in legacy API
  • Loading branch information
MarkEWaite authored Jan 22, 2022
2 parents 612e606 + e446fee commit 708c2df
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/src/test/java/hudson/model/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit 708c2df

Please sign in to comment.