use of org.jvnet.hudson.test.recipes.PresetData in project jenkins by jenkinsci.
the class SecurityContextExecutorServiceTest method testCallableCollectionAgainstAllContexts.
@Test
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
public void testCallableCollectionAgainstAllContexts() throws Exception {
Collection<Callable<SecurityContext>> callables = new ArrayList<>();
Callable<SecurityContext> c = new Callable<SecurityContext>() {
@Override
public SecurityContext call() {
return SecurityContextHolder.getContext();
}
};
callables.add(c);
callables.add(c);
callables.add(c);
SecurityContextHolder.setContext(systemContext);
Collection<Future<SecurityContext>> results = wrappedService.invokeAll(callables);
for (Future<SecurityContext> result : results) {
// Assert each thread context was identical to the initial service context
SecurityContext value = result.get();
assertEquals(systemContext, value);
}
SecurityContextHolder.setContext(userContext);
results = wrappedService.invokeAll(callables);
for (Future<SecurityContext> result : results) {
// Assert each thread context was identical to the initial service context
assertEquals(userContext, result.get());
}
SecurityContextHolder.setContext(nullContext);
results = wrappedService.invokeAll(callables);
for (Future<SecurityContext> result : results) {
// Assert each thread context was identical to the initial service context
assertEquals(nullContext, result.get());
}
}
use of org.jvnet.hudson.test.recipes.PresetData in project jenkins by jenkinsci.
the class LayoutTest 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 DefaultCrumbIssuerTest method apiJson.
@PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
@Test
public void apiJson() throws Exception {
WebClient wc = r.createWebClient();
String json = wc.goTo("crumbIssuer/api/json", "application/json").getWebResponse().getContentAsString();
JSONObject jsonObject = JSONObject.fromObject(json);
assertEquals(r.jenkins.getCrumbIssuer().getCrumbRequestField(), jsonObject.getString("crumbRequestField"));
assertTrue(jsonObject.getString("crumb").matches("[0-9a-f]+"));
wc.assertFails("crumbIssuer/api/json?jsonp=hack", HttpURLConnection.HTTP_FORBIDDEN);
}
use of org.jvnet.hudson.test.recipes.PresetData in project jenkins by jenkinsci.
the class DefaultCrumbIssuerTest method apiXml.
@PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
@Test
public void apiXml() throws Exception {
WebClient wc = r.createWebClient();
r.assertXPathValue(wc.goToXml("crumbIssuer/api/xml"), "//crumbRequestField", r.jenkins.getCrumbIssuer().getCrumbRequestField());
String text = wc.goTo("crumbIssuer/api/xml?xpath=concat(//crumbRequestField,'=',//crumb)", "text/plain").getWebResponse().getContentAsString();
assertTrue(text, text.matches("\\Q" + r.jenkins.getCrumbIssuer().getCrumbRequestField() + "\\E=[0-9a-f]+"));
text = wc.goTo("crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)", "text/plain").getWebResponse().getContentAsString();
assertTrue(text, text.matches("\\Q" + r.jenkins.getCrumbIssuer().getCrumbRequestField() + "\\E:[0-9a-f]+"));
text = wc.goTo("crumbIssuer/api/xml?xpath=/*/crumbRequestField/text()", "text/plain").getWebResponse().getContentAsString();
assertEquals(r.jenkins.getCrumbIssuer().getCrumbRequestField(), text);
text = wc.goTo("crumbIssuer/api/xml?xpath=/*/crumb/text()", "text/plain").getWebResponse().getContentAsString();
assertTrue(text, text.matches("[0-9a-f]+"));
wc.assertFails("crumbIssuer/api/xml?xpath=concat('hack=\"',//crumb,'\"')", HttpURLConnection.HTTP_FORBIDDEN);
wc.assertFails("crumbIssuer/api/xml?xpath=concat(\"hack='\",//crumb,\"'\")", HttpURLConnection.HTTP_FORBIDDEN);
// 37.5% chance that crumb ~ /[a-f].+/
wc.assertFails("crumbIssuer/api/xml?xpath=concat('{',//crumb,':1}')", HttpURLConnection.HTTP_FORBIDDEN);
// ditto
wc.assertFails("crumbIssuer/api/xml?xpath=concat('hack.',//crumb,'=1')", HttpURLConnection.HTTP_FORBIDDEN);
r.jenkins.getCrumbIssuer().getDescriptor().setCrumbRequestField("_crumb");
// perhaps interpretable as JS number
wc.assertFails("crumbIssuer/api/xml?xpath=concat(//crumbRequestField,'=',//crumb)", HttpURLConnection.HTTP_FORBIDDEN);
}
use of org.jvnet.hudson.test.recipes.PresetData in project jenkins by jenkinsci.
the class LoginTest method loginRememberMe.
/**
* Test 'remember me' cookie
*/
@Test
@PresetData(DataSet.SECURED_ACEGI)
public void loginRememberMe() throws Exception {
WebClient wc = j.createWebClient();
HtmlFormUtil.submit(prepareLoginFormWithRememberMeChecked(wc), null);
assertNotNull(getRememberMeCookie(wc));
}
Aggregations