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

[EDGORDERS-83-IT]. Add tls integration test, add test scope BC deps, … #102

Merged
merged 12 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bc-fips.version>1.0.2.5</bc-fips.version>
<bcpkix-fips.version>1.0.7</bcpkix-fips.version>
<bctls-fips.version>1.0.19</bctls-fips.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -89,6 +92,25 @@
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<!-- Library provides the basic cryptographic functionality complying with FIPS for testing -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bc-fips</artifactId>
<version>${bc-fips.version}</version>
<scope>test</scope>
</dependency>
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-fips</artifactId>
<version>${bcpkix-fips.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bctls-fips</artifactId>
<version>${bctls-fips.version}</version>
<scope>test</scope>
</dependency>

<!-- provided dependencies needed for MockOkapi and TestUtils -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.folio.edge.core;

import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.KeyStoreOptions;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
import org.folio.edge.core.utils.SslConfigurationUtil;
import org.folio.edge.core.utils.test.TestUtils;
import org.junit.*;
import org.junit.runner.RunWith;
azizbekxm marked this conversation as resolved.
Show resolved Hide resolved

import java.security.Security;

@RunWith(VertxUnitRunner.class)
public class EdgeVerticleTlsIntegrationTest {

private static final Logger logger = LogManager.getLogger(EdgeVerticleTlsIntegrationTest.class);
static Vertx vertx;

static final String KEYSTORE_TYPE = "BCFKS";
static final String KEYSTORE_PATH = "test.keystore 1.bcfks";
static final String TRUST_STORE_PATH = "test.truststore 1.bcfks";
static final String KEYSTORE_PASSWORD = "SecretPassword";
static final String RESPONSE_MESSAGE = "<OK>";

@BeforeClass
public static void setUpOnce(TestContext context) {
Security.addProvider(new BouncyCastleFipsProvider());
vertx = Vertx.vertx();
}

@AfterClass
public static void tearDownOnce(TestContext context) {
vertx.close(context.asyncAssertSuccess());
}

@Test
public void testServerClientTlsCommunication(TestContext context) {
final JsonObject config = getCommonConfig();

final HttpServerOptions serverOptions = new HttpServerOptions();
serverOptions.setPort(config.getInteger(Constants.SYS_PORT));

SslConfigurationUtil.configureSslServerOptionsIfEnabled(config, serverOptions);

final HttpServer httpServer = vertx.createHttpServer(serverOptions);
httpServer
.requestHandler(req -> req.response().putHeader("content-type", "text/plain").end(RESPONSE_MESSAGE))
.listen(config.getInteger(Constants.SYS_PORT), http -> logger.info("Server started on port {}", config.getInteger(Constants.SYS_PORT)));

final WebClientOptions clientOptions = new WebClientOptions();
SerhiiNosko marked this conversation as resolved.
Show resolved Hide resolved
clientOptions
.setSsl(config.getBoolean(Constants.SYS_WEB_CLIENT_SSL_ENABLED))
.setVerifyHost(true)
.setTrustOptions(new KeyStoreOptions()
.setType(config.getString(Constants.SYS_WEB_CLIENT_TRUSTSTORE_TYPE))
.setPath(config.getString(Constants.SYS_WEB_CLIENT_TRUSTSTORE_PATH))
.setPassword(config.getString(Constants.SYS_WEB_CLIENT_TRUSTSTORE_PASSWORD)));
final WebClient webClient = WebClient.create(vertx, clientOptions);

webClient.get(config.getInteger(Constants.SYS_PORT), "localhost", "/")
.send()
.onComplete(context.asyncAssertSuccess(response -> {
String message = response.body().toString();
logger.info("WebClient sent message to server port {}, response message: {}", config.getInteger(Constants.SYS_PORT), message);
context.assertEquals(HttpResponseStatus.OK.code(), response.statusCode());
context.assertEquals(RESPONSE_MESSAGE, message);
}));
}

private JsonObject getCommonConfig() {
int serverPort = TestUtils.getPort();
return new JsonObject().put(Constants.SYS_PORT, serverPort)
.put(Constants.SYS_HTTP_SERVER_SSL_ENABLED, true)
.put(Constants.SYS_HTTP_SERVER_KEYSTORE_TYPE, KEYSTORE_TYPE)
.put(Constants.SYS_HTTP_SERVER_KEYSTORE_PATH, KEYSTORE_PATH)
.put(Constants.SYS_HTTP_SERVER_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD)
.put(Constants.SYS_WEB_CLIENT_SSL_ENABLED, true)
.put(Constants.SYS_WEB_CLIENT_TRUSTSTORE_TYPE, KEYSTORE_TYPE)
.put(Constants.SYS_WEB_CLIENT_TRUSTSTORE_PATH, TRUST_STORE_PATH)
.put(Constants.SYS_WEB_CLIENT_TRUSTSTORE_PASSWORD, KEYSTORE_PASSWORD);
}
}
Binary file added src/test/resources/test.keystore 1.bcfks
Binary file not shown.
Binary file added src/test/resources/test.truststore 1.bcfks
Binary file not shown.