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));
}
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"));
}
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"));
}
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: ");
}
};
}
Aggregations