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