提交 3bb56b81 编写于 作者: W Wadeck Follonier

[JENKINS-53511] Bump of JTH to include new methods in WebClient

- And thus, adapt the code due to the breaking changes in JTH sub-lib
上级 bc028237
...@@ -54,7 +54,7 @@ THE SOFTWARE. ...@@ -54,7 +54,7 @@ THE SOFTWARE.
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness</artifactId> <artifactId>jenkins-test-harness</artifactId>
<version>2.41.1</version> <version>2.42</version>
<scope>test</scope> <scope>test</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
......
...@@ -34,6 +34,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm; ...@@ -34,6 +34,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.xml.XmlPage; import com.gargoylesoftware.htmlunit.xml.XmlPage;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import hudson.slaves.DumbSlave; import hudson.slaves.DumbSlave;
...@@ -109,7 +110,7 @@ public class ComputerTest { ...@@ -109,7 +110,7 @@ public class ComputerTest {
private void verifyOfflineCause(Computer computer) throws Exception { private void verifyOfflineCause(Computer computer) throws Exception {
XmlPage page = j.createWebClient().goToXml("computer/" + computer.getName() + "/config.xml"); XmlPage page = j.createWebClient().goToXml("computer/" + computer.getName() + "/config.xml");
String content = page.getWebResponse().getContentAsString("UTF-8"); String content = page.getWebResponse().getContentAsString(StandardCharsets.UTF_8);
assertThat(content, containsString("temporaryOfflineCause")); assertThat(content, containsString("temporaryOfflineCause"));
assertThat(content, containsString("<userId>username</userId>")); assertThat(content, containsString("<userId>username</userId>"));
assertThat(content, not(containsString("ApiTokenProperty"))); assertThat(content, not(containsString("ApiTokenProperty")));
......
...@@ -25,6 +25,7 @@ package hudson.model; ...@@ -25,6 +25,7 @@ package hudson.model;
import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.javascript.host.event.Event;
import hudson.*; import hudson.*;
import hudson.model.queue.QueueTaskFuture; import hudson.model.queue.QueueTaskFuture;
import hudson.security.AccessDeniedException2; import hudson.security.AccessDeniedException2;
...@@ -252,7 +253,8 @@ public class ProjectTest { ...@@ -252,7 +253,8 @@ public class ProjectTest {
assertEquals("Scm retry count should be the same as global scm retry count.", 6, p.getScmCheckoutRetryCount()); assertEquals("Scm retry count should be the same as global scm retry count.", 6, p.getScmCheckoutRetryCount());
HtmlForm form = j.createWebClient().goTo(p.getUrl() + "/configure").getFormByName("config"); HtmlForm form = j.createWebClient().goTo(p.getUrl() + "/configure").getFormByName("config");
((HtmlElement)form.getByXPath("//div[@class='advancedLink']//button").get(0)).click(); ((HtmlElement)form.getByXPath("//div[@class='advancedLink']//button").get(0)).click();
form.getInputByName("hasCustomScmCheckoutRetryCount").click(); // required due to the new default behavior of click
form.getInputByName("hasCustomScmCheckoutRetryCount").click(new Event(), true);
form.getInputByName("scmCheckoutRetryCount").setValueAttribute("7"); form.getInputByName("scmCheckoutRetryCount").setValueAttribute("7");
j.submit(form); j.submit(form);
assertEquals("Scm retry count was set.", 7, p.getScmCheckoutRetryCount()); assertEquals("Scm retry count was set.", 7, p.getScmCheckoutRetryCount());
......
...@@ -246,7 +246,7 @@ public class ViewTest { ...@@ -246,7 +246,7 @@ public class ViewTest {
ListView view = listView("v"); ListView view = listView("v");
view.description = "one"; view.description = "one";
WebClient wc = j.createWebClient(); WebClient wc = j.createWebClient();
String xml = wc.goToXml("view/v/config.xml").getContent(); String xml = wc.goToXml("view/v/config.xml").getWebResponse().getContentAsString();
assertTrue(xml, xml.contains("<description>one</description>")); assertTrue(xml, xml.contains("<description>one</description>"));
xml = xml.replace("<description>one</description>", "<description>two</description>"); xml = xml.replace("<description>one</description>", "<description>two</description>");
WebRequest req = new WebRequest(wc.createCrumbedUrl("view/v/config.xml"), HttpMethod.POST); WebRequest req = new WebRequest(wc.createCrumbedUrl("view/v/config.xml"), HttpMethod.POST);
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
package hudson.tools; package hudson.tools;
import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.InteractivePage;
import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
...@@ -148,7 +147,7 @@ public class ZipExtractionInstallerTest { ...@@ -148,7 +147,7 @@ public class ZipExtractionInstallerTest {
} }
@Override @Override
public Object callFunction(InteractivePage page, Function function, Scriptable scope, Scriptable thisObject, Object[] args) { public Object callFunction(HtmlPage page, Function function, Scriptable scope, Scriptable thisObject, Object[] args) {
if (thisObject instanceof XMLHttpRequest) { if (thisObject instanceof XMLHttpRequest) {
try { try {
WebRequest request = getPrivateWebRequestField((XMLHttpRequest) thisObject); WebRequest request = getPrivateWebRequestField((XMLHttpRequest) thisObject);
......
...@@ -41,7 +41,10 @@ public class Jenkins19124Test { ...@@ -41,7 +41,10 @@ public class Jenkins19124Test {
JenkinsRule.WebClient wc = j.createWebClient(); JenkinsRule.WebClient wc = j.createWebClient();
HtmlPage c = wc.getPage(p, "configure"); HtmlPage c = wc.getPage(p, "configure");
HtmlTextInput alpha = c.getElementByName("_.alpha"); HtmlTextInput alpha = c.getElementByName("_.alpha");
// the fireEvent is required as setValueAttribute's new behavior is not triggering the onChange event anymore
alpha.setValueAttribute("hello"); alpha.setValueAttribute("hello");
alpha.fireEvent("change");
WebClientUtil.waitForJSExec(wc); WebClientUtil.waitForJSExec(wc);
assertEquals("hello", d.alpha); assertEquals("hello", d.alpha);
assertEquals("2", d.bravo); assertEquals("2", d.bravo);
......
...@@ -11,7 +11,6 @@ import hudson.Util; ...@@ -11,7 +11,6 @@ import hudson.Util;
import hudson.util.Secret; import hudson.util.Secret;
import hudson.util.SecretHelper; import hudson.util.SecretHelper;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.hamcrest.CoreMatchers;
import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.recipes.Recipe.Runner; import org.jvnet.hudson.test.recipes.Recipe.Runner;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
...@@ -22,8 +21,7 @@ import java.io.File; ...@@ -22,8 +21,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream;
import static org.junit.Assert.assertThat;
/** /**
* @author Kohsuke Kawaguchi * @author Kohsuke Kawaguchi
...@@ -132,7 +130,18 @@ public class RekeySecretAdminMonitorTest extends HudsonTestCase { ...@@ -132,7 +130,18 @@ public class RekeySecretAdminMonitorTest extends HudsonTestCase {
} }
private HtmlButton getButton(HtmlForm form, int index) { private HtmlButton getButton(HtmlForm form, int index) {
return form.<HtmlButton>getHtmlElementsByTagName("button").get(index); // due to the removal of method HtmlElement.getHtmlElementsByTagName
Stream<HtmlButton> buttonStream = form.getElementsByTagName("button").stream()
.filter(HtmlButton.class::isInstance)
.map(HtmlButton.class::cast);
if (index > 0) {
buttonStream = buttonStream.skip(index - 1);
}
return buttonStream
.findFirst()
.orElse(null);
} }
public void testScanOnBoot() throws Exception { public void testScanOnBoot() throws Exception {
......
...@@ -148,7 +148,7 @@ public class PasswordTest { ...@@ -148,7 +148,7 @@ public class PasswordTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
String pName = p.getFullName(); String pName = p.getFullName();
getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err); getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err);
assertEquals(xmlAdmin, baos.toString(configXml.getWebResponse().getContentCharset())); assertEquals(xmlAdmin, baos.toString(configXml.getWebResponse().getContentCharset().name()));
CopyJobCommand copyJobCommand = new CopyJobCommand(); CopyJobCommand copyJobCommand = new CopyJobCommand();
copyJobCommand.setTransportAuth(adminAuth); copyJobCommand.setTransportAuth(adminAuth);
String pAdminName = pName + "-admin"; String pAdminName = pName + "-admin";
...@@ -171,7 +171,7 @@ public class PasswordTest { ...@@ -171,7 +171,7 @@ public class PasswordTest {
getJobCommand.setTransportAuth(devAuth); getJobCommand.setTransportAuth(devAuth);
baos = new ByteArrayOutputStream(); baos = new ByteArrayOutputStream();
getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err); getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err);
assertEquals(xmlDev, baos.toString(configXml.getWebResponse().getContentCharset())); assertEquals(xmlDev, baos.toString(configXml.getWebResponse().getContentCharset().name()));
copyJobCommand = new CopyJobCommand(); copyJobCommand = new CopyJobCommand();
copyJobCommand.setTransportAuth(devAuth); copyJobCommand.setTransportAuth(devAuth);
String pDevName = pName + "-dev"; String pDevName = pName + "-dev";
...@@ -194,7 +194,9 @@ public class PasswordTest { ...@@ -194,7 +194,9 @@ public class PasswordTest {
} }
VulnerableProperty.DescriptorImpl.incomingURL = null; VulnerableProperty.DescriptorImpl.incomingURL = null;
String secret = "s3cr3t"; String secret = "s3cr3t";
// the fireEvent is required as setText's new behavior is not triggering the onChange event anymore
field.setText(secret); field.setText(secret);
field.fireEvent("change");
while (VulnerableProperty.DescriptorImpl.incomingURL == null) { while (VulnerableProperty.DescriptorImpl.incomingURL == null) {
Thread.sleep(100); // form validation of edited value Thread.sleep(100); // form validation of edited value
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册