Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cert revocation improvement integration tests #2155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
import org.apache.synapse.samples.framework.tests.tasks.Sample300;
import org.apache.synapse.samples.framework.tests.template.Sample750;
import org.apache.synapse.samples.framework.tests.template.Sample751;
import org.apache.synapse.samples.framework.tests.transport.Sample10102;
import org.apache.synapse.samples.framework.tests.transport.Sample10103;
import org.apache.synapse.samples.framework.tests.transport.Sample250;
import org.apache.synapse.samples.framework.tests.transport.Sample251;
import org.apache.synapse.samples.framework.tests.transport.Sample268;
Expand Down Expand Up @@ -322,5 +324,7 @@ private static void populateTemplateSamples() {

private static void populateTransportSamples() {
sampleClassRepo.put("268", Sample268.class);
sampleClassRepo.put("10102", Sample10102.class);
sampleClassRepo.put("10103", Sample10103.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.ssl.SSLContexts;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.util.Map;

/**
Expand Down Expand Up @@ -112,4 +120,34 @@ public HttpResponse doPost(String url, byte[] payload,
}
}

public HttpResponse doPostWithCert(String url, byte[] payload,
String contentType, String keyStorePath,
String trustStorePath, String keyStorePass, String trustStorePass)
throws Exception {

KeyStore testKeyStore = KeyStore.getInstance("JKS");
testKeyStore.load(Files.newInputStream(Paths.get(keyStorePath)), keyStorePass.toCharArray());

KeyStore testTrustStore = KeyStore.getInstance("JKS");
testTrustStore.load(Files.newInputStream(Paths.get(trustStorePath)), trustStorePass.toCharArray());

SSLContext sslContext = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(testKeyStore, keyStorePass.toCharArray());

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
trustManagerFactory.init(testTrustStore);

sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

try (CloseableHttpClient client = HttpClientBuilder.create().setSSLContext(sslContext).build()) {
HttpPost post = new HttpPost(url);
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContentType(contentType);
entity.setContent(new ByteArrayInputStream(payload));
post.setEntity(entity);
return new HttpResponse(client.execute(post));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.synapse.samples.framework.tests.transport;

import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpStatus;
import org.apache.synapse.samples.framework.SynapseTestCase;
import org.apache.synapse.samples.framework.clients.BasicHttpClient;
import org.apache.synapse.samples.framework.clients.HttpResponse;

public class Sample10102 extends SynapseTestCase {

public static final byte[] TEST_PAYLOAD = "<test>foo</test>".getBytes();

public Sample10102() {
super(10102);
}

public void testSingleClientCertForRevocation() throws Exception {

BasicHttpClient client = new BasicHttpClient();
HttpResponse response = client.doPostWithCert("https://localhost:8253/test/order",
TEST_PAYLOAD, "application/xml",
FilenameUtils.normalize(System.getProperty("user.dir")
+ "/modules/integration/src/test/resources/transport.jks"),
FilenameUtils.normalize(System.getProperty("user.dir") +
"/modules/integration/src/test/resources/trust.jks"), "wso2carbon",
"password");
assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.synapse.samples.framework.tests.transport;

import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpStatus;
import org.apache.synapse.samples.framework.SynapseTestCase;
import org.apache.synapse.samples.framework.clients.BasicHttpClient;
import org.apache.synapse.samples.framework.clients.HttpResponse;

public class Sample10103 extends SynapseTestCase {

public static final byte[] TEST_PAYLOAD = "<test>foo</test>".getBytes();

public Sample10103() {
super(10103);
}

public void testSingleClientCertForRevocationWithExpiryCheck() throws Exception {

BasicHttpClient client = new BasicHttpClient();
HttpResponse response = client.doPostWithCert("https://localhost:8253/test/order",
TEST_PAYLOAD, "application/xml",
FilenameUtils.normalize(System.getProperty("user.dir")
+ "/modules/integration/src/test/resources/transport.jks"),
FilenameUtils.normalize(System.getProperty("user.dir")
+ "/modules/integration/src/test/resources/trust.jks"), "wso2carbon",
"password");
assertEquals(HttpStatus.SC_ACCEPTED, response.getStatus());
}
}
Loading
Loading