提交 00a75819 编写于 作者: J Jesse Glick

Merge branch 'security-stable-2.19' into security-stable-2.32

...@@ -189,9 +189,11 @@ public abstract class ConsoleNote<T> implements Serializable, Describable<Consol ...@@ -189,9 +189,11 @@ public abstract class ConsoleNote<T> implements Serializable, Describable<Consol
DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null));
try { try {
buf2.write(PREAMBLE); buf2.write(PREAMBLE);
byte[] mac = MAC.mac(buf.toByteArray()); if (Jenkins.getInstanceOrNull() != null) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE
dos.writeInt(- mac.length); // negative to differentiate from older form byte[] mac = MAC.mac(buf.toByteArray());
dos.write(mac); dos.writeInt(- mac.length); // negative to differentiate from older form
dos.write(mac);
}
dos.writeInt(buf.size()); dos.writeInt(buf.size());
buf.writeTo(dos); buf.writeTo(dos);
} finally { } finally {
......
...@@ -59,9 +59,7 @@ public abstract class ConfidentialStore { ...@@ -59,9 +59,7 @@ public abstract class ConfidentialStore {
* Retrieves the currently active singleton instance of {@link ConfidentialStore}. * Retrieves the currently active singleton instance of {@link ConfidentialStore}.
*/ */
public static @Nonnull ConfidentialStore get() { public static @Nonnull ConfidentialStore get() {
if (TEST != null) { if (TEST!=null) return TEST.get();
return TEST;
}
Jenkins j = Jenkins.getInstance(); Jenkins j = Jenkins.getInstance();
Lookup lookup = j.lookup; Lookup lookup = j.lookup;
...@@ -92,7 +90,7 @@ public abstract class ConfidentialStore { ...@@ -92,7 +90,7 @@ public abstract class ConfidentialStore {
/** /**
* Testing only. Used for testing {@link ConfidentialKey} without {@link Jenkins} * Testing only. Used for testing {@link ConfidentialKey} without {@link Jenkins}
*/ */
/*package*/ static ConfidentialStore TEST = null; /*package*/ static ThreadLocal<ConfidentialStore> TEST = null;
private static final Logger LOGGER = Logger.getLogger(ConfidentialStore.class.getName()); private static final Logger LOGGER = Logger.getLogger(ConfidentialStore.class.getName());
} }
package hudson.model; package hudson.model;
import static org.junit.Assert.*; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import hudson.console.AnnotatedLargeText; import hudson.console.AnnotatedLargeText;
import hudson.security.ACL; import hudson.security.ACL;
import hudson.security.Permission; import hudson.security.Permission;
import jenkins.security.ConfidentialStoreRule;
import org.acegisecurity.Authentication; import org.acegisecurity.Authentication;
import static org.hamcrest.CoreMatchers.startsWith;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
/** /**
...@@ -18,9 +15,6 @@ import org.junit.Test; ...@@ -18,9 +15,6 @@ import org.junit.Test;
*/ */
public class TaskActionTest { public class TaskActionTest {
@Rule
public ConfidentialStoreRule confidentialStoreRule = new ConfidentialStoreRule();
private static class MyTaskThread extends TaskThread { private static class MyTaskThread extends TaskThread {
MyTaskThread(TaskAction taskAction) { MyTaskThread(TaskAction taskAction) {
super(taskAction, ListenerAndText.forMemory(taskAction)); super(taskAction, ListenerAndText.forMemory(taskAction));
...@@ -69,6 +63,6 @@ public class TaskActionTest { ...@@ -69,6 +63,6 @@ public class TaskActionTest {
} }
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
annotatedText.writeLogTo(0, os); annotatedText.writeLogTo(0, os);
assertThat(os.toString("UTF-8"), startsWith("a linkCompleted")); assertTrue(os.toString("UTF-8").startsWith("a linkCompleted"));
} }
} }
...@@ -14,13 +14,16 @@ public class ConfidentialStoreRule extends ExternalResource { ...@@ -14,13 +14,16 @@ public class ConfidentialStoreRule extends ExternalResource {
@Override @Override
protected void before() throws Throwable { protected void before() throws Throwable {
tmp.create(); tmp.create();
ConfidentialStore.TEST = new DefaultConfidentialStore(tmp.getRoot()); ConfidentialStore.TEST.set(new DefaultConfidentialStore(tmp.getRoot()));
} }
@Override @Override
protected void after() { protected void after() {
ConfidentialStore.TEST = null; ConfidentialStore.TEST.set(null);
tmp.delete(); tmp.delete();
} }
static {
ConfidentialStore.TEST = new ThreadLocal<ConfidentialStore>();
}
} }
...@@ -29,23 +29,23 @@ import java.io.ByteArrayOutputStream; ...@@ -29,23 +29,23 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.StringWriter; import java.io.StringWriter;
import jenkins.security.ConfidentialStoreRule;
import org.apache.commons.io.Charsets; import org.apache.commons.io.Charsets;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.For; import org.jvnet.hudson.test.For;
import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.framework.io.ByteBuffer; import org.kohsuke.stapler.framework.io.ByteBuffer;
@For({AnnotatedLargeText.class, ConsoleNote.class, ConsoleAnnotationOutputStream.class, PlainTextConsoleOutputStream.class}) @For({AnnotatedLargeText.class, ConsoleNote.class, ConsoleAnnotationOutputStream.class, PlainTextConsoleOutputStream.class})
public class AnnotatedLargeTextTest { public class AnnotatedLargeTextTest {
@Rule @ClassRule
public ConfidentialStoreRule confidentialStoreRule = new ConfidentialStoreRule(); public static JenkinsRule r = new JenkinsRule();
/* TODO in trunk: /* TODO in master:
@Rule @Rule
public LoggerRule logging = new LoggerRule().record(ConsoleAnnotationOutputStream.class, Level.FINE).capture(100); public LoggerRule logging = new LoggerRule().record(ConsoleAnnotationOutputStream.class, Level.FINE).capture(100);
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册