Skip to content

Commit

Permalink
Merge pull request #3206 from Kehrlann/dgarnier/fix-ldap-tests
Browse files Browse the repository at this point in the history
fix AuditCheckMockMvcTests with `ldap` profile
  • Loading branch information
duanemay authored Dec 19, 2024
2 parents d36838e + e05948b commit e814390
Showing 1 changed file with 13 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,8 @@ void invalidPasswordLoginUnsuccessfulTest() throws Exception {
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/login?error=login_failure"));

assertNumberOfAuditEventsReceived(3);
// When the profile is ldap, an extra event is emitted
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(3));

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

assertNumberOfAuditEventsReceived(3);
// When the profile is ldap, an extra event is emitted
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(3));

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

assertNumberOfAuditEventsReceived(2);
// When the profile is ldap, an extra event is emitted
assertNumberOfAuditEventsReceived(greaterThanOrEqualTo(2));

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

private void assertNumberOfAuditEventsReceived(int expectedEventCount) {
assertEquals(expectedEventCount, testListener.getEventCount());
assertEquals(expectedEventCount, testLogger.getMessageCount());
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 e814390

Please sign in to comment.