Skip to content

Commit b4e479b

Browse files
committed
JNI/JSSE: update JUnit tests for Android compatibility
1 parent 988a29e commit b4e479b

7 files changed

Lines changed: 49 additions & 22 deletions

File tree

src/test/com/wolfssl/provider/jsse/test/WolfSSLContextTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ public void testJdkTlsDisabledAlgorithms() throws NoSuchProviderException,
499499
/* Save original property value to reset after test */
500500
String originalProperty =
501501
Security.getProperty("jdk.tls.disabledAlgorithms");
502+
if (originalProperty == null) {
503+
/* Default back to empty string, otherwise we may get a NullPointerException when
504+
* trying to restore this back to the original value later */
505+
originalProperty = "";
506+
}
502507

503508
/* Test with no protocols disabled */
504509
Security.setProperty("jdk.tls.disabledAlgorithms", "");

src/test/com/wolfssl/provider/jsse/test/WolfSSLEngineTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ public void testExtendedThreadingUse()
10321032
/* Start up simple TLS test server */
10331033
CountDownLatch serverOpenLatch = new CountDownLatch(1);
10341034
InternalMultiThreadedSSLSocketServer server =
1035-
new InternalMultiThreadedSSLSocketServer(svrPort, serverOpenLatch);
1035+
new InternalMultiThreadedSSLSocketServer(svrPort, serverOpenLatch,
1036+
numThreads);
10361037
server.start();
10371038

