提交 71014c53 编写于 作者: J Jesse Glick

Merge branch 'security-stable-1.642' into security-stable-1.651

......@@ -28,6 +28,7 @@ import hudson.Functions;
import hudson.model.Computer;
import hudson.model.User;
import jenkins.model.Jenkins;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
......@@ -147,7 +148,7 @@ public abstract class OfflineCause {
}
private UserCause(String userId, String message) {
super(hudson.slaves.Messages._SlaveComputer_DisconnectedBy(userId, message));
super(hudson.slaves.Messages._SlaveComputer_DisconnectedBy(userId != null ? userId : Jenkins.ANONYMOUS.getName(), message));
this.userId = userId;
}
......
......@@ -51,10 +51,15 @@ import java.util.*;
import java.util.concurrent.Callable;
import jenkins.model.Jenkins;
import jenkins.security.NotReallyRoleSensitiveCallable;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContextHolder;
import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.junit.Assert.*;
import org.jenkinsci.remoting.RoleChecker;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -123,6 +128,40 @@ public class NodeTest {
assertNull(computer.getOfflineCause());
}
@Test
public void testOfflineCauseAsAnonymous() throws Exception {
Node node = j.createOnlineSlave();
final Computer computer = node.toComputer();
OfflineCause.UserCause cause;
ACL.impersonate(Jenkins.ANONYMOUS, new NotReallyRoleSensitiveCallable() {
@Override
public Void call() throws Exception {
computer.doToggleOffline("original message");
return null;
}
});
cause = (UserCause) computer.getOfflineCause();
assertThat(cause.toString(), endsWith("Disconnected by anonymous : original message"));
assertEquals(User.getUnknown(), cause.getUser());
final User root = User.get("root@localhost");
ACL.impersonate(root.impersonate(), new NotReallyRoleSensitiveCallable() {
@Override
public Void call() throws Exception {
computer.doChangeOfflineCause("new message");
return null;
}
});
cause = (UserCause) computer.getOfflineCause();
assertThat(cause.toString(), endsWith("Disconnected by root@localhost : new message"));
assertEquals(root, cause.getUser());
computer.doToggleOffline(null);
assertNull(computer.getOfflineCause());
}
@Test
public void testGetLabelCloud() throws Exception {
Node node = j.createOnlineSlave();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册