Skip to content

Commit b0c4235

Browse files
committed
fix #4 since my logic in InvalidUserTest.java needed fixing to actually run the assert; also added SSLTest.java for additional validation
1 parent 79910e1 commit b0c4235

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/test/java/com/marklogic/client/test/InvalidUserTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,20 @@ public void testInvalidUserAuth() {
4040

4141
String docId = "/example/text.txt";
4242
TextDocumentManager docMgr = client.newTextDocumentManager();
43-
// write doc
44-
try
45-
{
46-
// make use of the client connection
43+
try {
44+
// make use of the client connection so we get an auth error
4745
StringHandle handle = new StringHandle();
4846
handle.set("A simple text document");
4947
docMgr.write(docId, handle);
50-
assertEquals(expectedException, exception);
48+
// the next line will only run if write doesn't throw an exception
5149
docMgr.delete(docId);
5250
}
5351
catch (Exception e) {
5452
exception = e.toString();
5553
} finally {
5654
client.release();
5755
}
56+
assertEquals(expectedException, exception);
5857

5958
}
6059
}

src/test/java/com/marklogic/client/test/SSLTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ public class SSLTest {
3737
@Test
3838
public void testSSLAuth() throws NoSuchAlgorithmException, KeyManagementException {
3939

40-
// create a trust manager
41-
// (note: a real application should verify certificates)
42-
TrustManager naiveTrustMgr = new X509TrustManager() {
43-
@Override
44-
public void checkClientTrusted(X509Certificate[] chain, String authType) {
45-
}
46-
@Override
47-
public void checkServerTrusted(X509Certificate[] chain, String authType) {
48-
}
49-
@Override
50-
public X509Certificate[] getAcceptedIssuers() {
51-
return new X509Certificate[0];
52-
}
53-
};
40+
// create a trust manager
41+
// (note: a real application should verify certificates)
42+
TrustManager naiveTrustMgr = new X509TrustManager() {
43+
@Override
44+
public void checkClientTrusted(X509Certificate[] chain, String authType) {
45+
}
46+
@Override
47+
public void checkServerTrusted(X509Certificate[] chain, String authType) {
48+
}
49+
@Override
50+
public X509Certificate[] getAcceptedIssuers() {
51+
return new X509Certificate[0];
52+
}
53+
};
5454

5555
// create an SSL context
5656
SSLContext sslContext = SSLContext.getInstance("SSLv3");
@@ -60,18 +60,18 @@ public X509Certificate[] getAcceptedIssuers() {
6060
DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8012, "MyFooUser", "x", Authentication.DIGEST, sslContext, SSLHostnameVerifier.ANY);
6161

6262

63-
String expectedException = "FailedRequestException: Local message: write failed: Unauthorized";
63+
String expectedException = "com.sun.jersey.api.client.ClientHandlerException: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated";
6464
String exception = "";
6565

66-
// write doc
67-
try
68-
{
69-
// make use of the client connection
66+
try {
67+
// make use of the client connection so we get an auth error
7068
TextDocumentManager docMgr = client.newTextDocumentManager();
7169
String docId = "/example/text.txt";
7270
StringHandle handle = new StringHandle();
7371
handle.set("A simple text document");
7472
docMgr.write(docId, handle);
73+
// the next line will only run if write doesn't throw an exception
74+
docMgr.delete(docId);
7575
}
7676
catch (Exception e) {
7777
exception = e.toString();

0 commit comments

Comments
 (0)