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