Search in sources :

Example 16 with RequestAuditRecord

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

Example 17 with RequestAuditRecord

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"));
}
Also used : SecurityEventAuditRecord(org.cloudfoundry.credhub.domain.SecurityEventAuditRecord) RequestAuditRecord(org.cloudfoundry.credhub.entity.RequestAuditRecord) Test(org.junit.Test)

Example 18 with RequestAuditRecord

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");
}
Also used : SecurityEventAuditRecord(org.cloudfoundry.credhub.domain.SecurityEventAuditRecord) RequestAuditRecord(org.cloudfoundry.credhub.entity.RequestAuditRecord) Test(org.junit.Test)

Example 19 with RequestAuditRecord

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"));
}
Also used : RequestAuditRecord(org.cloudfoundry.credhub.entity.RequestAuditRecord) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

RequestAuditRecord (org.cloudfoundry.credhub.entity.RequestAuditRecord)19 Test (org.junit.Test)13 SecurityEventAuditRecord (org.cloudfoundry.credhub.domain.SecurityEventAuditRecord)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 EventAuditRecord (org.cloudfoundry.credhub.entity.EventAuditRecord)4 Sort (org.springframework.data.domain.Sort)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 List (java.util.List)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 Principal (java.security.Principal)1 Collections.emptyList (java.util.Collections.emptyList)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)1 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 UserContext (org.cloudfoundry.credhub.auth.UserContext)1 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)1