use of org.cloudfoundry.credhub.entity.RequestAuditRecord in project credhub by cloudfoundry-incubator.
the class AuthConfigurationTest method dataEndpoint_withMutualTLS_logsOrgUnitFromTheDN.
@Test
public void dataEndpoint_withMutualTLS_logsOrgUnitFromTheDN() throws Exception {
setupDataEndpointMocks();
final MockHttpServletRequestBuilder post = post(dataApiPath).with(SecurityMockMvcRequestPostProcessors.x509(CertificateReader.getCertificate(CertificateStringConstants.SELF_SIGNED_CERT_WITH_CLIENT_AUTH_EXT))).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content("{\"type\":\"password\",\"name\":\"" + credentialName + "\"}");
mockMvc.perform(post).andExpect(status().isOk());
ArgumentCaptor<RequestAuditRecord> argumentCaptor = ArgumentCaptor.forClass(RequestAuditRecord.class);
verify(requestAuditRecordDataService, times(1)).save(argumentCaptor.capture());
RequestAuditRecord requestAuditRecord = argumentCaptor.getValue();
assertThat(requestAuditRecord.getClientId(), equalTo("C=US,ST=NY,O=Test Org,OU=app:a12345e5-b2b0-4648-a0d0-772d3d399dcb,CN=example.com,E=test@example.com"));
}
use of org.cloudfoundry.credhub.entity.RequestAuditRecord in project credhub by cloudfoundry-incubator.
the class SecurityEventsLogServiceTest method log_whenTheQueryParamStringIsNull_shouldSpecifyOnlyThePathInTheRequest.
@Test
public void log_whenTheQueryParamStringIsNull_shouldSpecifyOnlyThePathInTheRequest() {
RequestAuditRecord requestAuditRecord = makeOperationAuditRecord(null, AUTH_METHOD_UAA);
subject.log(new SecurityEventAuditRecord(requestAuditRecord, "actor-id"));
assertThat(fakeVersion, notNullValue());
assertThat(fakeVersion.length(), greaterThan(0));
verify(securityEventsLogger).info(contains("request=/api/some-path requestMethod=GET"));
}
use of org.cloudfoundry.credhub.entity.RequestAuditRecord in project credhub by cloudfoundry-incubator.
the class SecurityEventsLogServiceTest method log_shouldLogAnOperationAuditRecordToTheSysLogWhenUsingOAuth.
@Test
public void log_shouldLogAnOperationAuditRecordToTheSysLogWhenUsingOAuth() {
RequestAuditRecord requestAuditRecord = makeOperationAuditRecord("foo=bar", AUTH_METHOD_UAA);
subject.log(new SecurityEventAuditRecord(requestAuditRecord, "actor-id"));
verify(securityEventsLogger).info("CEF:0|cloud_foundry|credhub|" + fakeVersion + "|GET /api/some-path|" + "GET /api/some-path|0|rt=" + String.valueOf(now.toEpochMilli()) + " suser=user-name " + "suid=actor-id " + "cs1Label=userAuthenticationMechanism " + "cs1=oauth-access-token " + "request=/api/some-path?foo=bar " + "requestMethod=GET " + "cs3Label=result " + "cs3=success " + "cs4Label=httpStatusCode " + "cs4=200 " + "src=127.0.0.1 " + "dst=host.example.com");
}
use of org.cloudfoundry.credhub.entity.RequestAuditRecord in project credhub by cloudfoundry-incubator.
the class AuditTest method when_event_audit_record_save_fails_it_saves_request_audit_record.
@Test
public void when_event_audit_record_save_fails_it_saves_request_audit_record() throws Exception {
long initialRequestAuditCount = requestAuditRecordRepository.count();
long initialEventAuditCount = eventAuditRecordRepository.count();
String credentialName = "/TEST/SECRET";
String credentialType = "password";
doThrow(new RuntimeException("test exception")).when(eventAuditRecordDataService).save(any(List.class));
mockMvc.perform(post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + credentialName + "\"," + "\"type\":\"" + credentialType + "\"" + "}")).andExpect(status().isInternalServerError());
assertThat(requestAuditRecordRepository.count(), equalTo(initialRequestAuditCount + 1));
RequestAuditRecord requestAuditRecord = requestAuditRecordRepository.findAll(sortByDate).get(0);
assertThat(requestAuditRecord.getStatusCode(), equalTo(500));
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(logger, times(1)).info(captor.capture());
assertThat(captor.getValue(), containsString("cs4=500"));
}
Aggregations