Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix AuditCheckMockMvcTests with ldap profile #3206

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Kehrlann marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading