use of org.jvnet.hudson.test.JenkinsRule.WebClient in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionPermissionsViaWebClient.
@Test
// TODO figure out a good way to test this with SECURITY-2293
@Ignore
public void testManualPromotionPermissionsViaWebClient() throws Exception {
enableSecurity(j);
FreeStyleProject p = j.createFreeStyleProject();
PromotionProcess pp = addPromotionProcess(p, "foo");
WebClient wc = j.createWebClient();
FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
ManualCondition cond = new ManualCondition();
pp.conditions.add(cond);
j.assertBuildStatusSuccess(cond.approve(b, pp, Collections.EMPTY_LIST));
assertThat(b.getAction(ManualApproval.class), notNullValue());
{
// Re-execute promotion as user without Promotion/Promote when no users are specified
wc.login("non-promoter", "non-promoter");
// Status#doBuild does a bare `return;` without scheduling the build in this case, which is why we use goTo with "" for the MIME type.
wc.goTo(String.format("job/%s/%d/promotion/%s/build?json={}", p.getName(), b.getNumber(), pp.getName()), "");
assertThat(pp.getBuildByNumber(2), nullValue());
}
{
// Re-execute promotion as user with Promotion/Promote when no users are specified
wc.login("promoter", "promoter");
try {
wc.getPage(b, String.format("promotion/%s/build?json={}", pp.getName()));
fail();
} catch (FailingHttpStatusCodeException e) {
// Redirect after the build is broken.
assertThat(e.getStatusCode(), equalTo(404));
}
assertThat(waitForBuildByNumber(pp, 2).getResult(), equalTo(Result.SUCCESS));
}
{
// Re-execute promotion as specified user without Promotion/Promote
cond.setUsers("non-promoter");
wc.login("non-promoter", "non-promoter");
try {
wc.getPage(b, String.format("promotion/%s/build?json={}", pp.getName()));
fail();
} catch (FailingHttpStatusCodeException e) {
// Redirect after the build is broken.
assertThat(e.getStatusCode(), equalTo(404));
}
assertThat(waitForBuildByNumber(pp, 3).getResult(), equalTo(Result.SUCCESS));
}
{
// Re-execute promotion as unspecified user with Promotion/Promote
cond.setUsers("non-promoter");
wc.login("promoter", "promoter");
// Status#doBuild does a bare `return;` without scheduling the build in this case, which is why we use goTo with "" for the MIME type.
wc.goTo(String.format("job/%s/%d/promotion/%s/build?json={}", p.getName(), b.getNumber(), pp.getName()), "");
assertThat(pp.getBuildByNumber(4), nullValue());
}
}
use of org.jvnet.hudson.test.JenkinsRule.WebClient in project support-core-plugin by jenkinsci.
the class SupportActionTest method doBundle.
private WebResponse doBundle(String action, String bundle, String user, String extraBundle) throws IOException {
j.jenkins.setCrumbIssuer(null);
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to("admin").grant(Jenkins.READ).everywhere().to("user"));
WebClient wc = j.createWebClient().withBasicCredentials(user).withThrowExceptionOnFailingStatusCode(false);
String json = "?json={%22bundles%22:[{%22selected%22:+true,%22name%22:+%22" + bundle + "%22}]}";
if (extraBundle != null) {
json = "?json={%22bundles%22:[{%22selected%22:+true,%22name%22:+%22" + bundle + "%22},{%22selected%22:+true,%22name%22:+%22" + extraBundle + "%22}]}";
}
WebRequest request = new WebRequest(new URL(j.getURL() + root.getUrlName() + "/" + action + json), HttpMethod.POST);
return wc.getPage(request).getWebResponse();
}
use of org.jvnet.hudson.test.JenkinsRule.WebClient in project support-core-plugin by jenkinsci.
the class SupportActionTest method takeSnapshotAndMakeSureSomethingHappens.
/*
* Integration test that simulates the user action of clicking the button to generate the bundle.
* <p>
* If any warning is reported to j.u.l logger, treat that as a sign of failure, because
* support-core plugin works darn hard to try to generate something in the presence of failing
* {@link Component} impls.
*/
@Test
public void takeSnapshotAndMakeSureSomethingHappens() throws Exception {
j.createSlave("agent1", "test", null).getComputer().connect(false).get();
j.createSlave("agent2", "test", null).getComputer().connect(false).get();
RingBufferLogHandler checker = new RingBufferLogHandler();
Logger logger = Logger.getLogger(SupportPlugin.class.getPackage().getName());
logger.addHandler(checker);
try {
WebClient wc = j.createWebClient();
HtmlPage p = wc.goTo(root.getUrlName());
HtmlForm form = p.getFormByName("bundle-contents");
HtmlButton submit = (HtmlButton) form.getElementsByTagName("button").get(0);
Page zip = submit.click();
File zipFile = File.createTempFile("test", "zip");
IOUtils.copy(zip.getWebResponse().getContentAsStream(), Files.newOutputStream(zipFile.toPath()));
ZipFile z = new ZipFile(zipFile);
// check the presence of files
// TODO: emit some log entries and see if it gets captured here
assertNotNull(z.getEntry("about.md"));
assertNotNull(z.getEntry("nodes.md"));
assertNotNull(z.getEntry("nodes/master/thread-dump.txt"));
if (SystemPlatform.LINUX == SystemPlatform.current()) {
List<String> files = Arrays.asList("proc/swaps.txt", "proc/cpuinfo.txt", "proc/mounts.txt", "proc/system-uptime.txt", "proc/net/rpc/nfs.txt", "proc/net/rpc/nfsd.txt", "proc/meminfo.txt", "proc/self/status.txt", "proc/self/cmdline", "proc/self/environ", "proc/self/limits.txt", "proc/self/mountstats.txt", "sysctl.txt", "dmesg.txt", "userid.txt", "dmi.txt");
for (String file : files) {
assertNotNull(file + " was not found in the bundle", z.getEntry("nodes/master/" + file));
}
}
} finally {
logger.removeHandler(checker);
for (LogRecord r : checker.getView()) {
if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
Throwable thrown = r.getThrown();
if (thrown != null)
thrown.printStackTrace(System.err);
fail(r.getMessage());
}
}
}
}
Aggregations