use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method settingACredential_returnsTheExpectedResponse.
@Test
public void settingACredential_returnsTheExpectedResponse() throws Exception {
MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
ResultActions response = mockMvc.perform(request);
ArgumentCaptor<CredentialVersion> argumentCaptor = ArgumentCaptor.forClass(CredentialVersion.class);
verify(credentialVersionDataService, times(1)).save(argumentCaptor.capture());
response.andExpect(parametizer.jsonAssertions()).andExpect(multiJsonPath("$.type", parametizer.credentialType, "$.id", argumentCaptor.getValue().getUuid().toString(), "$.version_created_at", FROZEN_TIME.toString())).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method settingACredential_shouldAcceptAnyCasingForType.
@Test
public void settingACredential_shouldAcceptAnyCasingForType() throws Exception {
MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType.toUpperCase() + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
ResultActions response = mockMvc.perform(request);
ArgumentCaptor<CredentialVersion> argumentCaptor = ArgumentCaptor.forClass(CredentialVersion.class);
verify(credentialVersionDataService, times(1)).save(argumentCaptor.capture());
response.andExpect(status().isOk()).andExpect(parametizer.jsonAssertions()).andExpect(multiJsonPath("$.type", parametizer.credentialType, "$.id", argumentCaptor.getValue().getUuid().toString(), "$.version_created_at", FROZEN_TIME.toString())).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method settingACredential_expectsDataServiceToPersistTheCredential.
@Test
public void settingACredential_expectsDataServiceToPersistTheCredential() throws Exception {
MockHttpServletRequestBuilder request = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
ArgumentCaptor<CredentialVersion> argumentCaptor = ArgumentCaptor.forClass(CredentialVersion.class);
mockMvc.perform(request);
verify(setHandler, times(1)).handle(isA(BaseCredentialSetRequest.class), any());
verify(credentialVersionDataService, times(1)).save(argumentCaptor.capture());
CredentialVersion newCredentialVersion = argumentCaptor.getValue();
parametizer.credentialAssertions(newCredentialVersion);
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method parameters.
@Parameterized.Parameters(name = "{0}")
public static Collection<Object> parameters() {
UUID credentialUuid = UUID.randomUUID();
Collection<Object> params = new ArrayList<>();
TestParametizer valueParameters = new TestParametizer("value", "\"" + VALUE_VALUE + "\"") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", VALUE_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
assertThat(((ValueCredentialVersion) credential).getValue(), equalTo(VALUE_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new ValueCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setValue(VALUE_VALUE).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer passwordParameters = new TestParametizer("password", "\"" + PASSWORD_VALUE + "\"") {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", PASSWORD_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
assertThat(((PasswordCredentialVersion) credential).getPassword(), equalTo(PASSWORD_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new PasswordCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPasswordAndGenerationParameters(PASSWORD_VALUE, null).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer certificateParameters = new TestParametizer("certificate", CERTIFICATE_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.certificate", TestConstants.TEST_CERTIFICATE, "$.value.private_key", TestConstants.TEST_PRIVATE_KEY, "$.value.ca", TestConstants.TEST_CA);
}
void credentialAssertions(CredentialVersion credential) {
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credential;
assertThat(certificateCredential.getCa(), equalTo(TestConstants.TEST_CA));
assertThat(certificateCredential.getCertificate(), equalTo(TestConstants.TEST_CERTIFICATE));
assertThat(certificateCredential.getPrivateKey(), equalTo(TestConstants.TEST_PRIVATE_KEY));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new CertificateCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setCa(TestConstants.TEST_CA).setCertificate(TestConstants.TEST_CERTIFICATE).setPrivateKey(TestConstants.TEST_PRIVATE_KEY).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer sshParameters = new TestParametizer("ssh", SSH_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT, "$.value.private_key", TestConstants.PRIVATE_KEY_4096, "$.value.public_key_fingerprint", "UmqxK9UJJR4Jrcw0DcwqJlCgkeQoKp8a+HY+0p0nOgc");
}
void credentialAssertions(CredentialVersion credential) {
SshCredentialVersion sshCredential = (SshCredentialVersion) credential;
assertThat(sshCredential.getPublicKey(), equalTo(TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT));
assertThat(sshCredential.getPrivateKey(), equalTo(TestConstants.PRIVATE_KEY_4096));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new SshCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(TestConstants.PRIVATE_KEY_4096).setPublicKey(TestConstants.SSH_PUBLIC_KEY_4096_WITH_COMMENT).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer rsaParameters = new TestParametizer("rsa", RSA_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.public_key", TestConstants.RSA_PUBLIC_KEY_4096, "$.value.private_key", TestConstants.PRIVATE_KEY_4096);
}
void credentialAssertions(CredentialVersion credential) {
RsaCredentialVersion rsaCredential = (RsaCredentialVersion) credential;
assertThat(rsaCredential.getPublicKey(), equalTo(TestConstants.RSA_PUBLIC_KEY_4096));
assertThat(rsaCredential.getPrivateKey(), equalTo(TestConstants.PRIVATE_KEY_4096));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new RsaCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setPrivateKey(TestConstants.PRIVATE_KEY_4096).setPublicKey(TestConstants.RSA_PUBLIC_KEY_4096).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer jsonParameters = new TestParametizer("json", JSON_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value", jsonValueMap);
}
void credentialAssertions(CredentialVersion credential) {
JsonCredentialVersion jsonCredential = (JsonCredentialVersion) credential;
assertThat(jsonCredential.getValue(), equalTo(jsonValueMap));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new JsonCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setValue(jsonValueMap).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
TestParametizer userParameters = new TestParametizer("user", USER_VALUE_JSON_STRING) {
ResultMatcher jsonAssertions() {
return multiJsonPath("$.value.username", USERNAME_VALUE, "$.value.password", PASSWORD_VALUE);
}
void credentialAssertions(CredentialVersion credential) {
UserCredentialVersion userCredential = (UserCredentialVersion) credential;
assertThat(userCredential.getUsername(), equalTo(USERNAME_VALUE));
assertThat(userCredential.getPassword(), equalTo(PASSWORD_VALUE));
}
CredentialVersion createCredential(Encryptor encryptor) {
return new UserCredentialVersion(CREDENTIAL_NAME).setEncryptor(encryptor).setUsername(USERNAME_VALUE).setPassword(PASSWORD_VALUE).setUuid(credentialUuid).setVersionCreatedAt(FROZEN_TIME.minusSeconds(1));
}
};
params.add(valueParameters);
params.add(passwordParameters);
params.add(certificateParameters);
params.add(sshParameters);
params.add(rsaParameters);
params.add(jsonParameters);
params.add(userParameters);
return params;
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findActiveByName_whenAskedForCertificate_returnsTransitionalValueInAddition.
@Test
public void findActiveByName_whenAskedForCertificate_returnsTransitionalValueInAddition() throws Exception {
CertificateCredentialVersion certificate = saveCertificate(2000000000123L, "/some-certificate");
CertificateCredentialVersion version2 = saveTransitionalCertificate(2000000000123L, "/some-certificate");
CertificateCredentialVersion version3 = saveCertificate(2000000000229L, "/some-certificate");
List<CredentialVersion> credentialVersions = subject.findActiveByName("/some-certificate");
assertThat(credentialVersions.size(), equalTo(2));
assertThat(credentialVersions, containsInAnyOrder(hasProperty("uuid", equalTo(version2.getUuid())), hasProperty("uuid", equalTo(version3.getUuid()))));
}
Aggregations