use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenAnExistingCredential_throwsExceptionIfTypeMismatch.
@Test(expected = ParameterizedValidationException.class)
public void save_givenAnExistingCredential_throwsExceptionIfTypeMismatch() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential-3");
passwordCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(credential);
ValueCredentialVersionData newCredentialData = new ValueCredentialVersionData();
newCredentialData.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("some value".getBytes()));
newCredentialData.setCredential(passwordCredentialData.getCredential());
ValueCredentialVersion newCredential = new ValueCredentialVersion(newCredentialData);
subject.save(newCredential);
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findAllPaths_returnsCompleteDirectoryStructure.
@Test
public void findAllPaths_returnsCompleteDirectoryStructure() {
String valueOther = "/fubario";
String valueName = "/value/Credential";
String passwordName = "/password/Credential";
String certificateName = "/certif/ic/ateCredential";
ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(valueOther);
ValueCredentialVersion valueCredential = new ValueCredentialVersion(valueCredentialData);
subject.save(valueCredential);
valueCredentialData = new ValueCredentialVersionData(valueName);
valueCredential = new ValueCredentialVersion(valueCredentialData);
subject.save(valueCredential);
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData(passwordName);
PasswordCredentialVersion passwordCredential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(passwordCredential);
CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData(certificateName);
CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
assertThat(subject.findAllPaths(), equalTo(newArrayList("/", "/certif/", "/certif/ic/", "/password/", "/value/")));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class AuthConfigurationTest method setupDataEndpointMocks.
private void setupDataEndpointMocks() {
when(credentialVersionDataService.save(any(CredentialVersion.class))).thenAnswer(invocation -> {
PasswordCredentialVersion passwordCredential = invocation.getArgumentAt(0, PasswordCredentialVersion.class);
passwordCredential.setUuid(UUID.randomUUID());
passwordCredential.setVersionCreatedAt(Instant.now());
return passwordCredential;
});
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerAuditLogTest method gettingACredential_byId_makesACredentialAccessAuditLogEntry.
@Test
public void gettingACredential_byId_makesACredentialAccessAuditLogEntry() throws Exception {
doReturn(new PasswordCredentialVersion("/foo").setEncryptor(encryptor)).when(credentialVersionDataService).findByUuid(eq("foo-id"));
mockMvc.perform(get(CredentialsController.API_V1_DATA + "/foo-id").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).header("X-Forwarded-For", "1.1.1.1,2.2.2.2"));
ArgumentCaptor<List> recordCaptor = ArgumentCaptor.forClass(List.class);
verify(eventAuditRecordDataService, times(1)).save(recordCaptor.capture());
EventAuditRecord auditRecord = (EventAuditRecord) recordCaptor.getValue().get(0);
assertThat(auditRecord.getCredentialName(), equalTo("/foo"));
assertThat(auditRecord.getOperation(), equalTo(CREDENTIAL_ACCESS.toString()));
}
use of org.cloudfoundry.credhub.domain.PasswordCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialsControllerAuditLogTest method gettingACredential_byName_makesACredentialAccessLogEntry.
@Test
public void gettingACredential_byName_makesACredentialAccessLogEntry() throws Exception {
doReturn(Arrays.asList(new PasswordCredentialVersion("/foo").setEncryptor(encryptor))).when(credentialVersionDataService).findAllByName(eq("foo"));
mockMvc.perform(get(CredentialsController.API_V1_DATA + "?name=foo").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).header("X-Forwarded-For", "1.1.1.1,2.2.2.2"));
ArgumentCaptor<List> recordCaptor = ArgumentCaptor.forClass(List.class);
verify(eventAuditRecordDataService, times(1)).save(recordCaptor.capture());
EventAuditRecord auditRecord = (EventAuditRecord) recordCaptor.getValue().get(0);
assertThat(auditRecord.getCredentialName(), equalTo("/foo"));
assertThat(auditRecord.getOperation(), equalTo(CREDENTIAL_ACCESS.toString()));
}
Aggregations