Skip to content
Permalink
Browse files
[JENKINS-32376] Changed the target to the least LTS 1.596.
  • Loading branch information
ikedam committed Jan 16, 2016
1 parent 8b2f3b0 commit d5d4f7ebd550bd015a35e224edcfea21f81417f0
15 pom.xml
@@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.609.3</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.596</version><!-- which version of Jenkins is this plugin built against? -->
</parent>

<groupId>jp.ikedam.jenkins.plugins</groupId>
@@ -55,17 +55,4 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
@@ -34,11 +34,18 @@ public ExtendedCertJsonSignValidator(String id, String cert) {
@Override
protected Set<TrustAnchor> loadTrustAnchors(CertificateFactory cf) throws IOException {
Set<TrustAnchor> trustAnchors = super.loadTrustAnchors(cf);
try (InputStream stream = new StringInputStream(cert)) {
InputStream stream = null;
try {
stream = new StringInputStream(cert);
Certificate certificate = cf.generateCertificate(stream);
trustAnchors.add(new TrustAnchor((X509Certificate) certificate, null));
} catch (CertificateException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
} finally {
if (stream != null) {
stream.close();
stream = null;
}
}
return trustAnchors;
}
@@ -172,6 +172,7 @@ public void testDoConfigure() throws Exception
// duplicate id
{
WebClient wc = new WebClient();
wc.setPrintContentOnFailingStatusCode(false);

HtmlPage editSitePage = wc.goTo(String.format("%s/%s", UpdateSitesManager.URL, target.getPageUrl()));

@@ -193,6 +194,7 @@ public void testDoConfigure() throws Exception
// cannot configure for editable
{
WebClient wc = new WebClient();
wc.setPrintContentOnFailingStatusCode(false);

HtmlPage editSitePage = wc.goTo(String.format("%s/%s", UpdateSitesManager.URL, target.getPageUrl()));

@@ -215,6 +217,7 @@ public void testDoConfigure() throws Exception
editSiteForm = editSitePage.getFormByName("editSiteForm");

assertEquals("no button must exists", 0, editSiteForm.getHtmlElementsByTagName("button").size());
assertEquals("no button must exists", 0, editSiteForm.getSubmitButtons().size());

target.setEditable(true);
}
@@ -311,6 +314,7 @@ public void testDoDelete() throws Exception
int initialSize = Jenkins.getInstance().getUpdateCenter().getSites().size();

WebClient wc = new WebClient();
wc.setPrintContentOnFailingStatusCode(false);

HtmlPage deleteSitePage = wc.goTo(String.format("%s/%s/delete", UpdateSitesManager.URL, target.getPageUrl()));
assertEquals("UpdateSite must not be deleted yet.", initialSize, Jenkins.getInstance().getUpdateCenter().getSites().size());
@@ -358,6 +362,7 @@ public void testPrivilege() throws Exception
wcAdmin.login("admin", "admin");

WebClient wcUser = new WebClient();
wcUser.setPrintContentOnFailingStatusCode(false);
wcUser.login("user", "user");

// configure
@@ -23,6 +23,7 @@
*/
package jp.ikedam.jenkins.plugins.updatesitesmanager;

import hudson.security.csrf.CrumbIssuer;
import hudson.util.FormValidation;

import java.io.File;
@@ -32,12 +33,16 @@
import java.net.URL;
import java.security.GeneralSecurityException;

import jenkins.model.Jenkins;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.jvnet.hudson.test.HudsonTestCase;
import org.kohsuke.stapler.StaplerRequest;

import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequestSettings;

/**
* Tests for ManagedUpdateSite, concerned with Jenkins.
*/
@@ -94,6 +99,78 @@ private File getResource(String name) throws URISyntaxException, FileNotFoundExc
return new File(url.toURI());
}

public void testDoPostBack() throws URISyntaxException, IOException, GeneralSecurityException
{
// CrumbIssuer causes failures in POST request.
// I don't know why CrumbIssuer is enabled in a test environment...
CrumbIssuer crumb = Jenkins.getInstance().getCrumbIssuer();
try
{
Jenkins.getInstance().setCrumbIssuer(null);
String caCertificate = FileUtils.readFileToString(getResource("caCertificate.crt"));

TestManagedUpdateSite target = new TestManagedUpdateSite(
"test",
"http://localhost/update-center.json",
false,
null,
"test",
false
);
Jenkins.getInstance().getUpdateCenter().getSites().clear();
Jenkins.getInstance().getUpdateCenter().getSites().add(target);
Jenkins.getInstance().getUpdateCenter().save();

WebClient wc = new WebClient();
WebRequestSettings wrs = new WebRequestSettings(
new URL(String.format("%s%s/byId/%s/postBack",
wc.getContextPath(),
Jenkins.getInstance().getUpdateCenter().getSearchUrl(),
target.getId()
)),
HttpMethod.POST
);
wrs.setAdditionalHeader("Content-Type", "application/json; charset=UTF-8");
wrs.setRequestBody(FileUtils.readFileToString(getResource("update-center.json"), "UTF-8"));

{
target.setDoPostBackResult(null);
wc.getPage(wrs);
assertEquals(
"Accessing update center with no certificate must fail",
FormValidation.Kind.ERROR,
target.getDoPostBackResult().kind
);
}

{
target.setCaCertificate(caCertificate);
target.setDoPostBackResult(null);
wc.getPage(wrs);
assertEquals(
"Accessing update center with a proper certificate must succeed",
FormValidation.Kind.OK,
target.getDoPostBackResult().kind
);
}

{
target.setCaCertificate(null);
target.setDoPostBackResult(null);
wc.getPage(wrs);
assertEquals(
"Accessing update center with no certificate must fail",
FormValidation.Kind.ERROR,
target.getDoPostBackResult().kind
);
}
}
finally
{
Jenkins.getInstance().setCrumbIssuer(crumb);
}
}

private ManagedUpdateSite.DescriptorImpl getDescriptor()
{
return (ManagedUpdateSite.DescriptorImpl)new ManagedUpdateSite(null, null, false, null, null, false).getDescriptor();
@@ -435,6 +435,7 @@ public void testDo_addError() throws Exception
assertTrue("This test must run with more than one UpdateSite Descriptors registered.", 1 < target.getUpdateSiteDescriptorList().size());

WebClient wc = new WebClient();
wc.setPrintContentOnFailingStatusCode(false);

// Post without id.
{
@@ -616,6 +617,7 @@ public void testPrivilege() throws Exception
wcAdmin.login("admin", "admin");

WebClient wcUser = new WebClient();
wcUser.setPrintContentOnFailingStatusCode(false);
wcUser.login("user", "user");

wcAdmin.goTo(UpdateSitesManager.URL);
@@ -1,29 +1,38 @@
package jp.ikedam.jenkins.plugins.updatesitesmanager.internal;

import net.sf.json.JSONObject;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.security.cert.CertificateFactory;
import java.security.cert.TrustAnchor;
import java.util.Set;
import hudson.util.FormValidation;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import jenkins.util.JSONSignatureValidator;
import static org.junit.Assert.*;

/**
* @author lanwen (Merkushev Kirill)
*/
public class ExtendedCertJsonSignValidatorTest {

@ClassRule
public static JenkinsRule j = new JenkinsRule();

@Test
public void shouldAddCustomCertToTrustAnchors() throws Exception {
String RESOURCE_BASE = "jp/ikedam/jenkins/plugins/updatesitesmanager/ManagedUpdateSiteJenkinsTest";

String cert = IOUtils.toString(getClass().getClassLoader()
.getResourceAsStream("jp/ikedam/jenkins/plugins/updatesitesmanager/" +
"ManagedUpdateSiteJenkinsTest/caCertificate.crt"), Charsets.UTF_8);
CertificateFactory cf = CertificateFactory.getInstance("X509");

Set<TrustAnchor> test = new ExtendedCertJsonSignValidator("test", cert).loadTrustAnchors(cf);
assertThat(test, hasSize(1));
.getResourceAsStream(RESOURCE_BASE + "/caCertificate.crt"), Charsets.UTF_8);
JSONSignatureValidator validator = new ExtendedCertJsonSignValidator("test", cert);
//JSONSignatureValidator validator = new JSONSignatureValidator("test");
JSONObject ucToTest = JSONObject.fromObject(IOUtils.toString(
getClass().getClassLoader().getResourceAsStream(RESOURCE_BASE + "/update-center.json"),
Charsets.UTF_8
));
assertEquals(FormValidation.Kind.OK, validator.verifySignature(ucToTest).kind);
}
}
}

0 comments on commit d5d4f7e

Please sign in to comment.