Add a mode field to set and generate requests and deprecate the overwrite field.
Fixes #35
This commit is contained in:
@@ -30,15 +30,17 @@ import java.util.List;
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class CredHubRequest<T> {
|
||||
protected boolean overwrite;
|
||||
protected WriteMode mode;
|
||||
protected CredentialName name;
|
||||
protected CredentialType credentialType;
|
||||
protected List<CredentialPermission> additionalPermissions;
|
||||
protected T details;
|
||||
|
||||
public CredHubRequest() {
|
||||
additionalPermissions = new ArrayList<CredentialPermission>();
|
||||
additionalPermissions = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +48,7 @@ public class CredHubRequest<T> {
|
||||
* should create a new credential or update an existing credential.
|
||||
*
|
||||
* @return the {@literal boolean} overwrite value
|
||||
* @deprecated as of CredHub 1.6, use {@link #mode}
|
||||
*/
|
||||
public boolean isOverwrite() {
|
||||
return this.overwrite;
|
||||
@@ -55,6 +58,19 @@ public class CredHubRequest<T> {
|
||||
this.overwrite = overwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the write mode indicator.
|
||||
*
|
||||
* @return the write mode
|
||||
*/
|
||||
public WriteMode getMode() {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
void setMode(WriteMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link CredentialName} of the credential.
|
||||
*
|
||||
@@ -182,12 +198,25 @@ public class CredHubRequest<T> {
|
||||
* @param overwrite {@literal false} to create a new credential, or
|
||||
* {@literal true} to update and existing credential
|
||||
* @return the builder
|
||||
* @deprecated as of CredHub 1.6, use {@link #mode(WriteMode)}
|
||||
*/
|
||||
public B overwrite(boolean overwrite) {
|
||||
targetObj.setOverwrite(overwrite);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value indicating the action CredHub should take when a credential being written
|
||||
* or generated already exists.
|
||||
*
|
||||
* @param mode the {@link WriteMode} to use when a credential exists
|
||||
* @return the builder
|
||||
*/
|
||||
public B mode(WriteMode mode) {
|
||||
targetObj.setMode(mode);
|
||||
return thisObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an {@link CredentialPermission} to the permissions that will be assigned to the
|
||||
* credential.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.springframework.credhub.support;
|
||||
|
||||
/**
|
||||
* The acceptable values for the {@code mode} parameter on a set or generate request,
|
||||
* indicating the action CredHub should take when the credential being set or generated
|
||||
* already exists.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public enum WriteMode {
|
||||
/**
|
||||
* Indicates that CredHub should not replace the value of a credential
|
||||
* if the credential exists
|
||||
*/
|
||||
NO_OVERWRITE("no-overwrite"),
|
||||
|
||||
/**
|
||||
* Indicates that CredHub should replace any existing credential
|
||||
* value with a new value
|
||||
*/
|
||||
OVERWRITE("overwrite"),
|
||||
|
||||
/**
|
||||
* Indicates that CredHub should replace any existing credential
|
||||
* value with a new value only if generation parameters are different
|
||||
* from the original generation parameters
|
||||
*/
|
||||
CONVERGE("converge");
|
||||
|
||||
private final String mode;
|
||||
|
||||
WriteMode(String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code mode} value as a {@code String}
|
||||
*
|
||||
* @return the mode value
|
||||
*/
|
||||
public String getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String toString() {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ package org.springframework.credhub.support.permissions;
|
||||
*/
|
||||
public enum ActorType {
|
||||
/**
|
||||
* An Cloud Foundry application entity
|
||||
* A Cloud Foundry application entity
|
||||
*/
|
||||
APP("mtls-app"),
|
||||
|
||||
|
||||
@@ -110,9 +110,10 @@ public abstract class CredHubRequestUnitTestsBase {
|
||||
return jsonValue;
|
||||
}
|
||||
|
||||
protected void assertCommonRequestFields(String jsonValue, boolean overwrite, String name, String type) {
|
||||
protected void assertCommonRequestFields(String jsonValue, boolean overwrite, WriteMode writeMode, String name, String type) {
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.overwrite", equalTo(overwrite)),
|
||||
hasJsonPath("$.mode", equalTo(writeMode.getMode())),
|
||||
hasJsonPath("$.name", equalTo(name)),
|
||||
hasJsonPath("$.type", equalTo(type))));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -38,7 +39,7 @@ public class CertificateCredentialRequestUnitTests extends CredHubRequestUnitTes
|
||||
public void serializeWithAllValues() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "certificate");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.certificate", equalTo("cert")),
|
||||
hasJsonPath("$.value.ca", equalTo("ca")),
|
||||
@@ -53,7 +54,7 @@ public class CertificateCredentialRequestUnitTests extends CredHubRequestUnitTes
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "certificate");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.certificate", equalTo("cert")),
|
||||
hasNoJsonPath("$.value.ca"),
|
||||
@@ -68,7 +69,7 @@ public class CertificateCredentialRequestUnitTests extends CredHubRequestUnitTes
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "certificate");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.value.certificate"),
|
||||
hasJsonPath("$.value.ca", equalTo("ca")),
|
||||
@@ -84,10 +85,12 @@ public class CertificateCredentialRequestUnitTests extends CredHubRequestUnitTes
|
||||
serializeToJson(requestBuilder);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void buildRequest(CertificateCredential value) {
|
||||
requestBuilder = CertificateCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.KeyLength;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -29,6 +30,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -41,6 +43,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
requestBuilder = CertificateParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.parameters(CertificateParameters.builder()
|
||||
.keyLength(KeyLength.LENGTH_2048)
|
||||
.commonName("common")
|
||||
@@ -58,7 +61,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "certificate");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.parameters.key_length", equalTo(2048)),
|
||||
hasJsonPath("$.parameters.common_name", equalTo("common")),
|
||||
@@ -81,6 +84,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
requestBuilder = CertificateParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.NO_OVERWRITE)
|
||||
.parameters(CertificateParameters.builder()
|
||||
.commonName("common")
|
||||
.certificateAuthorityCredential("credential")
|
||||
@@ -88,7 +92,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.NO_OVERWRITE, "/example/credential", "certificate");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.parameters.key_length"),
|
||||
hasJsonPath("$.parameters.common_name", equalTo("common")),
|
||||
@@ -108,11 +112,12 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
public void serializeWithNoParameters() throws Exception {
|
||||
requestBuilder = CertificateParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true);
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.CONVERGE);
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "certificate");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.CONVERGE, "/example/credential", "certificate");
|
||||
assertParametersNotSet(jsonValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -38,14 +39,15 @@ public class JsonCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
put("data", "value");
|
||||
put("test", true);
|
||||
}
|
||||
});
|
||||
})
|
||||
.mode(WriteMode.OVERWRITE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeWithJsonValue() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, false, "/example/credential", "json");
|
||||
assertCommonRequestFields(jsonValue, false, WriteMode.OVERWRITE, "/example/credential", "json");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.data", equalTo("value")),
|
||||
hasJsonPath("$.value.test", equalTo(true))));
|
||||
|
||||
@@ -21,11 +21,13 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PasswordCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
|
||||
@Before
|
||||
@@ -33,6 +35,7 @@ public class PasswordCredentialRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
requestBuilder = PasswordCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(new PasswordCredential("secret"));
|
||||
}
|
||||
|
||||
@@ -40,7 +43,7 @@ public class PasswordCredentialRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
public void serializeWithPasswordValue() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "password");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "password");
|
||||
assertThat(jsonValue, hasJsonPath("$.value", equalTo("secret")));
|
||||
|
||||
assertNoPermissions(jsonValue);
|
||||
@@ -51,11 +54,12 @@ public class PasswordCredentialRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
requestBuilder = PasswordCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value("secret");
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "password");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "password");
|
||||
assertThat(jsonValue, hasJsonPath("$.value", equalTo("secret")));
|
||||
|
||||
assertNoPermissions(jsonValue);
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -28,6 +29,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PasswordParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -39,6 +41,7 @@ public class PasswordParametersRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
requestBuilder = PasswordParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.parameters(PasswordParameters.builder()
|
||||
.length(20)
|
||||
.excludeLower(true)
|
||||
@@ -49,7 +52,7 @@ public class PasswordParametersRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "password");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "password");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.parameters.length", equalTo(20)),
|
||||
hasJsonPath("$.parameters.exclude_lower", equalTo(true)),
|
||||
@@ -63,11 +66,12 @@ public class PasswordParametersRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
requestBuilder = PasswordParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.CONVERGE)
|
||||
.parameters(new PasswordParameters());
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "password");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.CONVERGE, "/example/credential", "password");
|
||||
assertParametersNotSet(jsonValue);
|
||||
}
|
||||
|
||||
@@ -75,11 +79,12 @@ public class PasswordParametersRequestUnitTests extends CredHubRequestUnitTestsB
|
||||
public void serializeWithNoParameters() throws Exception {
|
||||
requestBuilder = PasswordParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true);
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.NO_OVERWRITE);
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "password");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.NO_OVERWRITE, "/example/credential", "password");
|
||||
assertParametersNotSet(jsonValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -38,7 +39,7 @@ public class RsaCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
public void serializeWithPublicAndPrivateKey() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "rsa");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "rsa");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.public_key", equalTo("public-key")),
|
||||
hasJsonPath("$.value.private_key", equalTo("private-key"))));
|
||||
@@ -52,7 +53,7 @@ public class RsaCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "rsa");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "rsa");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.public_key", equalTo("public-key")),
|
||||
hasNoJsonPath("$.value.private_key")));
|
||||
@@ -66,7 +67,7 @@ public class RsaCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "rsa");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "rsa");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.value.public_key"),
|
||||
hasJsonPath("$.value.private_key", equalTo("private-key"))));
|
||||
@@ -81,10 +82,12 @@ public class RsaCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
serializeToJson(requestBuilder);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void buildRequest(RsaCredential value) {
|
||||
requestBuilder = RsaCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(value);
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,14 @@ import org.junit.Test;
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.KeyLength;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RsaParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -39,11 +41,12 @@ public class RsaParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
requestBuilder = RsaParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.parameters(new RsaParameters(KeyLength.LENGTH_4096));
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "rsa");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "rsa");
|
||||
assertThat(jsonValue, hasJsonPath("$.parameters.key_length", equalTo(4096)));
|
||||
}
|
||||
|
||||
@@ -51,11 +54,12 @@ public class RsaParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
public void serializeWithNoParameters() throws Exception {
|
||||
requestBuilder = RsaParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true);
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE);
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "rsa");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "rsa");
|
||||
assertThat(jsonValue, hasNoJsonPath("$.parameters.key_length"));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -38,7 +39,7 @@ public class SshCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
public void serializeWithPublicAndPrivateKey() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.public_key", equalTo("public-key")),
|
||||
hasJsonPath("$.value.private_key", equalTo("private-key"))));
|
||||
@@ -52,7 +53,7 @@ public class SshCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.public_key", equalTo("public-key")),
|
||||
hasNoJsonPath("$.value.private_key")));
|
||||
@@ -66,7 +67,7 @@ public class SshCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.value.public_key"),
|
||||
hasJsonPath("$.value.private_key", equalTo("private-key"))));
|
||||
@@ -81,10 +82,12 @@ public class SshCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
serializeToJson(requestBuilder);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void buildRequest(SshCredential value) {
|
||||
requestBuilder = SshCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(value);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.credhub.support.CredHubRequestUnitTestsBase;
|
||||
import org.springframework.credhub.support.KeyLength;
|
||||
import org.springframework.credhub.support.SimpleCredentialName;
|
||||
import org.springframework.credhub.support.WriteMode;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -29,6 +30,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SshParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -39,11 +41,12 @@ public class SshParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
requestBuilder = SshParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.parameters(new SshParameters(KeyLength.LENGTH_2048, "ssh comment"));
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.parameters.key_length", equalTo(2048)),
|
||||
hasJsonPath("$.parameters.ssh_comment", equalTo("ssh comment"))));
|
||||
@@ -54,11 +57,12 @@ public class SshParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
requestBuilder = SshParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.NO_OVERWRITE)
|
||||
.parameters(new SshParameters(KeyLength.LENGTH_2048));
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.NO_OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.parameters.key_length", equalTo(2048)),
|
||||
hasNoJsonPath("$.parameters.ssh_comment")));
|
||||
@@ -69,11 +73,12 @@ public class SshParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
requestBuilder = SshParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.CONVERGE)
|
||||
.parameters(new SshParameters("ssh comment"));
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.CONVERGE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.parameters.key_length"),
|
||||
hasJsonPath("$.parameters.ssh_comment", equalTo("ssh comment"))));
|
||||
@@ -83,11 +88,12 @@ public class SshParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
public void serializeWithNoParameters() throws Exception {
|
||||
requestBuilder = SshParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true);
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE);
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "ssh");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "ssh");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.parameters.key_length"),
|
||||
hasNoJsonPath("$.parameters.ssh_comment")));
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.user.UserCredentialRequest.UserCredentialRequestBuilder;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
@@ -29,12 +30,14 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
requestBuilder = UserCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(new UserCredential("myname", "secret"));
|
||||
}
|
||||
|
||||
@@ -42,7 +45,7 @@ public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
public void serializeWithUsernameAndPassword() throws Exception {
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "user");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.username", equalTo("myname")),
|
||||
hasJsonPath("$.value.password", equalTo("secret")),
|
||||
@@ -56,11 +59,12 @@ public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
UserCredentialRequestBuilder builder = UserCredentialRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.value(new UserCredential("secret"));
|
||||
|
||||
String jsonValue = serializeToJson(builder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "user");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.value.username"),
|
||||
hasJsonPath("$.value.password", equalTo("secret")),
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.password.PasswordParameters;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
@@ -29,6 +30,7 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasJsonPath;
|
||||
import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -40,6 +42,7 @@ public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
requestBuilder = UserParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.OVERWRITE)
|
||||
.username("user")
|
||||
.parameters(PasswordParameters.builder()
|
||||
.length(20)
|
||||
@@ -51,7 +54,7 @@ public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.OVERWRITE, "/example/credential", "user");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.username", equalTo("user")),
|
||||
hasJsonPath("$.parameters.length", equalTo(20)),
|
||||
@@ -66,11 +69,12 @@ public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
requestBuilder = UserParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.NO_OVERWRITE)
|
||||
.parameters(new PasswordParameters());
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.NO_OVERWRITE, "/example/credential", "user");
|
||||
assertParametersNotSet(jsonValue);
|
||||
}
|
||||
|
||||
@@ -78,11 +82,12 @@ public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
public void serializeWithNoParameters() throws Exception {
|
||||
requestBuilder = UserParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
.overwrite(true);
|
||||
.overwrite(true)
|
||||
.mode(WriteMode.CONVERGE);
|
||||
|
||||
String jsonValue = serializeToJson(requestBuilder);
|
||||
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertCommonRequestFields(jsonValue, true, WriteMode.CONVERGE, "/example/credential", "user");
|
||||
assertParametersNotSet(jsonValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user