Skip to content

Commit

Permalink
Merge pull request #2155 from Akila94/cert-revocation-synapse-improve…
Browse files Browse the repository at this point in the history
…ment-tests

Cert revocation improvement integration tests
  • Loading branch information
tharikaGitHub authored Mar 2, 2024
2 parents eaa611b + 03879b1 commit 3726f01
Show file tree
Hide file tree
Showing 12 changed files with 1,072 additions and 0 deletions.
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

0 comments on commit 3726f01

Please sign in to comment.