Search in sources :

Example 11 with EventAuditRecord

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);
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 12 with 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"));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with EventAuditRecord

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);
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with 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));
    }
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) Sort(org.springframework.data.domain.Sort)

Example 15 with EventAuditRecord

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()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

EventAuditRecord (org.cloudfoundry.credhub.entity.EventAuditRecord)19 Test (org.junit.Test)14 UUID (java.util.UUID)9 List (java.util.List)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 UserContext (org.cloudfoundry.credhub.auth.UserContext)6 RequestAuditRecord (org.cloudfoundry.credhub.entity.RequestAuditRecord)4 Sort (org.springframework.data.domain.Sort)4 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 Collectors (java.util.stream.Collectors)2 BaseMatcher (org.hamcrest.BaseMatcher)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Description (org.hamcrest.Description)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Function (java.util.function.Function)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)1 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 UserContextHolder (org.cloudfoundry.credhub.auth.UserContextHolder)1