Search in sources :

Example 6 with Email

use of org.jvnet.hudson.test.Email in project jenkins by jenkinsci.

the class JnlpAccessWithSecuredHudsonTest method anonymousCanAlwaysLoadJARs.

@PresetData(DataSet.NO_ANONYMOUS_READACCESS)
@Email("http://markmail.org/message/on4wkjdaldwi2atx")
@Test
public void anonymousCanAlwaysLoadJARs() throws Exception {
    ApiTokenTestHelper.enableLegacyBehavior();
    r.jenkins.setNodes(Collections.singletonList(createNewJnlpSlave("test")));
    JenkinsRule.WebClient wc = r.createWebClient();
    HtmlPage p = wc.withBasicApiToken(User.getById("alice", true)).goTo("computer/test/");
    // this fresh WebClient doesn't have a login cookie and represent JNLP launcher
    JenkinsRule.WebClient jnlpAgent = r.createWebClient();
    // parse the JNLP page into DOM to list up the jars.
    XmlPage jnlp = (XmlPage) wc.goTo("computer/test/jenkins-agent.jnlp", "application/x-java-jnlp-file");
    URL baseUrl = jnlp.getUrl();
    Document dom = new DOMReader().read(jnlp.getXmlDocument());
    for (Object jar : dom.selectNodes("//jar")) {
        URL url = new URL(baseUrl, ((Element) jar).attributeValue("href"));
        System.out.println(url);
        // now make sure that these URLs are unprotected
        Page jarResource = jnlpAgent.getPage(url);
        assertTrue(jarResource.getWebResponse().getContentType().toLowerCase(Locale.ENGLISH).startsWith("application/"));
    }
}
Also used : DOMReader(org.dom4j.io.DOMReader) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Document(org.dom4j.Document) URL(java.net.URL) Email(org.jvnet.hudson.test.Email) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

Example 7 with Email

use of org.jvnet.hudson.test.Email in project jenkins by jenkinsci.

the class DirectoryBrowserSupportTest method doubleDots2.

/**
 * <del>Also makes sure '\\' in the file name for Unix is handled correctly</del>.
 *
 * To prevent directory traversal attack, we now treat '\\' just like '/'.
 */
@Email("http://www.nabble.com/Status-Code-400-viewing-or-downloading-artifact-whose-filename-contains-two-consecutive-periods-tt21407604.html")
@Test
public void doubleDots2() throws Exception {
    Assume.assumeFalse("can't test this on Windows", Functions.isWindows());
    // create a problematic file name in the workspace
    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new Shell("mkdir abc; touch abc/def.bin"));
    j.buildAndAssertSuccess(p);
    // can we see it?
    j.createWebClient().goTo("job/" + p.getName() + "/ws/abc%5Cdef.bin", "application/octet-stream");
}
Also used : Shell(hudson.tasks.Shell) Email(org.jvnet.hudson.test.Email) Test(org.junit.Test)

Example 8 with Email

use of org.jvnet.hudson.test.Email in project jenkins by jenkinsci.

the class ArgumentListBuilder2Test method slaveMask.

/**
 * Makes sure {@link RemoteLauncher} properly masks arguments.
 */
@Test
@Email("http://n4.nabble.com/Password-masking-when-running-commands-on-a-slave-tp1753033p1753033.html")
public void slaveMask() throws Exception {
    ArgumentListBuilder args = new ArgumentListBuilder();
    args.add("java");
    args.addMasked("-version");
    Slave s = j.createOnlineSlave();
    j.showAgentLogs(s, logging);
    StringWriter out = new StringWriter();
    assertEquals(0, s.createLauncher(new StreamTaskListener(out)).launch().cmds(args).join());
    assertThat(out.toString(), containsString("$ java ********"));
}
Also used : Slave(hudson.model.Slave) StringWriter(java.io.StringWriter) Email(org.jvnet.hudson.test.Email) Test(org.junit.Test)

Example 9 with Email

use of org.jvnet.hudson.test.Email in project jenkins by jenkinsci.

the class ViewTest method conflictingName.

/**
 * Creating two views with the same name.
 */
@Email("http://d.hatena.ne.jp/ssogabe/20090101/1230744150")
@Test
public void conflictingName() throws Exception {
    assertNull(j.jenkins.getView("foo"));
    WebClient wc = j.createWebClient();
    HtmlForm form = wc.goTo("newView").getFormByName("createItem");
    form.getInputByName("name").setValueAttribute("foo");
    form.getRadioButtonsByName("mode").get(0).setChecked(true);
    j.submit(form);
    assertNotNull(j.jenkins.getView("foo"));
    wc.setThrowExceptionOnFailingStatusCode(false);
    // do it again and verify an error
    Page page = j.submit(form);
    assertEquals("shouldn't be allowed to create two views of the same name.", HttpURLConnection.HTTP_BAD_REQUEST, page.getWebResponse().getStatusCode());
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) Page(com.gargoylesoftware.htmlunit.Page) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) Email(org.jvnet.hudson.test.Email) Test(org.junit.Test)

Example 10 with Email

use of org.jvnet.hudson.test.Email in project junit-plugin by jenkinsci.

the class CaseResultTest method testRemoteApiDefaultVisibility.

@Email("http://jenkins.361315.n4.nabble.com/Change-remote-API-visibility-for-CaseResult-getStdout-getStderr-td395102.html")
@Test
public void testRemoteApiDefaultVisibility() throws Exception {
    FreeStyleBuild b = configureTestBuild("test-remoteapi");
    XmlPage page = (XmlPage) rule.createWebClient().goTo("job/test-remoteapi/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/api/xml", "application/xml");
    int found = 0;
    found = page.getByXPath(composeXPath(MAX_VISIBILITY_FIELDS)).size();
    assertTrue("Should have found an element, but found " + found, found > 0);
    found = page.getByXPath(composeXPath(REDUCED_VISIBILITY_FIELDS)).size();
    assertTrue("Should have found an element, but found " + found, found > 0);
    found = page.getByXPath(composeXPath(OTHER_FIELDS)).size();
    assertTrue("Should have found an element, but found " + found, found > 0);
}
Also used : XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) FreeStyleBuild(hudson.model.FreeStyleBuild) Email(org.jvnet.hudson.test.Email) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Email (org.jvnet.hudson.test.Email)13 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)4 FreeStyleBuild (hudson.model.FreeStyleBuild)4 SearchTest (hudson.search.SearchTest)3 SmokeTest (org.jvnet.hudson.test.SmokeTest)3 Page (com.gargoylesoftware.htmlunit.Page)2 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 MavenInstallation (hudson.tasks.Maven.MavenInstallation)2 URL (java.net.URL)2 ExtractResourceSCM (org.jvnet.hudson.test.ExtractResourceSCM)2 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 Slave (hudson.model.Slave)1 AntInstallation (hudson.tasks.Ant.AntInstallation)1 Shell (hudson.tasks.Shell)1