Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.marklogic
version=6.6-SNAPSHOT
version=6.7-SNAPSHOT
describedName=MarkLogic Java Client API
publishUrl=file:../marklogic-java/releases

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,13 @@ private DatabaseClientFactory.SecurityContext newSecurityContext(String type, SS
}

private String getRequiredStringValue(String propertyName) {
return getRequiredStringValue(propertyName, String.format("%s must be of type String", propertyName));
}

private String getRequiredStringValue(String propertyName, String errorMessage) {
Object value = propertySource.apply(PREFIX + propertyName);
if (value == null || !(value instanceof String)) {
throw new IllegalArgumentException(propertyName + " must be of type String");
throw new IllegalArgumentException(errorMessage);
}
return (String) value;
}
Expand All @@ -204,13 +208,15 @@ private String getNullableStringValue(String propertyName, String defaultValue)

private DatabaseClientFactory.SecurityContext newBasicAuthContext() {
return new DatabaseClientFactory.BasicAuthContext(
getRequiredStringValue("username"), getRequiredStringValue("password")
getRequiredStringValue("username", "Must specify a username when using basic authentication."),
getRequiredStringValue("password", "Must specify a password when using basic authentication.")
);
}

private DatabaseClientFactory.SecurityContext newDigestAuthContext() {
return new DatabaseClientFactory.DigestAuthContext(
getRequiredStringValue("username"), getRequiredStringValue("password")
getRequiredStringValue("username", "Must specify a username when using digest authentication."),
getRequiredStringValue("password", "Must specify a password when using digest authentication.")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ void digest() {
assertEquals("my-password", context.getPassword());
}

@Test
void digestNoUsername() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () ->
Common.newClientBuilder().withDigestAuth(null, "my-password").buildBean());
assertEquals("Must specify a username when using digest authentication.", ex.getMessage());
}

@Test
void digestNoPassword() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () ->
Common.newClientBuilder().withDigestAuth("my-user", null).buildBean());
assertEquals("Must specify a password when using digest authentication.", ex.getMessage());
}

@Test
void basic() {
bean = Common.newClientBuilder()
Expand All @@ -102,6 +116,20 @@ void basic() {
assertEquals("my-password", context.getPassword());
}

@Test
void basicNoUsername() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () ->
Common.newClientBuilder().withBasicAuth(null, "my-password").buildBean());
assertEquals("Must specify a username when using basic authentication.", ex.getMessage());
}

@Test
void basicNoPassword() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () ->
Common.newClientBuilder().withBasicAuth("my-user", null).buildBean());
assertEquals("Must specify a password when using basic authentication.", ex.getMessage());
}

@Test
void cloudWithBasePath() {
bean = Common.newClientBuilder()
Expand Down