Add test that jnlp launch contains the alt url
@@ -25,6 +25,7 @@ package hudson.slaves;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.xml.XmlPage;
import hudson.Proc;
import hudson.Util;
import hudson.model.Computer;
@@ -34,18 +35,24 @@ import hudson.model.Slave;
import hudson.remoting.Which;
import hudson.util.ArgumentListBuilder;
+import jenkins.model.JenkinsLocationConfiguration;
import jenkins.security.SlaveToMasterCallable;
+import jenkins.security.apitoken.ApiTokenTestHelper;
import jenkins.slaves.RemotingWorkDirSettings;
+import org.dom4j.Document;
+import org.dom4j.io.DOMReader;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.SmokeTest;
import org.jvnet.hudson.test.TestExtension;
import java.io.File;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -64,6 +71,7 @@ import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.recipes.LocalData;
+import org.jvnet.hudson.test.recipes.PresetData;
/**
* Tests of {@link JNLPLauncher}.
@@ -114,6 +122,29 @@ public class JNLPLauncherTest {
assertEquals(1, ComputerListener.all().get(ListenerImpl.class).offlined);
}
+ @PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
+ @Email("http://markmail.org/message/on4wkjdaldwi2atx")
+ @Test
+ public void testUniqueJnlpRoot() throws Exception {
+ ApiTokenTestHelper.enableLegacyBehavior();
+
+ // Override the jnlp root
+ String jnlpRoot = new URL("http://localhost:8080" + j.contextPath + "/").toString();
+ JenkinsLocationConfiguration config = JenkinsLocationConfiguration.get();
+ config.setJnlpRoot(jnlpRoot);
+
+ addTestSlave(false);
+ JenkinsRule.WebClient jnlpAgent = j.createWebClient().login("alice");
+
+ // parse the JNLP page into DOM to inspect the jnlp url argument.
+ XmlPage jnlp = (XmlPage) jnlpAgent.goTo("computer/test/slave-agent.jnlp","application/x-java-jnlp-file");
+ Document dom = new DOMReader().read(jnlp.getXmlDocument());
+ for( Object arg : dom.selectNodes("//application-desc/argument[3]/following-sibling::argument[1]") ) {
+ String val = ((org.dom4j.Element)arg).getText();
+ assertEquals(jnlpRoot, val);
+ }
+ }
+
@Test
@Issue("JENKINS-44112")
public void testHeadlessLaunchWithWorkDir() throws Exception {
