Search in sources :

Example 16 with EventAuditRecord

use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.

the class AuditLogFactoryTest method createEventAuditRecord_whenParameterAceOperationIsNull_createsEventAuditRecord.

@Test
public void createEventAuditRecord_whenParameterAceOperationIsNull_createsEventAuditRecord() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
    eventAuditRecordParameters.setCredentialName("/test-credential");
    when(userContext.getActor()).thenReturn("test-actor");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
    assertThat(eventAuditRecord.getAceOperation(), equalTo(null));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 17 with EventAuditRecord

use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.

the class AuditLogFactoryTest method createEventAuditRecord_whenAllFieldsAreComplete_createsEventAuditRecord.

@Test
public void createEventAuditRecord_whenAllFieldsAreComplete_createsEventAuditRecord() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
    eventAuditRecordParameters.setAuditingOperationCode(CREDENTIAL_ACCESS);
    eventAuditRecordParameters.setCredentialName("/test-credential");
    eventAuditRecordParameters.setAceOperation(WRITE_ACL);
    eventAuditRecordParameters.setAceActor("ace-actor");
    when(userContext.getActor()).thenReturn("test-actor");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
    assertThat(eventAuditRecord.getOperation(), equalTo("credential_access"));
    assertThat(eventAuditRecord.getCredentialName(), equalTo("/test-credential"));
    assertThat(eventAuditRecord.getActor(), equalTo("test-actor"));
    assertThat(eventAuditRecord.getRequestUuid(), equalTo(requestUuid));
    assertThat(eventAuditRecord.isSuccess(), equalTo(true));
    assertThat(eventAuditRecord.getAceOperation(), equalTo("write_acl"));
    assertThat(eventAuditRecord.getAceActor(), equalTo("ace-actor"));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with EventAuditRecord

use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.

the class AuditLogFactoryTest method createEventAuditRecord_whenOperationIsNull_fallsBackToUnknownOperation.

@Test
public void createEventAuditRecord_whenOperationIsNull_fallsBackToUnknownOperation() {
    final UserContext userContext = mock(UserContext.class);
    final UUID requestUuid = UUID.randomUUID();
    final EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters();
    eventAuditRecordParameters.setCredentialName("/test-credential");
    when(userContext.getActor()).thenReturn("test-actor");
    EventAuditRecord eventAuditRecord = AuditLogFactory.createEventAuditRecord(eventAuditRecordParameters, userContext, requestUuid, true);
    assertThat(eventAuditRecord.getOperation(), equalTo("unknown_operation"));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) UserContext(org.cloudfoundry.credhub.auth.UserContext) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with EventAuditRecord

use of org.cloudfoundry.credhub.entity.EventAuditRecord in project credhub by cloudfoundry-incubator.

the class AuditingHelper method matchesExpectedEvent.

private static Matcher<EventAuditRecord> matchesExpectedEvent(EventAuditRecordParameters parameters, String actor, boolean expectedSuccess, UUID requestUuid) {
    return new BaseMatcher<EventAuditRecord>() {

        @Override
        public boolean matches(Object item) {
            final EventAuditRecord actual = (EventAuditRecord) item;
            final String expectedAceOperation = parameters.getAceOperation() == null ? null : parameters.getAceOperation().getOperation();
            return StringUtils.equals(actual.getOperation(), parameters.getAuditingOperationCode().toString()) && StringUtils.equals(actual.getCredentialName(), parameters.getCredentialName()) && StringUtils.equals(actual.getAceOperation(), expectedAceOperation) && StringUtils.equals(actual.getAceActor(), parameters.getAceActor()) && StringUtils.equals(actual.getActor(), actor) && actual.isSuccess() == expectedSuccess && actual.getRequestUuid().equals(requestUuid);
        }

        @Override
        public void describeTo(Description message) {
            message.appendText("Expected audit parameters did not match actual audit parameters: ");
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord)

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