Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into cleanup
  • Loading branch information
hyperxpro committed Aug 28, 2023
2 parents 70c9014 + 3990870 commit 6afa14b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.shieldblaze.expressgateway.common.ExpressGateway;
import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.TestingServer;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,29 +59,11 @@ void connectToZooKeeperUsingTLSTest() throws Exception {
File file = new File(classLoader.getResource("default").getFile());
String absolutePath = file.getAbsolutePath();

int randomUsablePort = InstanceSpec.getRandomPort();

Map<String, Object> customProperties = new HashMap<>();
customProperties.put("secureClientPort", String.valueOf(randomUsablePort));
customProperties.put("ssl.keyStore.location", absolutePath + File.separator + "KeyStore.jks");
customProperties.put("ssl.keyStore.password", "123456");
customProperties.put("ssl.trustStore.location", absolutePath + File.separator + "TrustStore.jks");
customProperties.put("ssl.trustStore.password", "123456");
customProperties.put("ssl.hostnameVerification", "false");
customProperties.put("serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");

InstanceSpec instanceSpec = new InstanceSpec(null,
randomUsablePort,
-1,
-1,
true,
-1,
-1,
-1,
customProperties);
int securePort = InstanceSpec.getRandomPort();
InstanceSpec instanceSpec = instanceSpec(securePort, absolutePath);

try (TestingServer testingServer = new TestingServer(instanceSpec, true)) {
ExpressGateway.setInstance(forTest(new ExpressGateway.ZooKeeper(testingServer.getConnectString(),
ExpressGateway.setInstance(forTest(new ExpressGateway.ZooKeeper("127.0.0.1:" + securePort,
3,
100,
true,
Expand All @@ -101,4 +84,26 @@ void connectToZooKeeperUsingTLSTest() throws Exception {
System.clearProperty("zookeeper.ssl.trustStore.password");
}
}

@NotNull
private static InstanceSpec instanceSpec(int securePort, String absolutePath) {
Map<String, Object> customProperties = new HashMap<>();
customProperties.put("secureClientPort", String.valueOf(securePort));
customProperties.put("ssl.keyStore.location", absolutePath + File.separator + "KeyStore.jks");
customProperties.put("ssl.keyStore.password", "123456");
customProperties.put("ssl.trustStore.location", absolutePath + File.separator + "TrustStore.jks");
customProperties.put("ssl.trustStore.password", "123456");
customProperties.put("ssl.hostnameVerification", "false");
customProperties.put("serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");

return new InstanceSpec(null,
InstanceSpec.getRandomPort(),
-1,
-1,
true,
-1,
-1,
-1,
customProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
package com.shieldblaze.expressgateway.common.zookeeper;

import com.shieldblaze.expressgateway.common.ExpressGateway;
import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.QuorumConfigBuilder;
import org.apache.curator.test.QuorumPeerConfigBuilder;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.ZooKeeperServerEmbeddedAdapter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static com.shieldblaze.expressgateway.common.zookeeper.Curator.getInstance;
import static com.shieldblaze.expressgateway.common.zookeeper.CuratorUtils.createNew;
import static com.shieldblaze.expressgateway.common.zookeeper.CuratorUtils.deleteData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public final class IntermediateCrypto {
Cipher.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
Cipher.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Cipher.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
Cipher.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
);

private IntermediateCrypto() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ void simpleCipherTest() {
Cipher.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
Cipher.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Cipher.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
Cipher.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
Cipher.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
);

assertThat(ciphers, is(IntermediateCrypto.CIPHERS));
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ along with ShieldBlaze ExpressGateway. If not, see <https://www.gnu.org/license
<maven.compiler.target>17</maven.compiler.target>

<!-- Version Management -->
<apache.curator>5.3.0</apache.curator>
<apache.curator>5.5.0</apache.curator>
<netty>4.1.97.Final</netty>
<spring.boot>2.7.5</spring.boot>
</properties>
Expand Down Expand Up @@ -281,7 +281,7 @@ along with ShieldBlaze ExpressGateway. If not, see <https://www.gnu.org/license
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public final class ServiceDiscoveryClient {
false,
false,
serviceDiscovery.hostnameVerification(),
serviceDiscovery.hostnameVerification()
serviceDiscovery.hostnameVerification(),
false
)};

SSLContext sslContext = SSLContext.getInstance("TLSv1.3");
Expand Down

0 comments on commit 6afa14b

Please sign in to comment.