Skip to content

Commit

Permalink
ZOOKEEPER-4259 - add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkalmar committed Mar 24, 2021
1 parent 5bdd3a7 commit b19a9b3
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.Security;
Expand Down Expand Up @@ -143,6 +146,7 @@ public void cleanUp() {
System.clearProperty("zookeeper.ssl.quorum.trustStore.password");
System.clearProperty("zookeeper.ssl.quorum.trustStore.type");
System.clearProperty("zookeeper.admin.portUnification");
System.clearProperty("zookeeper.admin.forceHTTPS");
}

/**
Expand Down Expand Up @@ -234,6 +238,45 @@ public void testQuorum() throws Exception {
"waiting for server 2 down");
}

@Test
public void testForceHttpsPortUnificationEnabled() throws Exception {
System.setProperty("zookeeper.admin.forceHTTPS", "true");
boolean httpsPassed = false;

JettyAdminServer server = new JettyAdminServer();
try {
server.start();
queryAdminServer(String.format(HTTPS_URL_FORMAT, jettyAdminPort), true);
httpsPassed = true;
queryAdminServer(String.format(URL_FORMAT, jettyAdminPort), false);
} catch(SocketException se) {
//good
} finally {
server.shutdown();
}
assertTrue(httpsPassed);
}

@Test
public void testForceHttpsPortUnificationDisabled() throws Exception {
System.setProperty("zookeeper.admin.forceHTTPS", "true");
System.setProperty("zookeeper.admin.portUnification", "false");
boolean httpsPassed = false;

JettyAdminServer server = new JettyAdminServer();
try {
server.start();
queryAdminServer(String.format(HTTPS_URL_FORMAT, jettyAdminPort), true);
httpsPassed = true;
queryAdminServer(String.format(URL_FORMAT, jettyAdminPort), false);
} catch(SocketException se) {
//good
} finally {
server.shutdown();
}
assertTrue(httpsPassed);
}

/**
* Check that we can load the commands page of an AdminServer running at
* localhost:port. (Note that this should work even if no zk server is set.)
Expand Down

0 comments on commit b19a9b3

Please sign in to comment.