Skip to content

Commit

Permalink
fix AuditCheckMockMvcTests with LDAP profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kehrlann committed Dec 19, 2024
1 parent d36838e commit d470c68
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
Expand Down Expand Up @@ -325,7 +326,7 @@ void invalidPasswordLoginUnsuccessfulTest() throws Exception {
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/login?error=login_failure"));

assertNumberOfAuditEventsReceived(3);
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(3));

IdentityProviderAuthenticationFailureEvent idpAuthFailEvent = (IdentityProviderAuthenticationFailureEvent) testListener.getEvents().get(0);
assertEquals(testUser.getUserName(), idpAuthFailEvent.getUsername());
Expand Down Expand Up @@ -452,7 +453,7 @@ void invalidPasswordLoginAuthenticateEndpointTest() throws Exception {
.andExpect(status().isUnauthorized())
.andExpect(content().string("{\"error\":\"authentication failed\"}"));

assertNumberOfAuditEventsReceived(3);
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(3));

IdentityProviderAuthenticationFailureEvent event1 = (IdentityProviderAuthenticationFailureEvent) testListener.getEvents().get(0);
UserAuthenticationFailureEvent event2 = (UserAuthenticationFailureEvent) testListener.getEvents().get(1);
Expand Down Expand Up @@ -519,7 +520,7 @@ void userNotFoundLoginUnsuccessfulTest() throws Exception {
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/login?error=login_failure"));

assertNumberOfAuditEventsReceived(2);
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(2));

UserNotFoundEvent event1 = (UserNotFoundEvent) testListener.getEvents().get(0);
assertTrue(event1.getAuditEvent().getOrigin().contains("sessionId=<SESSION>"));
Expand Down Expand Up @@ -1370,8 +1371,13 @@ private void resetAuditTestReceivers() {
}

private void assertNumberOfAuditEventsReceived(int expectedEventCount) {
assertEquals(expectedEventCount, testListener.getEventCount());
assertEquals(expectedEventCount, testLogger.getMessageCount());
assertNumberOfAuditEventsReceived(equalTo(expectedEventCount));
assertNumberOfAuditEventsReceived(equalTo(expectedEventCount));
}

private void assertNumberOfAuditEventsReceived(org.hamcrest.Matcher<Integer> matcher) {
assertThat(testListener.getEventCount(), matcher);
assertThat(testLogger.getMessageCount(), matcher);
}

private void assertSingleAuditEventFiredWith(AuditEventType expectedEventType, String[] expectedScopes, String[] expectedAuthorities) {
Expand Down

0 comments on commit d470c68

Please sign in to comment.