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