From d470c68ed30d2db2aff27f58f6932dbc4a2aeca1 Mon Sep 17 00:00:00 2001 From: Daniel Garnier-Moiroux Date: Thu, 19 Dec 2024 22:18:55 +0100 Subject: [PATCH] fix AuditCheckMockMvcTests with LDAP profile --- .../uaa/mock/audit/AuditCheckMockMvcTests.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/audit/AuditCheckMockMvcTests.java b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/audit/AuditCheckMockMvcTests.java index 1985a241ee7..f0e6a719c84 100644 --- a/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/audit/AuditCheckMockMvcTests.java +++ b/uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/audit/AuditCheckMockMvcTests.java @@ -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; @@ -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()); @@ -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); @@ -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=")); @@ -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 matcher) { + assertThat(testListener.getEventCount(), matcher); + assertThat(testLogger.getMessageCount(), matcher); } private void assertSingleAuditEventFiredWith(AuditEventType expectedEventType, String[] expectedScopes, String[] expectedAuthorities) {