From 7c98a39770c7664716ca68b14e88c9a7d0afa1fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 03:41:21 +0000 Subject: [PATCH 1/3] Bump org.springframework:spring-framework-bom from 5.3.30 to 5.3.31 Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 5.3.30 to 5.3.31. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.30...v5.3.31) --- updated-dependencies: - dependency-name: org.springframework:spring-framework-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7795eb2343..7f58ea4f6e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ org-mockito = "4.8.1" org-opensaml4 = "4.1.0" org-opensaml3 = "3.4.6" org-slf4j = "1.7.36" -org-springframework = "5.3.30" +org-springframework = "5.3.31" [libraries] ch-qos-logback-logback-classic = "ch.qos.logback:logback-classic:1.2.12" From 382cfd63ed4ff6f28bcd7ae5324c94c8c0a1cd4c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 03:41:11 +0000 Subject: [PATCH 2/3] Bump io-spring-javaformat from 0.0.39 to 0.0.40 Bumps `io-spring-javaformat` from 0.0.39 to 0.0.40. Updates `io.spring.javaformat:spring-javaformat-checkstyle` from 0.0.39 to 0.0.40 - [Release notes](https://github.com/spring-io/spring-javaformat/releases) - [Commits](https://github.com/spring-io/spring-javaformat/compare/v0.0.39...v0.0.40) Updates `io.spring.javaformat:spring-javaformat-gradle-plugin` from 0.0.39 to 0.0.40 - [Release notes](https://github.com/spring-io/spring-javaformat/releases) - [Commits](https://github.com/spring-io/spring-javaformat/compare/v0.0.39...v0.0.40) --- updated-dependencies: - dependency-name: io.spring.javaformat:spring-javaformat-checkstyle dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.spring.javaformat:spring-javaformat-gradle-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7f58ea4f6e..0786192cd9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ com-squareup-okhttp3 = "3.14.9" io-r2dbc = "0.9.1.RELEASE" io-rsocket = "1.1.4" -io-spring-javaformat = "0.0.39" +io-spring-javaformat = "0.0.40" io-spring-nohttp = "0.0.11" org-apache-directory-server = "1.5.5" org-aspectj = "1.9.20.1" From a7da9491d9325941526ea3811993b6dc26f7b821 Mon Sep 17 00:00:00 2001 From: Marcus Hert Da Coregio Date: Fri, 17 Nov 2023 08:27:19 -0300 Subject: [PATCH 3/3] Use assertj assertions --- .../saml2/Saml2LoginConfigurerTests.java | 3 +- .../RunAsImplAuthenticationProviderTests.java | 3 +- ...stleAesBytesEncryptorEquivalencyTests.java | 13 +- .../BouncyCastleAesBytesEncryptorTests.java | 8 +- ...uth2AccessTokenResponseConverterTests.java | 111 +++++++++--------- ...2AccessTokenResponseMapConverterTests.java | 43 +++---- ...SamlAuthenticationRequestFactoryTests.java | 7 +- ...aml4AuthenticationRequestFactoryTests.java | 5 +- .../Saml2WebSsoAuthenticationFilterTests.java | 8 +- 9 files changed, 99 insertions(+), 102 deletions(-) diff --git a/config/src/test/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurerTests.java b/config/src/test/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurerTests.java index 3940428ae8..e4a2cff213 100644 --- a/config/src/test/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurerTests.java +++ b/config/src/test/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurerTests.java @@ -29,7 +29,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -461,7 +460,7 @@ public class Saml2LoginConfigurerTests { Authentication authentication = this.securityContextRepository .loadContext(new HttpRequestResponseHolder(this.request, this.response)) .getAuthentication(); - Assertions.assertNotNull(authentication, "Expected a valid authentication object."); + assertThat(authentication).as("Expected a valid authentication object.").isNotNull(); assertThat(authentication.getAuthorities()).hasSize(1); assertThat(authentication.getAuthorities()).first() .isInstanceOf(SimpleGrantedAuthority.class) diff --git a/core/src/test/java/org/springframework/security/access/intercept/RunAsImplAuthenticationProviderTests.java b/core/src/test/java/org/springframework/security/access/intercept/RunAsImplAuthenticationProviderTests.java index 18e79ca1eb..91a616415b 100644 --- a/core/src/test/java/org/springframework/security/access/intercept/RunAsImplAuthenticationProviderTests.java +++ b/core/src/test/java/org/springframework/security/access/intercept/RunAsImplAuthenticationProviderTests.java @@ -16,7 +16,6 @@ package org.springframework.security.access.intercept; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.security.authentication.BadCredentialsException; @@ -50,7 +49,7 @@ public class RunAsImplAuthenticationProviderTests { RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider(); provider.setKey("my_password"); Authentication result = provider.authenticate(token); - Assertions.assertTrue(result instanceof RunAsUserToken, "Should have returned RunAsUserToken"); + assertThat(result instanceof RunAsUserToken).as("Should have returned RunAsUserToken").isTrue(); RunAsUserToken resultCast = (RunAsUserToken) result; assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode()); } diff --git a/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorEquivalencyTests.java b/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorEquivalencyTests.java index 66cc64b30e..a37c83092c 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorEquivalencyTests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorEquivalencyTests.java @@ -20,7 +20,6 @@ import java.security.SecureRandom; import java.util.Random; import java.util.UUID; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,6 +28,8 @@ import org.springframework.security.crypto.encrypt.AesBytesEncryptor.CipherAlgor import org.springframework.security.crypto.keygen.BytesKeyGenerator; import org.springframework.security.crypto.keygen.KeyGenerators; +import static org.assertj.core.api.Assertions.assertThat; + public class BouncyCastleAesBytesEncryptorEquivalencyTests { private byte[] testData; @@ -96,11 +97,11 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests { // and can decrypt back to the original input byte[] leftEncrypted = left.encrypt(this.testData); byte[] rightEncrypted = right.encrypt(this.testData); - Assertions.assertArrayEquals(leftEncrypted, rightEncrypted); + assertThat(rightEncrypted).containsExactly(leftEncrypted); byte[] leftDecrypted = left.decrypt(leftEncrypted); byte[] rightDecrypted = right.decrypt(rightEncrypted); - Assertions.assertArrayEquals(this.testData, leftDecrypted); - Assertions.assertArrayEquals(this.testData, rightDecrypted); + assertThat(leftDecrypted).containsExactly(this.testData); + assertThat(rightDecrypted).containsExactly(this.testData); } } @@ -114,8 +115,8 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests { byte[] rightEncrypted = right.encrypt(this.testData); byte[] leftDecrypted = left.decrypt(rightEncrypted); byte[] rightDecrypted = right.decrypt(leftEncrypted); - Assertions.assertArrayEquals(this.testData, leftDecrypted); - Assertions.assertArrayEquals(this.testData, rightDecrypted); + assertThat(leftDecrypted).containsExactly(this.testData); + assertThat(rightDecrypted).containsExactly(this.testData); } } diff --git a/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorTests.java b/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorTests.java index 2b5ec62348..792c7c89df 100644 --- a/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorTests.java +++ b/crypto/src/test/java/org/springframework/security/crypto/encrypt/BouncyCastleAesBytesEncryptorTests.java @@ -20,13 +20,13 @@ import java.security.SecureRandom; import java.util.UUID; import org.bouncycastle.util.Arrays; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.security.crypto.codec.Hex; import org.springframework.security.crypto.keygen.KeyGenerators; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; public class BouncyCastleAesBytesEncryptorTests { @@ -64,11 +64,11 @@ public class BouncyCastleAesBytesEncryptorTests { private void generatesDifferentCipherTexts(BytesEncryptor bcEncryptor) { byte[] encrypted1 = bcEncryptor.encrypt(this.testData); byte[] encrypted2 = bcEncryptor.encrypt(this.testData); - Assertions.assertFalse(Arrays.areEqual(encrypted1, encrypted2)); + assertThat(Arrays.areEqual(encrypted1, encrypted2)).isFalse(); byte[] decrypted1 = bcEncryptor.decrypt(encrypted1); byte[] decrypted2 = bcEncryptor.decrypt(encrypted2); - Assertions.assertArrayEquals(this.testData, decrypted1); - Assertions.assertArrayEquals(this.testData, decrypted2); + assertThat(decrypted1).containsExactly(this.testData); + assertThat(decrypted2).containsExactly(this.testData); } @Test diff --git a/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultMapOAuth2AccessTokenResponseConverterTests.java b/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultMapOAuth2AccessTokenResponseConverterTests.java index 7b07619d58..bd2c4904df 100644 --- a/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultMapOAuth2AccessTokenResponseConverterTests.java +++ b/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultMapOAuth2AccessTokenResponseConverterTests.java @@ -22,7 +22,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,6 +29,8 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.security.oauth2.core.OAuth2AccessToken; import org.springframework.security.oauth2.core.OAuth2RefreshToken; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link DefaultMapOAuth2AccessTokenResponseConverter}. * @@ -56,24 +57,24 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests { map.put("custom_parameter_2", "custom-value-2"); OAuth2AccessTokenResponse converted = this.messageConverter.convert(map); OAuth2AccessToken accessToken = converted.getAccessToken(); - Assertions.assertNotNull(accessToken); - Assertions.assertEquals("access-token-1234", accessToken.getTokenValue()); - Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType()); + assertThat(accessToken).isNotNull(); + assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234"); + assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); Set scopes = accessToken.getScopes(); - Assertions.assertNotNull(scopes); - Assertions.assertEquals(2, scopes.size()); - Assertions.assertTrue(scopes.contains("read")); - Assertions.assertTrue(scopes.contains("write")); - Assertions.assertEquals(3600, - Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()); + assertThat(scopes).isNotNull(); + assertThat(scopes.size()).isEqualTo(2); + assertThat(scopes.contains("read")).isTrue(); + assertThat(scopes.contains("write")).isTrue(); + assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()) + .isEqualTo(3600); OAuth2RefreshToken refreshToken = converted.getRefreshToken(); - Assertions.assertNotNull(refreshToken); - Assertions.assertEquals("refresh-token-1234", refreshToken.getTokenValue()); + assertThat(refreshToken).isNotNull(); + assertThat(refreshToken.getTokenValue()).isEqualTo("refresh-token-1234"); Map additionalParameters = converted.getAdditionalParameters(); - Assertions.assertNotNull(additionalParameters); - Assertions.assertEquals(2, additionalParameters.size()); - Assertions.assertEquals("custom-value-1", additionalParameters.get("custom_parameter_1")); - Assertions.assertEquals("custom-value-2", additionalParameters.get("custom_parameter_2")); + assertThat(additionalParameters).isNotNull(); + assertThat(additionalParameters.size()).isEqualTo(2); + assertThat(additionalParameters.get("custom_parameter_1")).isEqualTo("custom-value-1"); + assertThat(additionalParameters.get("custom_parameter_2")).isEqualTo("custom-value-2"); } @Test @@ -83,19 +84,18 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests { map.put("token_type", "bearer"); OAuth2AccessTokenResponse converted = this.messageConverter.convert(map); OAuth2AccessToken accessToken = converted.getAccessToken(); - Assertions.assertNotNull(accessToken); - Assertions.assertEquals("access-token-1234", accessToken.getTokenValue()); - Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType()); + assertThat(accessToken).isNotNull(); + assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234"); + assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); Set scopes = accessToken.getScopes(); - Assertions.assertNotNull(scopes); - Assertions.assertEquals(0, scopes.size()); - Assertions.assertEquals(1, - Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()); + assertThat(scopes).isNotNull(); + assertThat(scopes.size()).isEqualTo(0); + assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()).isEqualTo(1); OAuth2RefreshToken refreshToken = converted.getRefreshToken(); - Assertions.assertNull(refreshToken); + assertThat(refreshToken).isNull(); Map additionalParameters = converted.getAdditionalParameters(); - Assertions.assertNotNull(additionalParameters); - Assertions.assertEquals(0, additionalParameters.size()); + assertThat(additionalParameters).isNotNull(); + assertThat(additionalParameters.size()).isEqualTo(0); } @Test @@ -106,19 +106,18 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests { map.put("expires_in", "2100-01-01-abc"); OAuth2AccessTokenResponse converted = this.messageConverter.convert(map); OAuth2AccessToken accessToken = converted.getAccessToken(); - Assertions.assertNotNull(accessToken); - Assertions.assertEquals("access-token-1234", accessToken.getTokenValue()); - Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType()); + assertThat(accessToken).isNotNull(); + assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234"); + assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); Set scopes = accessToken.getScopes(); - Assertions.assertNotNull(scopes); - Assertions.assertEquals(0, scopes.size()); - Assertions.assertEquals(1, - Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()); + assertThat(scopes).isNotNull(); + assertThat(scopes.size()).isEqualTo(0); + assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()).isEqualTo(1); OAuth2RefreshToken refreshToken = converted.getRefreshToken(); - Assertions.assertNull(refreshToken); + assertThat(refreshToken).isNull(); Map additionalParameters = converted.getAdditionalParameters(); - Assertions.assertNotNull(additionalParameters); - Assertions.assertEquals(0, additionalParameters.size()); + assertThat(additionalParameters).isNotNull(); + assertThat(additionalParameters.size()).isEqualTo(0); } // gh-9685 @@ -130,11 +129,11 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests { map.put("expires_in", 3600); OAuth2AccessTokenResponse converted = this.messageConverter.convert(map); OAuth2AccessToken accessToken = converted.getAccessToken(); - Assertions.assertNotNull(accessToken); - Assertions.assertEquals("access-token-1234", accessToken.getTokenValue()); - Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType()); - Assertions.assertEquals(3600, - Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()); + assertThat(accessToken).isNotNull(); + assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234"); + assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); + assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()) + .isEqualTo(3600); } // gh-9685 @@ -153,24 +152,24 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests { map.put("custom_parameter_2", "custom-value-2"); OAuth2AccessTokenResponse converted = this.messageConverter.convert(map); OAuth2AccessToken accessToken = converted.getAccessToken(); - Assertions.assertNotNull(accessToken); - Assertions.assertEquals("access-token-1234", accessToken.getTokenValue()); - Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType()); + assertThat(accessToken).isNotNull(); + assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234"); + assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER); Set scopes = accessToken.getScopes(); - Assertions.assertNotNull(scopes); - Assertions.assertEquals(2, scopes.size()); - Assertions.assertTrue(scopes.contains("read")); - Assertions.assertTrue(scopes.contains("write")); - Assertions.assertEquals(3600, - Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()); + assertThat(scopes).isNotNull(); + assertThat(scopes.size()).isEqualTo(2); + assertThat(scopes.contains("read")).isTrue(); + assertThat(scopes.contains("write")).isTrue(); + assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()) + .isEqualTo(3600); OAuth2RefreshToken refreshToken = converted.getRefreshToken(); - Assertions.assertNotNull(refreshToken); - Assertions.assertEquals("refresh-token-1234", refreshToken.getTokenValue()); + assertThat(refreshToken).isNotNull(); + assertThat(refreshToken.getTokenValue()).isEqualTo("refresh-token-1234"); Map additionalParameters = converted.getAdditionalParameters(); - Assertions.assertNotNull(additionalParameters); - Assertions.assertEquals(2, additionalParameters.size()); - Assertions.assertEquals(nestedObject, additionalParameters.get("custom_parameter_1")); - Assertions.assertEquals("custom-value-2", additionalParameters.get("custom_parameter_2")); + assertThat(additionalParameters).isNotNull(); + assertThat(additionalParameters.size()).isEqualTo(2); + assertThat(additionalParameters.get("custom_parameter_1")).isEqualTo(nestedObject); + assertThat(additionalParameters.get("custom_parameter_2")).isEqualTo("custom-value-2"); } } diff --git a/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultOAuth2AccessTokenResponseMapConverterTests.java b/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultOAuth2AccessTokenResponseMapConverterTests.java index 0d58ddaea4..427a521fab 100644 --- a/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultOAuth2AccessTokenResponseMapConverterTests.java +++ b/oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/endpoint/DefaultOAuth2AccessTokenResponseMapConverterTests.java @@ -22,13 +22,14 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.core.convert.converter.Converter; import org.springframework.security.oauth2.core.OAuth2AccessToken; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link DefaultOAuth2AccessTokenResponseMapConverter}. * @@ -61,14 +62,14 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests { .build(); // @formatter:on Map result = this.messageConverter.convert(build); - Assertions.assertEquals(7, result.size()); - Assertions.assertEquals("access-token-value-1234", result.get("access_token")); - Assertions.assertEquals("refresh-token-value-1234", result.get("refresh_token")); - Assertions.assertEquals("read write", result.get("scope")); - Assertions.assertEquals("Bearer", result.get("token_type")); - Assertions.assertNotNull(result.get("expires_in")); - Assertions.assertEquals("custom-value-1", result.get("custom_parameter_1")); - Assertions.assertEquals("custom-value-2", result.get("custom_parameter_2")); + assertThat(result.size()).isEqualTo(7); + assertThat(result.get("access_token")).isEqualTo("access-token-value-1234"); + assertThat(result.get("refresh_token")).isEqualTo("refresh-token-value-1234"); + assertThat(result.get("scope")).isEqualTo("read write"); + assertThat(result.get("token_type")).isEqualTo("Bearer"); + assertThat(result.get("expires_in")).isNotNull(); + assertThat(result.get("custom_parameter_1")).isEqualTo("custom-value-1"); + assertThat(result.get("custom_parameter_2")).isEqualTo("custom-value-2"); } @Test @@ -79,10 +80,10 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests { .build(); // @formatter:on Map result = this.messageConverter.convert(build); - Assertions.assertEquals(3, result.size()); - Assertions.assertEquals("access-token-value-1234", result.get("access_token")); - Assertions.assertEquals("Bearer", result.get("token_type")); - Assertions.assertNotNull(result.get("expires_in")); + assertThat(result.size()).isEqualTo(3); + assertThat(result.get("access_token")).isEqualTo("access-token-value-1234"); + assertThat(result.get("token_type")).isEqualTo("Bearer"); + assertThat(result.get("expires_in")).isNotNull(); } // gh-9685 @@ -107,14 +108,14 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests { .build(); // @formatter:on Map result = this.messageConverter.convert(build); - Assertions.assertEquals(7, result.size()); - Assertions.assertEquals("access-token-value-1234", result.get("access_token")); - Assertions.assertEquals("refresh-token-value-1234", result.get("refresh_token")); - Assertions.assertEquals("read write", result.get("scope")); - Assertions.assertEquals("Bearer", result.get("token_type")); - Assertions.assertNotNull(result.get("expires_in")); - Assertions.assertEquals(nestedObject, result.get("custom_parameter_1")); - Assertions.assertEquals("custom-value-2", result.get("custom_parameter_2")); + assertThat(result.size()).isEqualTo(7); + assertThat(result.get("access_token")).isEqualTo("access-token-value-1234"); + assertThat(result.get("refresh_token")).isEqualTo("refresh-token-value-1234"); + assertThat(result.get("scope")).isEqualTo("read write"); + assertThat(result.get("token_type")).isEqualTo("Bearer"); + assertThat(result.get("expires_in")).isNotNull(); + assertThat(result.get("custom_parameter_1")).isEqualTo(nestedObject); + assertThat(result.get("custom_parameter_2")).isEqualTo("custom-value-2"); } } diff --git a/saml2/saml2-service-provider/src/opensaml3Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationRequestFactoryTests.java b/saml2/saml2-service-provider/src/opensaml3Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationRequestFactoryTests.java index 6b2305447f..9139342689 100644 --- a/saml2/saml2-service-provider/src/opensaml3Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationRequestFactoryTests.java +++ b/saml2/saml2-service-provider/src/opensaml3Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import org.joda.time.DateTime; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; @@ -190,14 +189,14 @@ public class OpenSamlAuthenticationRequestFactoryTests { @Test public void createAuthenticationRequestWhenDefaultThenReturnsPostBinding() { AuthnRequest authn = getAuthNRequest(Saml2MessageBinding.POST); - Assertions.assertEquals(SAMLConstants.SAML2_POST_BINDING_URI, authn.getProtocolBinding()); + assertThat(SAMLConstants.SAML2_POST_BINDING_URI).isEqualTo(authn.getProtocolBinding()); } @Test public void createAuthenticationRequestWhenSetUriThenReturnsCorrectBinding() { this.factory.setProtocolBinding(SAMLConstants.SAML2_REDIRECT_BINDING_URI); AuthnRequest authn = getAuthNRequest(Saml2MessageBinding.POST); - Assertions.assertEquals(SAMLConstants.SAML2_REDIRECT_BINDING_URI, authn.getProtocolBinding()); + assertThat(SAMLConstants.SAML2_REDIRECT_BINDING_URI).isEqualTo(authn.getProtocolBinding()); } @Test diff --git a/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationRequestFactoryTests.java b/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationRequestFactoryTests.java index 7e361d88fc..06ff342faf 100644 --- a/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationRequestFactoryTests.java +++ b/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.time.Instant; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport; @@ -190,7 +189,7 @@ public class OpenSaml4AuthenticationRequestFactoryTests { @Test public void createAuthenticationRequestWhenDefaultThenReturnsPostBinding() { AuthnRequest authn = getAuthNRequest(Saml2MessageBinding.POST); - Assertions.assertEquals(SAMLConstants.SAML2_POST_BINDING_URI, authn.getProtocolBinding()); + assertThat(SAMLConstants.SAML2_POST_BINDING_URI).isEqualTo(authn.getProtocolBinding()); } @Test diff --git a/saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/web/authentication/Saml2WebSsoAuthenticationFilterTests.java b/saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/web/authentication/Saml2WebSsoAuthenticationFilterTests.java index 5e428ff793..4b5bec8e7b 100644 --- a/saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/web/authentication/Saml2WebSsoAuthenticationFilterTests.java +++ b/saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/web/authentication/Saml2WebSsoAuthenticationFilterTests.java @@ -18,7 +18,6 @@ package org.springframework.security.saml2.provider.service.web.authentication; import javax.servlet.http.HttpServletResponse; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,6 +45,7 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; +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.assertThatNoException; @@ -94,7 +94,7 @@ public class Saml2WebSsoAuthenticationFilterTests { @Test public void requiresAuthenticationWhenHappyPathThenReturnsTrue() { - Assertions.assertTrue(this.filter.requiresAuthentication(this.request, this.response)); + assertThat(this.filter.requiresAuthentication(this.request, this.response)).isTrue(); } @Test @@ -102,7 +102,7 @@ public class Saml2WebSsoAuthenticationFilterTests { this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}"); this.request.setPathInfo("/some/other/path/idp-registration-id"); this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here"); - Assertions.assertTrue(this.filter.requiresAuthentication(this.request, this.response)); + assertThat(this.filter.requiresAuthentication(this.request, this.response)).isTrue(); } @Test @@ -143,7 +143,7 @@ public class Saml2WebSsoAuthenticationFilterTests { this.filter.setAuthenticationDetailsSource(authenticationDetailsSource); this.request.setPathInfo("/some/other/path/idp-registration-id"); this.filter.attemptAuthentication(this.request, this.response); - Assertions.assertEquals(details, token.getDetails()); + assertThat(token.getDetails()).isEqualTo(details); } @Test