Search in sources :

Example 6 with EventAuditRecord

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

the class EventAuditRecordDataServiceTest method saveAll_givenAListOfRecords_savesTheRecords.

@Test
public void saveAll_givenAListOfRecords_savesTheRecords() {
    EventAuditRecord eventAuditRecord1 = new EventAuditRecord("credential_access", "/test/credential1", "test-actor1", requestAuditRecord.getUuid(), true, null, null);
    EventAuditRecord eventAuditRecord2 = new EventAuditRecord("credential_update", "/test/credential2", "test-actor2", requestAuditRecord.getUuid(), false, "credential_access", "ace-actor");
    subject.save(newArrayList(eventAuditRecord1, eventAuditRecord2));
    List<EventAuditRecord> records = eventAuditRecordRepository.findAll(new Sort(ASC, "credentialName"));
    assertThat(records, hasSize(2));
    EventAuditRecord actual1 = records.get(0);
    assertThat(actual1.getOperation(), equalTo("credential_access"));
    assertThat(actual1.getCredentialName(), equalTo("/test/credential1"));
    assertThat(actual1.getActor(), equalTo("test-actor1"));
    assertThat(actual1.getRequestUuid(), equalTo(requestAuditRecord.getUuid()));
    assertThat(actual1.isSuccess(), equalTo(true));
    assertThat(actual1.getUuid(), isA(UUID.class));
    assertThat(actual1.getNow(), equalTo(frozenTime));
    assertThat(actual1.getAceActor(), equalTo(null));
    assertThat(actual1.getAceOperation(), equalTo(null));
    EventAuditRecord actual2 = records.get(1);
    assertThat(actual2.getOperation(), equalTo("credential_update"));
    assertThat(actual2.getCredentialName(), equalTo("/test/credential2"));
    assertThat(actual2.getActor(), equalTo("test-actor2"));
    assertThat(actual2.getRequestUuid(), equalTo(requestAuditRecord.getUuid()));
    assertThat(actual2.isSuccess(), equalTo(false));
    assertThat(actual2.getUuid(), isA(UUID.class));
    assertThat(actual2.getNow(), equalTo(frozenTime));
    assertThat(actual2.getAceActor(), equalTo("ace-actor"));
    assertThat(actual2.getAceOperation(), equalTo("credential_access"));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) Sort(org.springframework.data.domain.Sort) UUID(java.util.UUID) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 7 with EventAuditRecord

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

the class CredentialsControllerAuditLogTest method gettingACredential_byId_makesACredentialAccessAuditLogEntry.

@Test
public void gettingACredential_byId_makesACredentialAccessAuditLogEntry() throws Exception {
    doReturn(new PasswordCredentialVersion("/foo").setEncryptor(encryptor)).when(credentialVersionDataService).findByUuid(eq("foo-id"));
    mockMvc.perform(get(CredentialsController.API_V1_DATA + "/foo-id").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"));
    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_ACCESS.toString()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) List(java.util.List) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with EventAuditRecord

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

the class CredentialsControllerAuditLogTest method gettingACredential_byName_makesACredentialAccessLogEntry.

@Test
public void gettingACredential_byName_makesACredentialAccessLogEntry() throws Exception {
    doReturn(Arrays.asList(new PasswordCredentialVersion("/foo").setEncryptor(encryptor))).when(credentialVersionDataService).findAllByName(eq("foo"));
    mockMvc.perform(get(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"));
    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_ACCESS.toString()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) List(java.util.List) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with EventAuditRecord

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

the class CredentialsControllerAuditLogTest method settingACredential_makesACredentialUpdateLogEntry.

@Test
public void settingACredential_makesACredentialUpdateLogEntry() throws Exception {
    when(credentialVersionDataService.save(any(CredentialVersion.class))).thenAnswer(invocation -> {
        ValueCredentialVersion valueCredential = invocation.getArgumentAt(0, ValueCredentialVersion.class);
        valueCredential.setEncryptor(encryptor);
        valueCredential.setUuid(UUID.randomUUID());
        return valueCredential;
    });
    MockHttpServletRequestBuilder set = MockMvcRequestBuilders.put(CredentialsController.API_V1_DATA).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").content("{\"type\":\"value\",\"name\":\"foo\",\"value\":\"credential\"}").with(request -> {
        request.setRemoteAddr("12346");
        return request;
    });
    mockMvc.perform(set).andExpect(status().isOk());
    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_UPDATE.toString()));
}
Also used : ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) List(java.util.List) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) ValueCredentialVersion(org.cloudfoundry.credhub.domain.ValueCredentialVersion) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 10 with EventAuditRecord

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

the class PermissionsControllerAuditLogTest method whenGettingAPermission_itLogsTheRetrieval.

@Test
public void whenGettingAPermission_itLogsTheRetrieval() throws Exception {
    final MockHttpServletRequestBuilder get = get("/api/v1/permissions?credential_name=" + CRED1.getName()).header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON);
    this.mockMvc.perform(get).andExpect(status().isOk());
    ArgumentCaptor<List> recordCaptor = ArgumentCaptor.forClass(List.class);
    verify(eventAuditRecordDataService).save(recordCaptor.capture());
    EventAuditRecord auditRecord = (EventAuditRecord) recordCaptor.getValue().get(0);
    assertThat(auditRecord.getCredentialName(), equalTo(CRED1.getName()));
    assertThat(auditRecord.getOperation(), equalTo(ACL_ACCESS.toString()));
}
Also used : EventAuditRecord(org.cloudfoundry.credhub.entity.EventAuditRecord) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) List(java.util.List) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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