Skip to content

Commit 2bb01f8

Browse files
authored
Merge pull request #1483 from marklogic/feature/refactor-test-client
Added securityContextType property to test plumbing
2 parents bb9c211 + fa07f54 commit 2bb01f8

27 files changed

+215
-182
lines changed

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pipeline{
101101
export PATH=$GRADLE_USER_HOME:$JAVA_HOME/bin:$PATH
102102
cd java-client-api
103103
./gradlew -i marklogic-client-api:test || true
104+
./gradlew marklogic-client-api-functionaltests:runFastFunctionalTests || true
104105
'''
105106
junit '**/build/**/TEST*.xml'
106107
}

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/WBFailover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void testBlackListHost() throws Exception {
332332
final AtomicInteger successCount = new AtomicInteger(0);
333333
final AtomicBoolean containsBLHost = new AtomicBoolean(false);
334334
final AtomicBoolean failState = new AtomicBoolean(false);
335-
SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("admin", "admin");
335+
SecurityContext secContext = newSecurityContext("admin", "admin");
336336
DatabaseClient dbClient = DatabaseClientFactory.newClient(hostLists.get(3), 8000, secContext, getConnType());
337337
DataMovementManager dmManager = dbClient.newDataMovementManager();
338338
WriteBatcher ihb2 = dmManager.newWriteBatcher();

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/AbstractFunctionalTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public static void initializeClients() throws Exception {
6161
adminModulesClient = getDatabaseClientOnDatabase(getRestServerHostName(), getRestServerPort(), modulesDbName, getAdminUser(), getAdminPassword(), getConnType());
6262
} else {
6363
schemasClient = DatabaseClientFactory.newClient(getRestServerHostName(), getRestServerPort(), schemasDbName,
64-
new DatabaseClientFactory.DigestAuthContext(OPTIC_USER, OPTIC_USER_PASSWORD));
64+
newSecurityContext(OPTIC_USER, OPTIC_USER_PASSWORD));
6565
client = DatabaseClientFactory.newClient(getRestServerHostName(), getRestServerPort(),
66-
new DatabaseClientFactory.DigestAuthContext(OPTIC_USER, OPTIC_USER_PASSWORD));
66+
newSecurityContext(OPTIC_USER, OPTIC_USER_PASSWORD));
6767
adminModulesClient = DatabaseClientFactory.newClient(getRestServerHostName(), getRestServerPort(), modulesDbName,
68-
new DatabaseClientFactory.DigestAuthContext(getAdminUser(), getAdminPassword()));
68+
newSecurityContext(getAdminUser(), getAdminPassword()));
6969
}
7070

7171
// Required to ensure that tests using the "/ext/" prefix work reliably. Expand to other directories as needed.
@@ -155,12 +155,12 @@ protected final String toWKT(String latLon) {
155155

156156
protected static DatabaseClient connectAsRestWriter() {
157157
return DatabaseClientFactory.newClient(getRestServerHostName(), getRestServerPort(),
158-
new DatabaseClientFactory.DigestAuthContext("rest-writer", "x"), getConnType());
158+
newSecurityContext("rest-writer", "x"), getConnType());
159159
}
160160

161161
protected static DatabaseClient connectAsAdmin() {
162162
return DatabaseClientFactory.newClient(getRestServerHostName(), getRestServerPort(),
163-
new DatabaseClientFactory.DigestAuthContext(getAdminUser(), getAdminPassword()), getConnType());
163+
newSecurityContext(getAdminUser(), getAdminPassword()), getConnType());
164164
}
165165

166166
protected static void removeFieldIndices() {

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestBulkWriteWithTransformations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void setUp() throws Exception {
7474
if (isLBHost())
7575
client = getDatabaseClient("eval-user", "x", getConnType());
7676
else {
77-
SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x");
77+
SecurityContext secContext = newSecurityContext("eval-user", "x");
7878
client = DatabaseClientFactory.newClient(appServerHostname, uberPort, "java-functest", secContext, getConnType());
7979
}
8080
}

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestDatabaseAuthentication.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
import com.marklogic.client.DatabaseClientFactory.SecurityContext;
2222
import com.marklogic.client.io.InputStreamHandle;
2323
import org.junit.After;
24-
import org.junit.AfterClass;
2524
import org.junit.Test;
2625

2726
import java.io.IOException;
2827
import java.io.InputStream;
29-
import java.security.KeyManagementException;
30-
import java.security.NoSuchAlgorithmException;
3128

3229
import static org.junit.Assert.assertEquals;
3330

@@ -42,13 +39,14 @@ public class TestDatabaseAuthentication extends AbstractFunctionalTest {
4239
private static String restServerName = "java-functest";
4340

4441
@After
45-
public void testCleanUp() throws Exception {
46-
deleteDocuments(connectAsAdmin());
42+
public void teardown() throws Exception {
43+
setAuthentication(securityContextType, restServerName);
44+
setDefaultUser("nobody", restServerName);
4745
}
4846

4947
// Should throw exceptions when none specified.
5048
@Test
51-
public void testAuthenticationNone() throws KeyManagementException, NoSuchAlgorithmException, IOException
49+
public void testAuthenticationNone() throws IOException
5250
{
5351
System.out.println("Running testAuthenticationNone");
5452
if (!IsSecurityEnabled()) {
@@ -63,13 +61,11 @@ public void testAuthenticationNone() throws KeyManagementException, NoSuchAlgori
6361
}
6462
assertEquals("Write Text difference", "makeSecurityContext should only be called with BASIC or DIGEST Authentication",
6563
str.toString().trim());
66-
setAuthentication("digest", restServerName);
67-
setDefaultUser("nobody", restServerName);
6864
}
6965
}
7066

7167
@Test
72-
public void testAuthenticationBasic() throws KeyManagementException, NoSuchAlgorithmException, IOException
68+
public void testAuthenticationBasic() throws IOException
7369
{
7470
if (!IsSecurityEnabled()) {
7571
setAuthentication("basic", restServerName);
@@ -100,15 +96,6 @@ public void testAuthenticationBasic() throws KeyManagementException, NoSuchAlgor
10096

10197
// release client
10298
client.release();
103-
104-
setAuthentication("digest", restServerName);
105-
setDefaultUser("nobody", restServerName);
10699
}
107100
}
108-
109-
@AfterClass
110-
public static void tearDown() throws Exception {
111-
setAuthentication("digest", restServerName);
112-
setDefaultUser("nobody", restServerName);
113-
}
114101
}

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/fastfunctest/TestHandles.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testXmlCRUD_BytesHandle() throws KeyManagementException, NoSuchAlgor
7878
XMLUnit.setNormalizeWhitespace(true);
7979

8080
// connect the client
81-
DatabaseClientFactory.SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x");
81+
DatabaseClientFactory.SecurityContext secContext = newSecurityContext("eval-user", "x");
8282
DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType());
8383

8484
// write docs
@@ -140,7 +140,7 @@ public void testTextCRUD_BytesHandle() throws KeyManagementException, NoSuchAlgo
140140
System.out.println("Runing test TextCRUD_BytesHandle");
141141

142142
// connect the client
143-
DatabaseClientFactory.SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x");
143+
DatabaseClientFactory.SecurityContext secContext = newSecurityContext("eval-user", "x");
144144
DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType());
145145

146146
// write docs
@@ -201,7 +201,7 @@ public void testJsonCRUD_BytesHandle() throws KeyManagementException, NoSuchAlgo
201201
ObjectMapper mapper = new ObjectMapper();
202202

203203
// connect the client
204-
DatabaseClientFactory.SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x");
204+
DatabaseClientFactory.SecurityContext secContext = newSecurityContext("eval-user", "x");
205205
DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType());
206206

207207
// write docs
@@ -262,7 +262,7 @@ public void testBinaryCRUD_BytesHandle() throws KeyManagementException, NoSuchAl
262262
System.out.println("Running testBinaryCRUD_BytesHandle");
263263

264264
// connect the client
265-
DatabaseClientFactory.SecurityContext secContext = new DatabaseClientFactory.DigestAuthContext("eval-user", "x");
265+
DatabaseClientFactory.SecurityContext secContext = newSecurityContext("eval-user", "x");
266266
DatabaseClient client = DatabaseClientFactory.newClient(appServerHostname, uberPort, dbName, secContext, getConnType());
267267

268268
// write docs

0 commit comments

Comments
 (0)