diff --git a/test/src/test/java/hudson/model/UserTest.java b/test/src/test/java/hudson/model/UserTest.java index 0177dea736293d6654cc788b90bb2824f2672c69..8e57f81b08b4eb71cf3397c3c4ae5bcc25afcc37 100644 --- a/test/src/test/java/hudson/model/UserTest.java +++ b/test/src/test/java/hudson/model/UserTest.java @@ -408,16 +408,19 @@ public class UserTest { User user = realm.createAccount("John Smith","password"); User user2 = realm.createAccount("John Smith2","password"); user2.save(); + User user3 = User.get("Random Somebody"); + SecurityContextHolder.getContext().setAuthentication(user.impersonate()); assertFalse("User should not be able delete because he does not have administer permission.", user2.canDelete()); auth.add(Jenkins.ADMINISTER, user.getId()); assertTrue("User should be able to delete.", user2.canDelete()); assertFalse("User should not be able to delete because it is current user.", user.canDelete()); + SecurityContextHolder.getContext().setAuthentication(user2.impersonate()); auth.add(Jenkins.ADMINISTER, user2.getId()); - assertFalse("User should not be able to delete because he is not saved.", user.canDelete()); - user.save(); - assertTrue("User should be able to delete.", user.canDelete()); + assertFalse("User should not be able to delete because he is not saved.", user3.canDelete()); + user3.save(); + assertTrue("User should be able to delete.", user3.canDelete()); } @Test