Allow empty credential values in requests
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
package org.springframework.credhub.support;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
/**
|
||||
* The details of a request to write a new or update an existing credential in CredHub.
|
||||
*
|
||||
@@ -39,6 +41,7 @@ public class CredentialRequest<T> extends CredHubRequest<T> {
|
||||
*
|
||||
* @return the value of the credential
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public T getValue() {
|
||||
return this.details;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.junit.Test;
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
import org.springframework.credhub.support.json.JsonCredentialRequest.JsonCredentialRequestBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.springframework.credhub.support.JsonPathAssert.assertThat;
|
||||
|
||||
@@ -32,17 +35,18 @@ public class JsonCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
public void setUp() {
|
||||
requestBuilder = JsonCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.value(new JsonCredential() {
|
||||
{
|
||||
put("data", "value");
|
||||
put("test", true);
|
||||
}
|
||||
})
|
||||
.mode(WriteMode.OVERWRITE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeWithJsonValue() {
|
||||
((JsonCredentialRequestBuilder) requestBuilder).value(new JsonCredential() {
|
||||
{
|
||||
put("data", "value");
|
||||
put("test", true);
|
||||
}
|
||||
});
|
||||
|
||||
DocumentContext json = toJsonPath(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(json, null, WriteMode.OVERWRITE, "/example/credential", "json");
|
||||
@@ -51,4 +55,17 @@ public class JsonCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
|
||||
assertNoPermissions(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeWithEmptyValue() {
|
||||
((JsonCredentialRequestBuilder) requestBuilder).value(new JsonCredential() {
|
||||
});
|
||||
|
||||
DocumentContext json = toJsonPath(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(json, null, WriteMode.OVERWRITE, "/example/credential", "json");
|
||||
assertThat(json).hasPath("$.value").isEqualTo(Collections.EMPTY_MAP);
|
||||
|
||||
assertNoPermissions(json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user