Search in sources :

Example 11 with PresetData

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

the class LoginTest method loginErrorRedirect2.

/**
 * Same as {@link #loginErrorRedirect1()} if the user has already successfully authenticated.
 */
@Test
@PresetData(DataSet.ANONYMOUS_READONLY)
public void loginErrorRedirect2() throws Exception {
    ApiTokenTestHelper.enableLegacyBehavior();
    // in a secured Hudson, the error page should render.
    WebClient wc = j.createWebClient();
    wc.assertFails("loginError", SC_UNAUTHORIZED);
    // but not once the user logs in.
    verifyNotError(wc.withBasicApiToken(User.getById("alice", true)));
}
Also used : WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) Test(org.junit.Test) PresetData(org.jvnet.hudson.test.recipes.PresetData)

Example 12 with PresetData

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

the class AbstractProjectTest method wipeWorkspaceProtected2.

/**
 * Makes sure that the workspace deletion link is not provided when the user
 * doesn't have an access.
 */
@Test
@PresetData(DataSet.ANONYMOUS_READONLY)
public void wipeWorkspaceProtected2() throws Exception {
    ((GlobalMatrixAuthorizationStrategy) j.jenkins.getAuthorizationStrategy()).add(Item.WORKSPACE, new PermissionEntry(AuthorizationType.EITHER, "anonymous"));
    // make sure that the deletion is protected in the same way
    wipeWorkspaceProtected();
    // there shouldn't be any "wipe out workspace" link for anonymous user
    JenkinsRule.WebClient webClient = j.createWebClient();
    HtmlPage page = webClient.getPage(j.jenkins.getItem("test0"));
    HtmlPage workspace = page.getAnchorByText("Workspace").click();
    String wipeOutLabel = ResourceBundle.getBundle("hudson/model/AbstractProject/sidepanel").getString("Wipe Out Workspace");
    assertThrows("shouldn't find a link", ElementNotFoundException.class, () -> workspace.getAnchorByText(wipeOutLabel));
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) PermissionEntry(org.jenkinsci.plugins.matrixauth.PermissionEntry) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) PresetData(org.jvnet.hudson.test.recipes.PresetData)

Example 13 with PresetData

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

the class AjaxTest method rejectedLinks.

@Issue("JENKINS-21254")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test
public void rejectedLinks() throws Exception {
    JenkinsRule.WebClient wc = r.createWebClient();
    String prefix = r.contextPath + '/';
    for (DomElement e : wc.goTo("login").getElementsByTagName("link")) {
        String href = ((HtmlLink) e).getHrefAttribute();
        if (!href.startsWith(prefix)) {
            System.err.println("ignoring " + href);
            continue;
        }
        System.err.println("checking " + href);
        wc.goTo(href.substring(prefix.length()), null);
    }
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlLink(com.gargoylesoftware.htmlunit.html.HtmlLink) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Issue(org.jvnet.hudson.test.Issue) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

Example 14 with PresetData

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

the class JnlpAccessWithSecuredHudsonTest method serviceUsingDirectSecret.

@PresetData(DataSet.NO_ANONYMOUS_READACCESS)
@SuppressWarnings("SleepWhileInLoop")
@Test
public void serviceUsingDirectSecret() throws Exception {
    Slave slave = createNewJnlpSlave("test");
    r.jenkins.setNodes(Collections.singletonList(slave));
    r.createWebClient().goTo("computer/test/jenkins-agent.jnlp?encrypt=true", "application/octet-stream");
    String secret = slave.getComputer().getJnlpMac();
    // To watch it fail: secret = secret.replace('1', '2');
    File slaveJar = tmp.newFile();
    FileUtils.copyURLToFile(new Slave.JnlpJar("agent.jar").getURL(), slaveJar);
    Proc p = new Launcher.LocalLauncher(StreamTaskListener.fromStderr()).launch().stdout(System.out).stderr(System.err).cmds(JavaEnvUtils.getJreExecutable("java"), "-jar", slaveJar.getAbsolutePath(), "-jnlpUrl", r.getURL() + "computer/test/jenkins-agent.jnlp", "-secret", secret).start();
    try {
        r.waitOnline(slave);
        Channel channel = slave.getComputer().getChannel();
        assertFalse("SECURITY-206", channel.isRemoteClassLoadingAllowed());
        r.jenkins.getExtensionList(AdminWhitelistRule.class).get(AdminWhitelistRule.class).setMasterKillSwitch(false);
        final File f = new File(r.jenkins.getRootDir(), "config.xml");
        assertTrue(f.exists());
    } finally {
        p.kill();
    }
}
Also used : Proc(hudson.Proc) AdminWhitelistRule(jenkins.security.s2m.AdminWhitelistRule) DumbSlave(hudson.slaves.DumbSlave) Slave(hudson.model.Slave) Channel(hudson.remoting.Channel) Launcher(hudson.Launcher) JNLPLauncher(hudson.slaves.JNLPLauncher) File(java.io.File) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

Example 15 with PresetData

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

the class LoginRedirectTest method redirect1.

/*
     * First sends HTTP 403, then redirects to the login page.
     */
@PresetData(DataSet.NO_ANONYMOUS_READACCESS)
@Test
public void redirect1() throws Exception {
    WebClient wc = j.createWebClient();
    wc.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage loginPage = wc.goTo("");
    assertEquals(HttpURLConnection.HTTP_OK, loginPage.getWebResponse().getStatusCode());
    assertEquals(j.contextPath + "/login", loginPage.getUrl().getPath());
    HtmlForm form = loginPage.getFormByName("login");
    form.getInputByName("j_username").setValueAttribute("alice");
    form.getInputByName("j_password").setValueAttribute("alice");
    HtmlPage mainPage = j.submit(form);
    assertEquals(j.contextPath + "/", mainPage.getUrl().getPath());
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

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