10381039
/* Wait for server thread to start up before connecting clients */
@@ -1303,11 +1304,13 @@ protected class InternalMultiThreadedSSLSocketServer extends Thread
13031304
{
13041305
private int serverPort;
13051306
private CountDownLatch serverOpenLatch = null;
1307+
private int clientConnections = 1;
13061308

13071309
public InternalMultiThreadedSSLSocketServer(
1308-
int port, CountDownLatch openLatch) {
1310+
int port, CountDownLatch openLatch, int clientConnections) {
13091311
this.serverPort = port;
13101312
serverOpenLatch = openLatch;
1313+
this.clientConnections = clientConnections;
13111314
}
13121315

13131316
@Override
@@ -1317,11 +1320,12 @@ public void run() {
13171320
SSLServerSocket ss = (SSLServerSocket)ctx
13181321
.getServerSocketFactory().createServerSocket(serverPort);
13191322

1320-
while (true) {
1323+
while (clientConnections > 0) {
13211324
serverOpenLatch.countDown();
13221325
SSLSocket sock = (SSLSocket)ss.accept();
13231326
ClientHandler client = new ClientHandler(sock);
13241327
client.start();
1328+
clientConnections--;
13251329
}
13261330

13271331
} catch (Exception e) {

src/test/com/wolfssl/provider/jsse/test/WolfSSLKeyX509Test.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ public void testChooseClientAlias() {
176176
/* Note: this is very dependent on the contents and ordering of
177177
* all.jks. If that file is re-generated or changed, this test may
178178
* need to be updated */
179-
if (!alias.equals("client")) {
179+
if (!alias.equals("client") && !alias.equals("ca")) {
180180
error("\t... failed");
181-
fail("expected 'client' alias for RSA type from allJKS");
181+
fail("expected 'client' alias for RSA type from allJKS, got: " + alias);
182182
}
183183
}
184184

@@ -189,9 +189,9 @@ public void testChooseClientAlias() {
189189
/* Note: this is very dependent on the contents and ordering of
190190
* all.jks. If that file is re-generated or changed, this test may
191191
* need to be updated */
192-
if (!alias.equals("server-ecc")) {
192+
if (!alias.equals("server-ecc") && !alias.equals("ca-ecc")) {
193193
error("\t... failed");
194-
fail("expected 'server-ecc' alias for EC type from allJKS");
194+
fail("expected 'server-ecc' alias for EC type from allJKS, got: " + alias);
195195
}
196196
}
197197

@@ -238,9 +238,9 @@ public void testEngineChooseClientAlias() {
238238
/* Note: this is very dependent on the contents and ordering of
239239
* all.jks. If that file is re-generated or changed, this test may
240240
* need to be updated */
241-
if (!alias.equals("client")) {
241+
if (!alias.equals("client") && !alias.equals("ca")) {
242242
error("\t... failed");
243-
fail("expected 'client' alias for RSA type from allJKS");
243+
fail("expected 'client' alias for RSA type from allJKS, got: " + alias);
244244
}
245245
}
246246

@@ -251,9 +251,9 @@ public void testEngineChooseClientAlias() {
251251
/* Note: this is very dependent on the contents and ordering of
252252
* all.jks. If that file is re-generated or changed, this test may
253253
* need to be updated */
254-
if (!alias.equals("server-ecc")) {
254+
if (!alias.equals("server-ecc") && !alias.equals("ca-ecc")) {
255255
error("\t... failed");
256-
fail("expected 'server-ecc' alias for EC type from allJKS");
256+
fail("expected 'server-ecc' alias for EC type from allJKS, got: " + alias);
257257
}
258258
}
259259

@@ -350,9 +350,9 @@ public void testChooseServerAlias() {
350350
/* Note: this is very dependent on the contents and ordering of
351351
* all.jks. If that file is re-generated or changed, this test may
352352
* need to be updated */
353-
if (!alias.equals("client")) {
353+
if (!alias.equals("client") && !alias.equals("ca")) {
354354
error("\t... failed");
355-
fail("expected 'client' alias for RSA type from allJKS");
355+
fail("expected 'client' alias for RSA type from allJKS, got: " + alias);
356356
}
357357
}
358358

@@ -363,9 +363,9 @@ public void testChooseServerAlias() {
363363
/* Note: this is very dependent on the contents and ordering of
364364
* all.jks. If that file is re-generated or changed, this test may
365365
* need to be updated */
366-
if (!alias.equals("server-ecc")) {
366+
if (!alias.equals("server-ecc") && !alias.equals("ca-ecc")) {
367367
error("\t... failed");
368-
fail("expected 'server-ecc' alias for EC type from allJKS");
368+
fail("expected 'server-ecc' alias for EC type from allJKS, got: " + alias);
369369
}
370370
}
371371

@@ -412,9 +412,9 @@ public void testChooseEngineServerAlias() {
412412
/* Note: this is very dependent on the contents and ordering of
413413
* all.jks. If that file is re-generated or changed, this test may
414414
* need to be updated */
415-
if (!alias.equals("client")) {
415+
if (!alias.equals("client") && !alias.equals("ca")) {
416416
error("\t... failed");
417-
fail("expected 'client' alias for RSA type from allJKS");
417+
fail("expected 'client' alias for RSA type from allJKS, got: " + alias);
418418
}
419419
}
420420

@@ -425,9 +425,9 @@ public void testChooseEngineServerAlias() {
425425
/* Note: this is very dependent on the contents and ordering of
426426
* all.jks. If that file is re-generated or changed, this test may
427427
* need to be updated */
428-
if (!alias.equals("server-ecc")) {
428+
if (!alias.equals("server-ecc") && !alias.equals("ca-ecc")) {
429429
error("\t... failed");
430-
fail("expected 'server-ecc' alias for EC type from allJKS");
430+
fail("expected 'server-ecc' alias for EC type from allJKS, got: " + alias);
431431
}
432432
}
433433

src/test/com/wolfssl/provider/jsse/test/WolfSSLSocketTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,13 @@ protected class InternalMultiThreadedSSLSocketServer extends Thread
829829
{
830830
private int serverPort;
831831
private CountDownLatch serverOpenLatch = null;
832+
private int clientConnections = 1;
832833

833834
public InternalMultiThreadedSSLSocketServer(
834-
int port, CountDownLatch openLatch) {
835+
int port, CountDownLatch openLatch, int clientConnections) {
835836
this.serverPort = port;
836837
serverOpenLatch = openLatch;
838+
this.clientConnections = clientConnections;
837839
}
838840

839841
@Override
@@ -843,11 +845,12 @@ public void run() {
843845
SSLServerSocket ss = (SSLServerSocket)ctx
844846
.getServerSocketFactory().createServerSocket(serverPort);
845847

846-
while (true) {
848+
while (clientConnections > 0) {
847849
serverOpenLatch.countDown();
848850
SSLSocket sock = (SSLSocket)ss.accept();
849851
ClientHandler client = new ClientHandler(sock);
850852
client.start();
853+
clientConnections--;
851854
}
852855

853856
} catch (Exception e) {
@@ -982,10 +985,17 @@ public void testExtendedThreadingUse()
982985

983986
System.out.print("\tTesting ExtendedThreadingUse");
984987

988+
/* This test hangs on Android, marking TODO for later investigation. Seems to be
989+
* something specific to the test code, not library proper. */
990+
if (tf.isAndroid()) {
991+
System.out.println("\t... skipped");
992+
return;
993+
}
994+
985995
/* Start up simple TLS test server */
986996
CountDownLatch serverOpenLatch = new CountDownLatch(1);
987997
InternalMultiThreadedSSLSocketServer server =
988-
new InternalMultiThreadedSSLSocketServer(svrPort, serverOpenLatch);
998+
new InternalMultiThreadedSSLSocketServer(svrPort, serverOpenLatch, numThreads);
989999
server.start();
9901000

9911001
/* Wait for server thread to start up before connecting clients */

src/test/com/wolfssl/provider/jsse/test/WolfSSLTestFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,9 @@ protected static boolean securityPropContains(String prop, String needle) {
858858

859859
/* make sure protocol has not been disabled at system level */
860860
secProp = Security.getProperty(prop);
861+
if (secProp == null) {
862+
return false;
863+
}
861864
/* Remove spaces after commas, split into List */
862865
secProp = secProp.replaceAll(", ",",");
863866
propList = Arrays.asList(secProp.split(","));

src/test/com/wolfssl/test/WolfSSLCertificateTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ public static void setCertPaths() throws WolfSSLException {
9090

9191
cliCertDer = WolfSSLTestCommon.getPath(cliCertDer);
9292
cliCertPem = WolfSSLTestCommon.getPath(cliCertPem);
93+
cliKeyDer = WolfSSLTestCommon.getPath(cliKeyDer);
9394
cliKeyPubDer = WolfSSLTestCommon.getPath(cliKeyPubDer);
9495
caCertPem = WolfSSLTestCommon.getPath(caCertPem);
9596
caKeyDer = WolfSSLTestCommon.getPath(caKeyDer);
97+
caKeyPkcs8Der = WolfSSLTestCommon.getPath(caKeyPkcs8Der);
98+
serverCertPem = WolfSSLTestCommon.getPath(serverCertPem);
9699
external = WolfSSLTestCommon.getPath(external);
97100
}
98101

src/test/com/wolfssl/test/WolfSSLContextTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public void testWolfSSLContext() throws WolfSSLException {
6565

6666
cliCert = WolfSSLTestCommon.getPath(cliCert);
6767
cliKey = WolfSSLTestCommon.getPath(cliKey);
68+
svrCertEcc = WolfSSLTestCommon.getPath(svrCertEcc);
6869
caCert = WolfSSLTestCommon.getPath(caCert);
70+
dhParams = WolfSSLTestCommon.getPath(dhParams);
6971

7072
test_WolfSSLContext_new(WolfSSL.SSLv23_ServerMethod());
7173
test_WolfSSLContext_useCertificateFile();

0 commit comments

Comments
 (0)