Fix getByName. Add passwordHash field to UserCredential. Cleanup typing in unit tests.
This commit is contained in:
@@ -189,18 +189,18 @@ public class CredHubTemplate implements CredHubOperations {
|
||||
Assert.notNull(name, "credential name must not be null");
|
||||
Assert.notNull(credentialType, "credential type must not be null");
|
||||
|
||||
final ParameterizedTypeReference<CredentialDetails<T>> ref =
|
||||
new ParameterizedTypeReference<CredentialDetails<T>>() {};
|
||||
final ParameterizedTypeReference<CredentialDetailsData<T>> ref =
|
||||
new ParameterizedTypeReference<CredentialDetailsData<T>>() {};
|
||||
|
||||
return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
|
||||
@Override
|
||||
public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
|
||||
ResponseEntity<CredentialDetails<T>> response =
|
||||
ResponseEntity<CredentialDetailsData<T>> response =
|
||||
restOperations.exchange(NAME_URL_QUERY_CURRENT, GET, null, ref, name.getName());
|
||||
|
||||
throwExceptionOnError(response);
|
||||
|
||||
return response.getBody();
|
||||
return response.getBody().getData().get(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class CredentialDetailsData<T> {
|
||||
*
|
||||
* @param data a collection of {@link CredentialDetails}
|
||||
*/
|
||||
@SafeVarargs
|
||||
public CredentialDetailsData(CredentialDetails<T>... data) {
|
||||
this.data = Arrays.asList(data);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,15 @@ package org.springframework.credhub.support.user;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A user credential consists of an optional username and a password.
|
||||
* A user credential consists of an optional username and a password. When retrieved, a user credential
|
||||
* will contain a hash of the password.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public class UserCredential {
|
||||
private final String username;
|
||||
private final String password;
|
||||
private final String passwordHash;
|
||||
|
||||
/**
|
||||
* Create an empty {@link UserCredential}. Intended to be used internally for deserialization of responses.
|
||||
@@ -33,6 +35,7 @@ public class UserCredential {
|
||||
private UserCredential() {
|
||||
username = null;
|
||||
password = null;
|
||||
passwordHash = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +49,7 @@ public class UserCredential {
|
||||
Assert.notNull(password, "password must not be null");
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.passwordHash = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +61,7 @@ public class UserCredential {
|
||||
Assert.notNull(password, "password must not be null");
|
||||
this.username = null;
|
||||
this.password = password;
|
||||
this.passwordHash = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,4 +81,13 @@ public class UserCredential {
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SHA-512 hash of the user password.
|
||||
*
|
||||
* @return the hash of the user password
|
||||
*/
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public class CredHubTemplateDetailCertificateUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<CertificateCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<CertificateCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ public class CredHubTemplateDetailJsonUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<JsonCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<JsonCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,8 @@ public class CredHubTemplateDetailPasswordUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<PasswordCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<PasswordCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ public class CredHubTemplateDetailRsaUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<RsaCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<RsaCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ public class CredHubTemplateDetailSshUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<SshCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<SshCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,21 +64,21 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
|
||||
static <T> List<ResponseEntity<CredentialDetails<T>>> buildDetailResponses(CredentialType type, T credential) {
|
||||
return Arrays.asList(
|
||||
new ResponseEntity<CredentialDetails<T>>(
|
||||
new CredentialDetails<T>(CREDENTIAL_ID, NAME, type, credential),
|
||||
new ResponseEntity<>(
|
||||
new CredentialDetails<>(CREDENTIAL_ID, NAME, type, credential),
|
||||
OK),
|
||||
new ResponseEntity<CredentialDetails<T>>(new CredentialDetails<T>(), UNAUTHORIZED)
|
||||
new ResponseEntity<>(new CredentialDetails<T>(), UNAUTHORIZED)
|
||||
);
|
||||
}
|
||||
|
||||
static <T> List<ResponseEntity<CredentialDetailsData<T>>> buildDataResponses(CredentialType type, T credential) {
|
||||
return Arrays.asList(
|
||||
new ResponseEntity<CredentialDetailsData<T>>(
|
||||
new CredentialDetailsData<T>(
|
||||
new CredentialDetails<T>(CREDENTIAL_ID, NAME,
|
||||
new ResponseEntity<>(
|
||||
new CredentialDetailsData<>(
|
||||
new CredentialDetails<>(CREDENTIAL_ID, NAME,
|
||||
type, credential)),
|
||||
OK),
|
||||
new ResponseEntity<CredentialDetailsData<T>>(
|
||||
new ResponseEntity<>(
|
||||
new CredentialDetailsData<T>(), UNAUTHORIZED)
|
||||
);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
CredentialRequest<T> request = getWriteRequest();
|
||||
|
||||
when(restTemplate.exchange(eq(BASE_URL_PATH), eq(PUT),
|
||||
eq(new HttpEntity<CredentialRequest<T>>(request)), isA(ParameterizedTypeReference.class)))
|
||||
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
|
||||
.thenReturn(expectedResponse);
|
||||
|
||||
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
|
||||
@@ -102,7 +102,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
else {
|
||||
CredentialDetails<T> response = credHubTemplate.write(request);
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
ParametersRequest<P> request = getGenerateRequest();
|
||||
|
||||
when(restTemplate.exchange(eq(BASE_URL_PATH), eq(POST),
|
||||
eq(new HttpEntity<ParametersRequest<P>>(request)), isA(ParameterizedTypeReference.class)))
|
||||
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
|
||||
.thenReturn(expectedResponse);
|
||||
|
||||
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
|
||||
@@ -125,7 +125,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
else {
|
||||
CredentialDetails<T> response = credHubTemplate.generate(request);
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
}};
|
||||
|
||||
when(restTemplate.exchange(eq(REGENERATE_URL_PATH), eq(POST),
|
||||
eq(new HttpEntity<Map<String, Object>>(request)), isA(ParameterizedTypeReference.class)))
|
||||
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
|
||||
.thenReturn(expectedResponse);
|
||||
|
||||
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
|
||||
@@ -150,7 +150,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
else {
|
||||
CredentialDetails<T> response = credHubTemplate.regenerate(NAME);
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,12 +173,12 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
CredentialDetails<T> response =
|
||||
credHubTemplate.getById(CREDENTIAL_ID, getType());
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
void verifyGetByName(ResponseEntity<CredentialDetails<T>> expectedResponse) {
|
||||
void verifyGetByName(ResponseEntity<CredentialDetailsData<T>> expectedResponse) {
|
||||
when(restTemplate.exchange(eq(NAME_URL_QUERY_CURRENT), eq(GET), isNull(HttpEntity.class),
|
||||
isA(ParameterizedTypeReference.class), eq(NAME.getName())))
|
||||
.thenReturn(expectedResponse);
|
||||
@@ -196,7 +196,7 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
else {
|
||||
CredentialDetails<T> response = credHubTemplate.getByName(NAME, getType());
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDataResponseContainsExpectedCredential(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,11 +219,11 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
else {
|
||||
List<CredentialDetails<T>> response = credHubTemplate.getByNameWithHistory(NAME, getType());
|
||||
|
||||
assertResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
assertDataResponseContainsExpectedCredentials(expectedResponse, response);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertResponseContainsExpectedCredentials(
|
||||
private void assertDataResponseContainsExpectedCredentials(
|
||||
ResponseEntity<CredentialDetailsData<T>> expectedResponse,
|
||||
List<CredentialDetails<T>> response) {
|
||||
assertThat(response, notNullValue());
|
||||
@@ -231,7 +231,15 @@ public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubTe
|
||||
assertThat(response.get(0), equalTo(expectedResponse.getBody().getData().get(0)));
|
||||
}
|
||||
|
||||
private void assertResponseContainsExpectedCredentials(
|
||||
private void assertDataResponseContainsExpectedCredential(
|
||||
ResponseEntity<CredentialDetailsData<T>> expectedResponse,
|
||||
CredentialDetails<T> response) {
|
||||
assertThat(response, notNullValue());
|
||||
assertThat(1, equalTo(expectedResponse.getBody().getData().size()));
|
||||
assertThat(response, equalTo(expectedResponse.getBody().getData().get(0)));
|
||||
}
|
||||
|
||||
private void assertDetailsResponseContainsExpectedCredential(
|
||||
ResponseEntity<CredentialDetails<T>> expectedResponse,
|
||||
CredentialDetails<T> response) {
|
||||
assertThat(response, notNullValue());
|
||||
|
||||
@@ -73,8 +73,8 @@ public class CredHubTemplateDetailUserUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<UserCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<UserCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,8 @@ public class CredHubTemplateDetailValueUnitTests
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void getByName(@FromDataPoints("detail-responses")
|
||||
ResponseEntity<CredentialDetails<ValueCredential>> expectedResponse) {
|
||||
public void getByName(@FromDataPoints("data-responses")
|
||||
ResponseEntity<CredentialDetailsData<ValueCredential>> expectedResponse) {
|
||||
verifyGetByName(expectedResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ import static org.springframework.http.HttpStatus.UNAUTHORIZED;
|
||||
public class CredHubTemplateSummaryResponseUnitTests extends CredHubTemplateUnitTestsBase {
|
||||
@DataPoint("responses")
|
||||
public static ResponseEntity<CredentialSummaryData> successfulResponse =
|
||||
new ResponseEntity<CredentialSummaryData>(new CredentialSummaryData(new CredentialSummary(NAME)), OK);
|
||||
new ResponseEntity<>(new CredentialSummaryData(new CredentialSummary(NAME)), OK);
|
||||
|
||||
@DataPoint("responses")
|
||||
public static ResponseEntity<CredentialSummaryData> httpErrorResponse =
|
||||
new ResponseEntity<CredentialSummaryData>(new CredentialSummaryData(), UNAUTHORIZED);
|
||||
new ResponseEntity<>(new CredentialSummaryData(), UNAUTHORIZED);
|
||||
|
||||
@Theory
|
||||
public void findByName(@FromDataPoints("responses")
|
||||
|
||||
@@ -64,6 +64,7 @@ public abstract class CredHubRequestUnitTestsBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void serializationWithThreePermissions() throws Exception {
|
||||
requestBuilder
|
||||
.permission(CredentialPermission.builder()
|
||||
|
||||
@@ -54,13 +54,13 @@ public abstract class JsonParsingUnitTestsBase {
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> CredentialDetails<T> parseDetails(String credentials, Class<T> type) throws java.io.IOException {
|
||||
protected <T> CredentialDetails<T> parseDetails(String credentials) throws java.io.IOException {
|
||||
String json = buildDetails(credentials);
|
||||
return (CredentialDetails<T>) objectMapper.readValue(json, CredentialDetails.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> CredentialDetailsData<T> parseDetailsData(String credentials, Class<T> type) throws java.io.IOException {
|
||||
protected <T> CredentialDetailsData<T> parseDetailsData(String credentials) throws java.io.IOException {
|
||||
String json = buildDetailsData(credentials);
|
||||
return (CredentialDetailsData<T>) objectMapper.readValue(json, CredentialDetailsData.class);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class CertificateCredentialDetailsUnitTests extends JsonParsingUnitTestsB
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsWithAllValues() throws Exception {
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(CERT_CREDENTIALS, CertificateCredential.class);
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(CERT_CREDENTIALS);
|
||||
|
||||
assertDetails(data, "cert", "authority", "private-key");
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class CertificateCredentialDetailsUnitTests extends JsonParsingUnitTestsB
|
||||
" \"value\": {" +
|
||||
" \"certificate\": \"cert\"" +
|
||||
" }";
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(credentials, CertificateCredential.class);
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, "cert", null, null);
|
||||
}
|
||||
@@ -62,14 +62,14 @@ public class CertificateCredentialDetailsUnitTests extends JsonParsingUnitTestsB
|
||||
" \"ca\": \"authority\"," +
|
||||
" \"private_key\": \"private-key\"" +
|
||||
" }";
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(credentials, CertificateCredential.class);
|
||||
CredentialDetails<CertificateCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, null, "authority", "private-key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<CertificateCredential> response = parseDetailsData(CERT_CREDENTIALS, CertificateCredential.class);
|
||||
CredentialDetailsData<CertificateCredential> response = parseDetailsData(CERT_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void serializeWithParameters() throws Exception {
|
||||
requestBuilder = CertificateParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
@@ -75,6 +76,7 @@ public class CertificateParametersRequestUnitTests extends CredHubRequestUnitTes
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void serializeWithMinimalParameters() throws Exception {
|
||||
requestBuilder = CertificateParametersRequest.builder()
|
||||
.name(new SimpleCredentialName("example", "credential"))
|
||||
|
||||
@@ -38,14 +38,14 @@ public class JsonCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
|
||||
@Test
|
||||
public void deserializeDetails() throws Exception {
|
||||
CredentialDetails<JsonCredential> data = parseDetails(JSON_CREDENTIALS, JsonCredential.class);
|
||||
CredentialDetails<JsonCredential> data = parseDetails(JSON_CREDENTIALS);
|
||||
|
||||
assertDetails(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<JsonCredential> data = parseDetailsData(JSON_CREDENTIALS, JsonCredential.class);
|
||||
CredentialDetailsData<JsonCredential> data = parseDetailsData(JSON_CREDENTIALS);
|
||||
|
||||
assertThat(data.getData().size(), equalTo(1));
|
||||
assertDetails(data.getData().get(0));
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PasswordCredentialDetailsUnitTests extends JsonParsingUnitTestsBase
|
||||
@Test
|
||||
public void deserializeDetails() throws Exception {
|
||||
CredentialDetails<PasswordCredential> data =
|
||||
parseDetails(PASSWORD_CREDENTIALS, PasswordCredential.class);
|
||||
parseDetails(PASSWORD_CREDENTIALS);
|
||||
|
||||
assertDetails(data);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class PasswordCredentialDetailsUnitTests extends JsonParsingUnitTestsBase
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<PasswordCredential> response =
|
||||
parseDetailsData(PASSWORD_CREDENTIALS, PasswordCredential.class);
|
||||
parseDetailsData(PASSWORD_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RsaCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsWithPublicAndPrivateKeys() throws Exception {
|
||||
CredentialDetails<RsaCredential> data = parseDetails(RSA_CREDENTIALS, RsaCredential.class);
|
||||
CredentialDetails<RsaCredential> data = parseDetails(RSA_CREDENTIALS);
|
||||
|
||||
assertDetails(data, "public-key", "private-key");
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class RsaCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"value\": {" +
|
||||
" \"public_key\": \"public-key\"" +
|
||||
" }";
|
||||
CredentialDetails<RsaCredential> data = parseDetails(credentials, RsaCredential.class);
|
||||
CredentialDetails<RsaCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, "public-key", null);
|
||||
}
|
||||
@@ -60,14 +60,14 @@ public class RsaCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"value\": {" +
|
||||
" \"private_key\": \"private-key\"" +
|
||||
" }";
|
||||
CredentialDetails<RsaCredential> data = parseDetails(credentials, RsaCredential.class);
|
||||
CredentialDetails<RsaCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, null, "private-key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<RsaCredential> response = parseDetailsData(RSA_CREDENTIALS, RsaCredential.class);
|
||||
CredentialDetailsData<RsaCredential> response = parseDetailsData(RSA_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsWithPublicAndPrivateKeys() throws Exception {
|
||||
CredentialDetails<SshCredential> data = parseDetails(SSH_CREDENTIALS, SshCredential.class);
|
||||
CredentialDetails<SshCredential> data = parseDetails(SSH_CREDENTIALS);
|
||||
|
||||
assertDetails(data, "public-key", "private-key");
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"value\": {" +
|
||||
" \"public_key\": \"public-key\"" +
|
||||
" }";
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials, SshCredential.class);
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, "public-key", null);
|
||||
}
|
||||
@@ -60,14 +60,14 @@ public class SshCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"value\": {" +
|
||||
" \"private_key\": \"private-key\"" +
|
||||
" }";
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials, SshCredential.class);
|
||||
CredentialDetails<SshCredential> data = parseDetails(credentials);
|
||||
|
||||
assertDetails(data, null, "private-key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<SshCredential> response = parseDetailsData(SSH_CREDENTIALS, SshCredential.class);
|
||||
CredentialDetailsData<SshCredential> response = parseDetailsData(SSH_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
|
||||
@@ -31,19 +31,20 @@ public class UserCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
" \"type\": \"user\"," +
|
||||
" \"value\": {" +
|
||||
" \"username\": \"myname\"," +
|
||||
" \"password\": \"secret\"" +
|
||||
" \"password\": \"secret\"," +
|
||||
" \"password_hash\": \"secret-hash\"" +
|
||||
" }";
|
||||
|
||||
@Test
|
||||
public void deserializeDetails() throws Exception {
|
||||
CredentialDetails<UserCredential> data = parseDetails(USER_CREDENTIALS, UserCredential.class);
|
||||
CredentialDetails<UserCredential> data = parseDetails(USER_CREDENTIALS);
|
||||
|
||||
assertDetails(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<UserCredential> response = parseDetailsData(USER_CREDENTIALS, UserCredential.class);
|
||||
CredentialDetailsData<UserCredential> response = parseDetailsData(USER_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
@@ -58,5 +59,6 @@ public class UserCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
assertThat(data.getCredentialType(), equalTo(CredentialType.USER));
|
||||
assertThat(data.getValue().getUsername(), equalTo("myname"));
|
||||
assertThat(data.getValue().getPassword(), equalTo("secret"));
|
||||
assertThat(data.getValue().getPasswordHash(), equalTo("secret-hash"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasJsonPath("$.value.username", equalTo("myname")),
|
||||
hasJsonPath("$.value.password", equalTo("secret"))));
|
||||
hasJsonPath("$.value.password", equalTo("secret")),
|
||||
hasNoJsonPath("$.value.password_hash")));
|
||||
|
||||
assertNoPermissions(jsonValue);
|
||||
}
|
||||
@@ -62,7 +63,8 @@ public class UserCredentialRequestUnitTests extends CredHubRequestUnitTestsBase
|
||||
assertCommonRequestFields(jsonValue, true, "/example/credential", "user");
|
||||
assertThat(jsonValue,
|
||||
allOf(hasNoJsonPath("$.value.username"),
|
||||
hasJsonPath("$.value.password", equalTo("secret"))));
|
||||
hasJsonPath("$.value.password", equalTo("secret")),
|
||||
hasNoJsonPath("$.value.password_hash")));
|
||||
|
||||
assertNoPermissions(jsonValue);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.valid4j.matchers.jsonpath.JsonPathMatchers.hasNoJsonPath;
|
||||
public class UserParametersRequestUnitTests extends CredHubRequestUnitTestsBase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
requestBuilder = new UserParametersRequest().builder();
|
||||
requestBuilder = UserParametersRequest.builder();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ValueCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
@Test
|
||||
public void deserializeDetails() throws Exception {
|
||||
CredentialDetails<ValueCredential> data =
|
||||
parseDetails(VALUE_CREDENTIALS, ValueCredential.class);
|
||||
parseDetails(VALUE_CREDENTIALS);
|
||||
|
||||
assertDetails(data);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class ValueCredentialDetailsUnitTests extends JsonParsingUnitTestsBase {
|
||||
@Test
|
||||
public void deserializeDetailsData() throws Exception {
|
||||
CredentialDetailsData<ValueCredential> response =
|
||||
parseDetailsData(VALUE_CREDENTIALS, ValueCredential.class);
|
||||
parseDetailsData(VALUE_CREDENTIALS);
|
||||
|
||||
assertThat(response.getData().size(), equalTo(1));
|
||||
|
||||
|
||||
@@ -3,4 +3,6 @@ applications:
|
||||
- name: spring-credhub-demo
|
||||
memory: 1G
|
||||
path: build/libs/spring-credhub-demo.jar
|
||||
env:
|
||||
SPRING_CREDHUB_URL: https://credhub.service.cf.internal:8844
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.credhub.core.CredHubTemplate;
|
||||
import org.springframework.credhub.core.CredHubOperations;
|
||||
import org.springframework.credhub.support.permissions.Actor;
|
||||
import org.springframework.credhub.support.permissions.CredentialPermission;
|
||||
import org.springframework.credhub.support.CredentialDetails;
|
||||
@@ -49,9 +49,9 @@ public class CredHubDemoController {
|
||||
private static final String APP_GUID_1 = UUID.randomUUID().toString();
|
||||
private static final String APP_GUID_2 = UUID.randomUUID().toString();
|
||||
|
||||
private CredHubTemplate credHubTemplate;
|
||||
private CredHubOperations credHubTemplate;
|
||||
|
||||
public CredHubDemoController(CredHubTemplate credHubTemplate) {
|
||||
public CredHubDemoController(CredHubOperations credHubTemplate) {
|
||||
this.credHubTemplate = credHubTemplate;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user