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)));
}
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));
}
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);
}
}
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();
}
}
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());
}
Aggregations