Skip to content

Commit

Permalink
Merge branch 'stable-2.150' into security-stable-2.150
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Nov 22, 2018
2 parents 90b6d47 + af455a6 commit 79384ef
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli/src/main/java/hudson/cli/CLI.java
Expand Up @@ -705,13 +705,13 @@ private synchronized void finished() {
connection.sendLocale(Locale.getDefault().toString());
connection.sendStart();
connection.begin();
final OutputStream stdin = connection.streamStdin();
new Thread("input reader") {
@Override
public void run() {
try {
final OutputStream stdin = connection.streamStdin();
int c;
while ((c = System.in.read()) != -1) { // TODO use InputStream.available
while (!connection.complete && (c = System.in.read()) != -1) {
stdin.write(c);
}
connection.sendEndStdin();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/Functions.java
Expand Up @@ -1827,7 +1827,7 @@ public static Locale getCurrentLocale() {
* from {@link ConsoleAnnotatorFactory}s and {@link ConsoleAnnotationDescriptor}s.
*/
public static String generateConsoleAnnotationScriptAndStylesheet() {
String cp = Stapler.getCurrentRequest().getContextPath();
String cp = Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH;
StringBuilder buf = new StringBuilder();
for (ConsoleAnnotatorFactory f : ConsoleAnnotatorFactory.all()) {
String path = cp + "/extensionList/" + ConsoleAnnotatorFactory.class.getName() + "/" + f.getClass().getName();
Expand Down
24 changes: 24 additions & 0 deletions test/src/test/java/hudson/cli/CLITest.java
Expand Up @@ -255,6 +255,30 @@ public void redirectToEndpointShouldBeFollowed() throws Exception {
assertEquals(0, ret);
}
}

@Test
@Issue("JENKINS-54310")
public void readInputAtOnce() throws Exception {
home = tempHome();
grabCliJar();

try (ByteArrayOutputStream baos = new ByteArrayOutputStream();) {
int ret = new Launcher.LocalLauncher(StreamTaskListener.fromStderr())
.launch()
.cmds("java",
"-Duser.home=" + home,
"-jar", jar.getAbsolutePath(),
"-s", r.getURL().toString(),
"list-plugins") // This CLI Command needs -auth option, so when we omit it, the CLI stops before reading the input.
.stdout(baos)
.stderr(baos)
.stdin(CLITest.class.getResourceAsStream("huge-stdin.txt"))
.join();
assertThat(baos.toString(), not(containsString("java.io.IOException: Stream is closed")));
assertEquals(0, ret);
}
}

@TestExtension("redirectToEndpointShouldBeFollowed")
public static final class CliProxyAction extends CrumbExclusion implements UnprotectedRootAction, StaplerProxy {

Expand Down
8 changes: 8 additions & 0 deletions test/src/test/java/hudson/console/ConsoleAnnotatorTest.java
Expand Up @@ -3,6 +3,7 @@
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.TextPage;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.FilePath;
Expand All @@ -27,6 +28,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
import jenkins.model.Jenkins;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
import org.junit.Rule;
Expand Down Expand Up @@ -288,6 +290,12 @@ public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {}
// verify that there's an element inserted by the script
assertNotNull(html.getElementById("inserted-by-test1"));
assertNotNull(html.getElementById("inserted-by-test2"));
for (DomElement e : html.getElementsByTagName("script")) {
String src = e.getAttribute("src");
if (!src.isEmpty()) {
assertThat(src, containsString(Jenkins.SESSION_HASH));
}
}
}

public static final class JustToIncludeScript extends ConsoleNote<Object> {
Expand Down

0 comments on commit 79384ef

Please sign in to comment.