use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenParametersAreNull_createsEventAuditRecord.
@Test
public void createEventAuditRecord_whenParametersAreNull_createsEventAuditRecord() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
when(userContext.getActor()).thenReturn("test-actor");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(null, userContext, requestUuid, true);
assertNotNull(eventAuditRecord);
}
use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenCredentialNameIsMissingLeadingSlash_prependsLeadingSlash.
@Test
public void createEventAuditRecord_whenCredentialNameIsMissingLeadingSlash_prependsLeadingSlash() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
eventAuditRecordParameters.setCredentialName("test-credential");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
assertThat(eventAuditRecord.getCredentialName(), equalTo("/test-credential"));
}
use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.
the class AuditLogFactoryTest method createEventAuditRecord_whenCredentialNameIsNull_createsEventAuditRecord.
@Test
public void createEventAuditRecord_whenCredentialNameIsNull_createsEventAuditRecord() {
final UserContext userContext = mock(UserContext.class);
final UUID requestUuid = UUID.randomUUID();
final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
eventAuditRecordParameters.setAuditingOperationCode(CREDENTIAL_UPDATE);
when(userContext.getActor()).thenReturn("test-actor");
EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
assertNotNull(eventAuditRecord);
}
use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.
the class EventAuditLogServiceTest method checkAuditRecords.
private void checkAuditRecords(List<EventAuditRecordParameters> eventAuditRecordParameters, boolean successFlag) {
final int expectedNumRecords = eventAuditRecordParameters.size();
final List<EventAuditRecord> eventAuditRecords = eventAuditRecordRepository.findAll(new Sort(ASC, "credentialName"));
assertThat(eventAuditRecords, hasSize(expectedNumRecords));
eventAuditRecordParameters.sort(Comparator.comparing(EventAuditRecordParameters::getCredentialName));
for (int i = 0; i < expectedNumRecords; i++) {
final EventAuditRecordParameters parameters = eventAuditRecordParameters.get(i);
final EventAuditRecord eventAuditRecord = eventAuditRecords.get(i);
assertThat(eventAuditRecord.getCredentialName(), equalTo(parameters.getCredentialName()));
assertThat(eventAuditRecord.getOperation(), equalTo(parameters.getAuditingOperationCode().toString()));
assertThat(eventAuditRecord.getActor(), equalTo("test-actor"));
assertThat(eventAuditRecord.isSuccess(), equalTo(successFlag));
assertThat(eventAuditRecord.getRequestUuid(), equalTo(requestUuid.getUuid()));
assertThat(eventAuditRecord.getRequestUuid(), notNullValue());
assertThat(eventAuditRecord.getNow(), equalTo(this.now));
}
}
use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.
the class CredentialsControllerAuditLogTest method deletingACredential_makesACredentialDeleteLogEntry.
@Test
public void deletingACredential_makesACredentialDeleteLogEntry() throws Exception {
MockHttpServletRequestBuilder deleteRequest = delete(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").with(request -> {
request.setRemoteAddr("12345");
return request;
});
mockMvc.perform(deleteRequest).andExpect(status().is4xxClientError());
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_DELETE.toString()));
}
Aggregations