From 36805c7192770c031d8898055014f3180e571b5c Mon Sep 17 00:00:00 2001 From: Eleftheria Stein Date: Tue, 8 Jun 2021 10:13:53 +0300 Subject: [PATCH] Revert "Use strict equality for timestamp comparison in JDBC tests" This reverts commit 09a0670cb68032beacb399e0abe6d671967f3702. This appears to still be an issue in Windows Issue gh-8782 --- ...dbcOAuth2AuthorizedClientServiceTests.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientServiceTests.java b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientServiceTests.java index 1e9b850631c..cea664e1661 100644 --- a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientServiceTests.java +++ b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/JdbcOAuth2AuthorizedClientServiceTests.java @@ -22,6 +22,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; import java.util.Set; @@ -55,6 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.within; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.BDDMockito.given; @@ -174,14 +176,15 @@ public void loadAuthorizedClientWhenExistsThenReturnAuthorizedClient() { .isEqualTo(expected.getAccessToken().getTokenType()); assertThat(authorizedClient.getAccessToken().getTokenValue()) .isEqualTo(expected.getAccessToken().getTokenValue()); - assertThat(authorizedClient.getAccessToken().getIssuedAt()).isEqualTo(expected.getAccessToken().getIssuedAt()); - assertThat(authorizedClient.getAccessToken().getExpiresAt()) - .isEqualTo(expected.getAccessToken().getExpiresAt()); + assertThat(authorizedClient.getAccessToken().getIssuedAt()).isCloseTo(expected.getAccessToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); + assertThat(authorizedClient.getAccessToken().getExpiresAt()).isCloseTo(expected.getAccessToken().getExpiresAt(), + within(1, ChronoUnit.MILLIS)); assertThat(authorizedClient.getAccessToken().getScopes()).isEqualTo(expected.getAccessToken().getScopes()); assertThat(authorizedClient.getRefreshToken().getTokenValue()) .isEqualTo(expected.getRefreshToken().getTokenValue()); - assertThat(authorizedClient.getRefreshToken().getIssuedAt()) - .isEqualTo(expected.getRefreshToken().getIssuedAt()); + assertThat(authorizedClient.getRefreshToken().getIssuedAt()).isCloseTo(expected.getRefreshToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); } @Test @@ -228,14 +231,15 @@ public void saveAuthorizedClientWhenSaveThenLoadReturnsSaved() { .isEqualTo(expected.getAccessToken().getTokenType()); assertThat(authorizedClient.getAccessToken().getTokenValue()) .isEqualTo(expected.getAccessToken().getTokenValue()); - assertThat(authorizedClient.getAccessToken().getIssuedAt()).isEqualTo(expected.getAccessToken().getIssuedAt()); - assertThat(authorizedClient.getAccessToken().getExpiresAt()) - .isEqualTo(expected.getAccessToken().getExpiresAt()); + assertThat(authorizedClient.getAccessToken().getIssuedAt()).isCloseTo(expected.getAccessToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); + assertThat(authorizedClient.getAccessToken().getExpiresAt()).isCloseTo(expected.getAccessToken().getExpiresAt(), + within(1, ChronoUnit.MILLIS)); assertThat(authorizedClient.getAccessToken().getScopes()).isEqualTo(expected.getAccessToken().getScopes()); assertThat(authorizedClient.getRefreshToken().getTokenValue()) .isEqualTo(expected.getRefreshToken().getTokenValue()); - assertThat(authorizedClient.getRefreshToken().getIssuedAt()) - .isEqualTo(expected.getRefreshToken().getIssuedAt()); + assertThat(authorizedClient.getRefreshToken().getIssuedAt()).isCloseTo(expected.getRefreshToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); // Test save/load of NOT NULL attributes only principal = createPrincipal(); expected = createAuthorizedClient(principal, this.clientRegistration, true); @@ -249,9 +253,10 @@ public void saveAuthorizedClientWhenSaveThenLoadReturnsSaved() { .isEqualTo(expected.getAccessToken().getTokenType()); assertThat(authorizedClient.getAccessToken().getTokenValue()) .isEqualTo(expected.getAccessToken().getTokenValue()); - assertThat(authorizedClient.getAccessToken().getIssuedAt()).isEqualTo(expected.getAccessToken().getIssuedAt()); - assertThat(authorizedClient.getAccessToken().getExpiresAt()) - .isEqualTo(expected.getAccessToken().getExpiresAt()); + assertThat(authorizedClient.getAccessToken().getIssuedAt()).isCloseTo(expected.getAccessToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); + assertThat(authorizedClient.getAccessToken().getExpiresAt()).isCloseTo(expected.getAccessToken().getExpiresAt(), + within(1, ChronoUnit.MILLIS)); assertThat(authorizedClient.getAccessToken().getScopes()).isEmpty(); assertThat(authorizedClient.getRefreshToken()).isNull(); } @@ -275,14 +280,15 @@ public void saveAuthorizedClientWhenSaveClientWithExistingPrimaryKeyThenUpdate() .isEqualTo(updatedClient.getAccessToken().getTokenType()); assertThat(savedClient.getAccessToken().getTokenValue()) .isEqualTo(updatedClient.getAccessToken().getTokenValue()); - assertThat(savedClient.getAccessToken().getIssuedAt()).isEqualTo(updatedClient.getAccessToken().getIssuedAt()); - assertThat(savedClient.getAccessToken().getExpiresAt()) - .isEqualTo(updatedClient.getAccessToken().getExpiresAt()); + assertThat(savedClient.getAccessToken().getIssuedAt()).isCloseTo(updatedClient.getAccessToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); + assertThat(savedClient.getAccessToken().getExpiresAt()).isCloseTo(updatedClient.getAccessToken().getExpiresAt(), + within(1, ChronoUnit.MILLIS)); assertThat(savedClient.getAccessToken().getScopes()).isEqualTo(updatedClient.getAccessToken().getScopes()); assertThat(savedClient.getRefreshToken().getTokenValue()) .isEqualTo(updatedClient.getRefreshToken().getTokenValue()); - assertThat(savedClient.getRefreshToken().getIssuedAt()) - .isEqualTo(updatedClient.getRefreshToken().getIssuedAt()); + assertThat(savedClient.getRefreshToken().getIssuedAt()).isCloseTo(updatedClient.getRefreshToken().getIssuedAt(), + within(1, ChronoUnit.MILLIS)); } @Test