j.createWebClient().goTo("api/xml?xpath=/*[1]", "application/xml");
}
@Test
@Issue("JENKINS-3267")
public void wrappedZeroItems() throws Exception {
Page page = j.createWebClient().goTo("api/xml?wrapper=root&xpath=/hudson/nonexistent", "application/xml");
assertEquals("", page.getWebResponse().getContentAsString());
}
/**
* Test that calling the XML API with the XPath document function fails.
*
* @throws Exception if so
*/
@Issue("SECURITY-165")
@Test public void xPathDocumentFunction() throws Exception {
File f = new File(j.jenkins.getRootDir(), "queue.xml");
JenkinsRule.WebClient client = j.createWebClient();
try {
client.goTo("api/xml?xpath=document(\"" + f.getAbsolutePath() + "\")", "application/xml");
fail("Should become 500 error");
} catch (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException e) {
String contentAsString = e.getResponse().getContentAsString();
j.assertStringContains(
contentAsString,
"Illegal function: document");
}
}
@Test
@Issue("JENKINS-3267")
public void wrappedOneItem() throws Exception {
Page page = j.createWebClient().goTo("api/xml?wrapper=root&xpath=/hudson/view/name", "application/xml");
assertEquals("All", page.getWebResponse().getContentAsString());
}
@Test
public void wrappedMultipleItems() throws Exception {
j.createFreeStyleProject();
j.createFreeStyleProject();
Page page = j.createWebClient().goTo("api/xml?wrapper=root&xpath=/hudson/job/name", "application/xml");
assertEquals("test0test1", page.getWebResponse().getContentAsString());
}
@Test
public void unwrappedZeroItems() throws Exception {
j.createWebClient().assertFails("api/xml?xpath=/hudson/nonexistent", HttpURLConnection.HTTP_NOT_FOUND);
}
@Test
public void unwrappedOneItem() throws Exception {
Page page = j.createWebClient().goTo("api/xml?xpath=/hudson/view/name", "application/xml");
assertEquals("All", page.getWebResponse().getContentAsString());
}
@Test
public void unwrappedLongString() throws Exception {
j.jenkins.setSystemMessage("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
Page page = j.createWebClient().goTo("api/xml?xpath=/hudson/description", "application/xml");
assertEquals(
""+j.jenkins.getSystemMessage()+"",
page.getWebResponse().getContentAsString());
}
@Test
public void unwrappedMultipleItems() throws Exception {
j.createFreeStyleProject();
j.createFreeStyleProject();
j.createWebClient().assertFails("api/xml?xpath=/hudson/job/name", HttpURLConnection.HTTP_INTERNAL_ERROR);
}
} |