use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class ClientAdminEndpointsMockMvcTests method testDeleteClientsTxSuccess.
@Test
void testDeleteClientsTxSuccess() throws Exception {
int count = 5;
BaseClientDetails[] details = new BaseClientDetails[count];
for (int i = 0; i < details.length; i++) {
details[i] = (BaseClientDetails) createClient(adminToken, null, SECRET, null);
}
MockHttpServletRequestBuilder deleteClientsPost = post("/oauth/clients/tx/delete").header("Authorization", "Bearer " + adminToken).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(details));
ResultActions result = mockMvc.perform(deleteClientsPost);
result.andExpect(status().isOk());
for (ClientDetails client : details) {
assertNull(getClient(client.getClientId()));
}
// create and then update events
verify(mockApplicationEventPublisher, times(count * 2)).publishEvent(abstractUaaEventCaptor.capture());
int index = 0;
for (AbstractUaaEvent event : abstractUaaEventCaptor.getAllValues()) {
if (index < count) {
assertEquals(AuditEventType.ClientCreateSuccess, event.getAuditEvent().getType());
} else {
assertEquals(AuditEventType.ClientDeleteSuccess, event.getAuditEvent().getType());
}
index++;
}
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class ClientAdminEndpointsMockMvcTests method testSecretChangeModifyTxApprovalsDeleted.
@Test
void testSecretChangeModifyTxApprovalsDeleted() throws Exception {
int count = 3;
// create clients
ClientDetailsModification[] clients = createBaseClients(count, SECRET, Arrays.asList("client_credentials", "password"));
for (ClientDetailsModification c : clients) {
c.setAction(ClientDetailsModification.ADD);
}
MockHttpServletRequestBuilder modifyClientsPost = post("/oauth/clients/tx/modify").header("Authorization", "Bearer " + adminToken).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(clients));
ResultActions result = mockMvc.perform(modifyClientsPost);
result.andExpect(status().isOk());
clients = (ClientDetailsModification[]) arrayFromString(result.andReturn().getResponse().getContentAsString(), ClientDetailsModification[].class);
// add approvals to the client
for (ClientDetailsModification c : clients) {
String userToken = testClient.getUserOAuthAccessToken(c.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
addApprovals(userToken, c.getClientId());
}
// verify approvals to the client
for (ClientDetailsModification c : clients) {
String userToken = testClient.getUserOAuthAccessToken(c.getClientId(), "secret", testUser.getUserName(), testPassword, "oauth.approvals");
assertEquals(3, getApprovals(c.getClientId()).length);
}
// change the secret, and we know don't the old secret
for (ClientDetailsModification c : clients) {
c.setClientSecret("secret2");
c.setAction(ClientDetailsModification.UPDATE_SECRET);
}
modifyClientsPost = post("/oauth/clients/tx/modify").header("Authorization", "Bearer " + adminToken).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(clients));
result = mockMvc.perform(modifyClientsPost);
result.andExpect(status().isOk());
clients = (ClientDetailsModification[]) arrayFromString(result.andReturn().getResponse().getContentAsString(), ClientDetailsModification[].class);
// check that we deleted approvals for each client
for (ClientDetailsModification c : clients) {
String userToken = testClient.getUserOAuthAccessToken(c.getClientId(), "secret2", testUser.getUserName(), testPassword, "oauth.approvals");
assertEquals(0, getApprovals(c.getClientId()).length);
assertTrue(c.isApprovalsDeleted());
}
// verify(mockApplicationEventPublisher, times(count*3)).publishEvent(abstractUaaEventCaptor.capture());
verify(mockApplicationEventPublisher, times(12)).publishEvent(abstractUaaEventCaptor.capture());
int index = 0;
for (AbstractUaaEvent event : abstractUaaEventCaptor.getAllValues()) {
if (index < count) {
assertEquals(AuditEventType.ClientCreateSuccess, event.getAuditEvent().getType());
} else {
int swit = index % 3;
if (swit == 0) {
assertEquals(AuditEventType.ClientUpdateSuccess, event.getAuditEvent().getType());
} else if (swit == 1) {
assertEquals(AuditEventType.SecretChangeSuccess, event.getAuditEvent().getType());
} else {
assertEquals(AuditEventType.ClientApprovalsDeleted, event.getAuditEvent().getType());
assertEquals(ClientApprovalsDeletedEvent.class, event.getClass());
}
}
index++;
}
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class TotpMfaEndpointMockMvcTests method testGoogleAuthenticatorLoginFlow.
@Test
void testGoogleAuthenticatorLoginFlow() throws Exception {
redirectToMFARegistration(mockMvc, mockHttpSession, scimUser, password);
performGetMfaRegister(mockMvc, mockHttpSession).andDo(print()).andExpect(view().name("mfa/qr_code"));
assertFalse(userGoogleMfaCredentialsProvisioning.activeUserCredentialExists(scimUser.getId(), mfaProvider.getId()));
int code = MockMvcUtils.getMFACodeFromSession(mockHttpSession);
String location = MockMvcUtils.performMfaPostVerifyWithCode(code, mockMvc, mockHttpSession);
ArgumentCaptor<AbstractUaaEvent> eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(9, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(7), instanceOf(MfaAuthenticationSuccessEvent.class));
mockMvc.perform(get(location).session(mockHttpSession)).andExpect(status().isFound()).andExpect(redirectedUrl("http://localhost/"));
mockHttpSession = new MockHttpSession();
performLoginWithSession(mockMvc, mockHttpSession, scimUser, password);
MockMvcUtils.performMfaPostVerifyWithCode(code, mockMvc, mockHttpSession);
eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(15, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(13), instanceOf(MfaAuthenticationSuccessEvent.class));
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class TotpMfaEndpointMockMvcTests method testOtpValidationFails.
@Test
void testOtpValidationFails() throws Exception {
redirectToMFARegistration(mockMvc, mockHttpSession, scimUser, password);
assertFalse(userGoogleMfaCredentialsProvisioning.activeUserCredentialExists(scimUser.getId(), mfaProvider.getId()));
performGetMfaManualRegister(mockMvc, mockHttpSession).andExpect((view().name("mfa/manual_registration")));
int code = MockMvcUtils.getMFACodeFromSession(mockHttpSession);
String location = MockMvcUtils.performMfaPostVerifyWithCode(code, mockMvc, mockHttpSession);
assertEquals("/login/mfa/completed", location);
ArgumentCaptor<AbstractUaaEvent> eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(9, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(7), instanceOf(MfaAuthenticationSuccessEvent.class));
mockMvc.perform(get("/").session(mockHttpSession)).andExpect(status().isOk()).andExpect(view().name("home"));
mockMvc.perform(get("/logout.do")).andReturn();
mockHttpSession = new MockHttpSession();
performLoginWithSession(mockMvc, mockHttpSession, scimUser, password);
mockMvc.perform(post("/login/mfa/verify.do").param("code", Integer.toString(code + 1)).header("Host", "localhost").session(mockHttpSession).with(cookieCsrf())).andExpect(status().is2xxSuccessful()).andExpect(view().name("mfa/enter_code"));
eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(15, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(13), instanceOf(MfaAuthenticationFailureEvent.class));
mockMvc.perform(post("/login/mfa/verify.do").param("code", "ABCDEF").header("Host", "localhost").session(mockHttpSession).with(cookieCsrf())).andExpect(status().is2xxSuccessful()).andExpect(view().name("mfa/enter_code"));
eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(17, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(15), instanceOf(MfaAuthenticationFailureEvent.class));
}
use of org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent in project uaa by cloudfoundry.
the class TotpMfaEndpointMockMvcTests method testManualRegistrationFlow.
@Test
void testManualRegistrationFlow() throws Exception {
redirectToMFARegistration(mockMvc, mockHttpSession, scimUser, password);
assertFalse(userGoogleMfaCredentialsProvisioning.activeUserCredentialExists(scimUser.getId(), mfaProvider.getId()));
performGetMfaManualRegister(mockMvc, mockHttpSession).andExpect((view().name("mfa/manual_registration")));
int code = MockMvcUtils.getMFACodeFromSession(mockHttpSession);
String location = MockMvcUtils.performMfaPostVerifyWithCode(code, mockMvc, mockHttpSession);
assertEquals("/login/mfa/completed", location);
ArgumentCaptor<AbstractUaaEvent> eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(9, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(7), instanceOf(MfaAuthenticationSuccessEvent.class));
mockMvc.perform(get("/").session(mockHttpSession)).andExpect(status().isOk()).andExpect(view().name("home"));
mockMvc.perform(get("/logout.do")).andReturn();
mockHttpSession = new MockHttpSession();
performLoginWithSession(mockMvc, mockHttpSession, scimUser, password);
MockMvcUtils.performMfaPostVerifyWithCode(code, mockMvc, mockHttpSession);
eventCaptor = ArgumentCaptor.forClass(AbstractUaaEvent.class);
verify(applicationListener, atLeast(1)).onApplicationEvent(eventCaptor.capture());
assertEquals(16, eventCaptor.getAllValues().size());
assertThat(eventCaptor.getAllValues().get(14), instanceOf(MfaAuthenticationSuccessEvent.class));
}
Aggregations