Skip to content

Commit

Permalink
Merge pull request #122 from Vlatombe/JENKINS-48436
Browse files Browse the repository at this point in the history
[JENKINS-48436] Restore backward compatibility on web endpoints
  • Loading branch information
jglick committed Dec 12, 2017
2 parents d0402c2 + 7696741 commit 5a60b46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/cloudbees/jenkins/support/SupportAction.java
Expand Up @@ -161,6 +161,18 @@ public void doDeleteBundles(StaplerRequest req, StaplerResponse rsp) throws Serv
rsp.sendRedirect("");
}

/**
* Generates a support bundle.
* @param req The stapler request
* @param rsp The stapler response
* @throws ServletException
* @throws IOException
*/
@RequirePOST
public void doDownload(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
doGenerateAllBundles(req, rsp);
}

@RequirePOST
public void doGenerateAllBundles(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
final Jenkins instance = Helper.getActiveInstance();
Expand Down
26 changes: 24 additions & 2 deletions src/test/java/com/cloudbees/jenkins/support/SupportActionTest.java
@@ -1,5 +1,8 @@
package com.cloudbees.jenkins.support;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import com.cloudbees.jenkins.support.api.Component;
import com.cloudbees.jenkins.support.util.SystemPlatform;
import com.gargoylesoftware.htmlunit.Page;
Expand All @@ -8,15 +11,16 @@
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.util.IOUtils;
import hudson.util.RingBufferLogHandler;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.xml.sax.SAXException;

import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -27,7 +31,7 @@
/**
* @author Kohsuke Kawaguchi
*/
public class SupportActionTest extends Assert {
public class SupportActionTest {
@Rule
public JenkinsRule rule = new JenkinsRule();

Expand All @@ -39,6 +43,24 @@ public void setUp() {
rule.jenkins.getInjector().injectMembers(this);
}

@Test
public void download() throws IOException, SAXException {
downloadBundle("/download?json={\"components\":1}");
}

@Test
public void generateAllBundles() throws IOException, SAXException {
downloadBundle("/generateAllBundles?json={\"components\":1}");
}

private void downloadBundle(String s) throws IOException, SAXException {
JenkinsRule.JSONWebResponse jsonWebResponse = rule.postJSON(root.getUrlName() + s, "");
File zipFile = File.createTempFile("test", "zip");
IOUtils.copy(jsonWebResponse.getContentAsStream(), zipFile);
ZipFile z = new ZipFile(zipFile);
// Zip file is valid
}

/**
* Integration test that simulates the user action of clicking the button to generate the bundle.
*
Expand Down

0 comments on commit 5a60b46

Please sign in to comment.