Search in sources :

Example 1 with PresetData

use of org.jvnet.hudson.test.recipes.PresetData in project jenkins-test-harness by jenkinsci.

the class UseRecipesWithJenkinsRuleTest method testPresetData.

@Test
@PresetData(DataSet.ANONYMOUS_READONLY)
public void testPresetData() throws Exception {
    WebClient wc = rule.createWebClient();
    wc.assertFails("loginError", SC_UNAUTHORIZED);
    // but not once the user logs in.
    verifyNotError(wc.login("alice"));
}
Also used : WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) Test(org.junit.Test) PresetData(org.jvnet.hudson.test.recipes.PresetData)

Example 2 with PresetData

use of org.jvnet.hudson.test.recipes.PresetData in project implied-labels-plugin by jenkinsci.

the class ConfigTest method notAuthorizedToConfigure.

@PresetData(DataSet.ANONYMOUS_READONLY)
@Test
public void notAuthorizedToConfigure() throws Exception {
    WebClient wc = j.createWebClient();
    wc.getOptions().setPrintContentOnFailingStatusCode(false);
    try {
        wc.goTo("label-implications");
    } catch (FailingHttpStatusCodeException ex) {
        assertThat(ex.getStatusMessage(), equalTo("Forbidden"));
    }
    try {
        wc.goTo("label-implications/configure");
    } catch (FailingHttpStatusCodeException ex) {
        assertThat(ex.getStatusMessage(), equalTo("Forbidden"));
    }
}
Also used : FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

Example 3 with PresetData

use of org.jvnet.hudson.test.recipes.PresetData in project job-config-history-plugin by jenkinsci.

the class JobConfigBadgeActionIT method testBadgeConfigurationAnonymous.

@PresetData(DataSet.ANONYMOUS_READONLY)
public void testBadgeConfigurationAnonymous() throws Exception {
    final String jobName = "newjob";
    final String description = "a description";
    final FreeStyleProject project = createFreeStyleProject(jobName);
    assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get());
    Thread.sleep(SLEEP_TIME);
    project.setDescription(description);
    Thread.sleep(SLEEP_TIME);
    assertBuildStatus(Result.SUCCESS, project.scheduleBuild2(0).get());
    jenkins.setSecurityRealm(createDummySecurityRealm());
    SecurityContextHolder.getContext().setAuthentication(Jenkins.ANONYMOUS);
    shouldPageContainBadge("anonymous");
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject) PresetData(org.jvnet.hudson.test.recipes.PresetData)

Example 4 with PresetData

use of org.jvnet.hudson.test.recipes.PresetData 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 5 with PresetData

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

the class SecurityContextExecutorServiceTest method testRunnableAgainstAllContexts.

@Test
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
public void testRunnableAgainstAllContexts() throws Exception {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            runnableThreadContext = SecurityContextHolder.getContext();
        }
    };
    SecurityContextHolder.setContext(systemContext);
    Future systemResult = wrappedService.submit(r);
    // Assert the runnable completed successfully
    assertNull(systemResult.get());
    // Assert the context inside the runnable thread was set to ACL.SYSTEM2
    assertEquals(systemContext, runnableThreadContext);
    SecurityContextHolder.setContext(userContext);
    Future userResult = wrappedService.submit(r);
    // Assert the runnable completed successfully
    assertNull(userResult.get());
    // Assert the context inside the runnable thread was set to the user's context
    assertEquals(userContext, runnableThreadContext);
    SecurityContextHolder.setContext(nullContext);
    Future nullResult = wrappedService.submit(r);
    // Assert the runnable completed successfully
    assertNull(nullResult.get());
    // Assert the context inside the runnable thread was set to the null context
    assertEquals(nullContext, runnableThreadContext);
}
Also used : Future(java.util.concurrent.Future) Test(org.junit.Test) PresetData(org.jvnet.hudson.test.recipes.PresetData)

Aggregations

PresetData (org.jvnet.hudson.test.recipes.PresetData)18 Test (org.junit.Test)17 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)10 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)2 HtmlLink (com.gargoylesoftware.htmlunit.html.HtmlLink)2 Future (java.util.concurrent.Future)2 Issue (org.jvnet.hudson.test.Issue)2 Page (com.gargoylesoftware.htmlunit.Page)1 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)1 Launcher (hudson.Launcher)1 Proc (hudson.Proc)1 FreeStyleProject (hudson.model.FreeStyleProject)1 Slave (hudson.model.Slave)1 Channel (hudson.remoting.Channel)1 GlobalMatrixAuthorizationStrategy (hudson.security.GlobalMatrixAuthorizationStrategy)1