Use assertj assertions
This commit is contained in:
parent
c09ace9c64
commit
00da9c9092
|
@ -25,7 +25,6 @@ import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
@ -384,7 +383,7 @@ public class Saml2LoginConfigurerTests {
|
||||||
Authentication authentication = this.securityContextRepository
|
Authentication authentication = this.securityContextRepository
|
||||||
.loadContext(new HttpRequestResponseHolder(this.request, this.response))
|
.loadContext(new HttpRequestResponseHolder(this.request, this.response))
|
||||||
.getAuthentication();
|
.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()).hasSize(1);
|
||||||
assertThat(authentication.getAuthorities()).first()
|
assertThat(authentication.getAuthorities()).first()
|
||||||
.isInstanceOf(SimpleGrantedAuthority.class)
|
.isInstanceOf(SimpleGrantedAuthority.class)
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.security.access.intercept;
|
package org.springframework.security.access.intercept;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
@ -50,7 +49,7 @@ public class RunAsImplAuthenticationProviderTests {
|
||||||
RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider();
|
RunAsImplAuthenticationProvider provider = new RunAsImplAuthenticationProvider();
|
||||||
provider.setKey("my_password");
|
provider.setKey("my_password");
|
||||||
Authentication result = provider.authenticate(token);
|
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;
|
RunAsUserToken resultCast = (RunAsUserToken) result;
|
||||||
assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode());
|
assertThat(resultCast.getKeyHash()).isEqualTo("my_password".hashCode());
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.BytesKeyGenerator;
|
||||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||||
|
|
||||||
private byte[] testData;
|
private byte[] testData;
|
||||||
|
@ -96,11 +97,11 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||||
// and can decrypt back to the original input
|
// and can decrypt back to the original input
|
||||||
byte[] leftEncrypted = left.encrypt(this.testData);
|
byte[] leftEncrypted = left.encrypt(this.testData);
|
||||||
byte[] rightEncrypted = right.encrypt(this.testData);
|
byte[] rightEncrypted = right.encrypt(this.testData);
|
||||||
Assertions.assertArrayEquals(leftEncrypted, rightEncrypted);
|
assertThat(rightEncrypted).containsExactly(leftEncrypted);
|
||||||
byte[] leftDecrypted = left.decrypt(leftEncrypted);
|
byte[] leftDecrypted = left.decrypt(leftEncrypted);
|
||||||
byte[] rightDecrypted = right.decrypt(rightEncrypted);
|
byte[] rightDecrypted = right.decrypt(rightEncrypted);
|
||||||
Assertions.assertArrayEquals(this.testData, leftDecrypted);
|
assertThat(leftDecrypted).containsExactly(this.testData);
|
||||||
Assertions.assertArrayEquals(this.testData, rightDecrypted);
|
assertThat(rightDecrypted).containsExactly(this.testData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,8 +115,8 @@ public class BouncyCastleAesBytesEncryptorEquivalencyTests {
|
||||||
byte[] rightEncrypted = right.encrypt(this.testData);
|
byte[] rightEncrypted = right.encrypt(this.testData);
|
||||||
byte[] leftDecrypted = left.decrypt(rightEncrypted);
|
byte[] leftDecrypted = left.decrypt(rightEncrypted);
|
||||||
byte[] rightDecrypted = right.decrypt(leftEncrypted);
|
byte[] rightDecrypted = right.decrypt(leftEncrypted);
|
||||||
Assertions.assertArrayEquals(this.testData, leftDecrypted);
|
assertThat(leftDecrypted).containsExactly(this.testData);
|
||||||
Assertions.assertArrayEquals(this.testData, rightDecrypted);
|
assertThat(rightDecrypted).containsExactly(this.testData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,13 @@ import java.security.SecureRandom;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bouncycastle.util.Arrays;
|
import org.bouncycastle.util.Arrays;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.security.crypto.codec.Hex;
|
import org.springframework.security.crypto.codec.Hex;
|
||||||
import org.springframework.security.crypto.keygen.KeyGenerators;
|
import org.springframework.security.crypto.keygen.KeyGenerators;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
public class BouncyCastleAesBytesEncryptorTests {
|
public class BouncyCastleAesBytesEncryptorTests {
|
||||||
|
@ -64,11 +64,11 @@ public class BouncyCastleAesBytesEncryptorTests {
|
||||||
private void generatesDifferentCipherTexts(BytesEncryptor bcEncryptor) {
|
private void generatesDifferentCipherTexts(BytesEncryptor bcEncryptor) {
|
||||||
byte[] encrypted1 = bcEncryptor.encrypt(this.testData);
|
byte[] encrypted1 = bcEncryptor.encrypt(this.testData);
|
||||||
byte[] encrypted2 = 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[] decrypted1 = bcEncryptor.decrypt(encrypted1);
|
||||||
byte[] decrypted2 = bcEncryptor.decrypt(encrypted2);
|
byte[] decrypted2 = bcEncryptor.decrypt(encrypted2);
|
||||||
Assertions.assertArrayEquals(this.testData, decrypted1);
|
assertThat(decrypted1).containsExactly(this.testData);
|
||||||
Assertions.assertArrayEquals(this.testData, decrypted2);
|
assertThat(decrypted2).containsExactly(this.testData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.OAuth2AccessToken;
|
||||||
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
import org.springframework.security.oauth2.core.OAuth2RefreshToken;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DefaultMapOAuth2AccessTokenResponseConverter}.
|
* Tests for {@link DefaultMapOAuth2AccessTokenResponseConverter}.
|
||||||
*
|
*
|
||||||
|
@ -56,24 +57,24 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests {
|
||||||
map.put("custom_parameter_2", "custom-value-2");
|
map.put("custom_parameter_2", "custom-value-2");
|
||||||
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
||||||
OAuth2AccessToken accessToken = converted.getAccessToken();
|
OAuth2AccessToken accessToken = converted.getAccessToken();
|
||||||
Assertions.assertNotNull(accessToken);
|
assertThat(accessToken).isNotNull();
|
||||||
Assertions.assertEquals("access-token-1234", accessToken.getTokenValue());
|
assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234");
|
||||||
Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType());
|
assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER);
|
||||||
Set<String> scopes = accessToken.getScopes();
|
Set<String> scopes = accessToken.getScopes();
|
||||||
Assertions.assertNotNull(scopes);
|
assertThat(scopes).isNotNull();
|
||||||
Assertions.assertEquals(2, scopes.size());
|
assertThat(scopes.size()).isEqualTo(2);
|
||||||
Assertions.assertTrue(scopes.contains("read"));
|
assertThat(scopes.contains("read")).isTrue();
|
||||||
Assertions.assertTrue(scopes.contains("write"));
|
assertThat(scopes.contains("write")).isTrue();
|
||||||
Assertions.assertEquals(3600,
|
assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds())
|
||||||
Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds());
|
.isEqualTo(3600);
|
||||||
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
||||||
Assertions.assertNotNull(refreshToken);
|
assertThat(refreshToken).isNotNull();
|
||||||
Assertions.assertEquals("refresh-token-1234", refreshToken.getTokenValue());
|
assertThat(refreshToken.getTokenValue()).isEqualTo("refresh-token-1234");
|
||||||
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
||||||
Assertions.assertNotNull(additionalParameters);
|
assertThat(additionalParameters).isNotNull();
|
||||||
Assertions.assertEquals(2, additionalParameters.size());
|
assertThat(additionalParameters.size()).isEqualTo(2);
|
||||||
Assertions.assertEquals("custom-value-1", additionalParameters.get("custom_parameter_1"));
|
assertThat(additionalParameters.get("custom_parameter_1")).isEqualTo("custom-value-1");
|
||||||
Assertions.assertEquals("custom-value-2", additionalParameters.get("custom_parameter_2"));
|
assertThat(additionalParameters.get("custom_parameter_2")).isEqualTo("custom-value-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,19 +84,18 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests {
|
||||||
map.put("token_type", "bearer");
|
map.put("token_type", "bearer");
|
||||||
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
||||||
OAuth2AccessToken accessToken = converted.getAccessToken();
|
OAuth2AccessToken accessToken = converted.getAccessToken();
|
||||||
Assertions.assertNotNull(accessToken);
|
assertThat(accessToken).isNotNull();
|
||||||
Assertions.assertEquals("access-token-1234", accessToken.getTokenValue());
|
assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234");
|
||||||
Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType());
|
assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER);
|
||||||
Set<String> scopes = accessToken.getScopes();
|
Set<String> scopes = accessToken.getScopes();
|
||||||
Assertions.assertNotNull(scopes);
|
assertThat(scopes).isNotNull();
|
||||||
Assertions.assertEquals(0, scopes.size());
|
assertThat(scopes.size()).isEqualTo(0);
|
||||||
Assertions.assertEquals(1,
|
assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()).isEqualTo(1);
|
||||||
Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds());
|
|
||||||
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
||||||
Assertions.assertNull(refreshToken);
|
assertThat(refreshToken).isNull();
|
||||||
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
||||||
Assertions.assertNotNull(additionalParameters);
|
assertThat(additionalParameters).isNotNull();
|
||||||
Assertions.assertEquals(0, additionalParameters.size());
|
assertThat(additionalParameters.size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -106,19 +106,18 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests {
|
||||||
map.put("expires_in", "2100-01-01-abc");
|
map.put("expires_in", "2100-01-01-abc");
|
||||||
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
||||||
OAuth2AccessToken accessToken = converted.getAccessToken();
|
OAuth2AccessToken accessToken = converted.getAccessToken();
|
||||||
Assertions.assertNotNull(accessToken);
|
assertThat(accessToken).isNotNull();
|
||||||
Assertions.assertEquals("access-token-1234", accessToken.getTokenValue());
|
assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234");
|
||||||
Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType());
|
assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER);
|
||||||
Set<String> scopes = accessToken.getScopes();
|
Set<String> scopes = accessToken.getScopes();
|
||||||
Assertions.assertNotNull(scopes);
|
assertThat(scopes).isNotNull();
|
||||||
Assertions.assertEquals(0, scopes.size());
|
assertThat(scopes.size()).isEqualTo(0);
|
||||||
Assertions.assertEquals(1,
|
assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds()).isEqualTo(1);
|
||||||
Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds());
|
|
||||||
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
||||||
Assertions.assertNull(refreshToken);
|
assertThat(refreshToken).isNull();
|
||||||
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
||||||
Assertions.assertNotNull(additionalParameters);
|
assertThat(additionalParameters).isNotNull();
|
||||||
Assertions.assertEquals(0, additionalParameters.size());
|
assertThat(additionalParameters.size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// gh-9685
|
// gh-9685
|
||||||
|
@ -130,11 +129,11 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests {
|
||||||
map.put("expires_in", 3600);
|
map.put("expires_in", 3600);
|
||||||
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
||||||
OAuth2AccessToken accessToken = converted.getAccessToken();
|
OAuth2AccessToken accessToken = converted.getAccessToken();
|
||||||
Assertions.assertNotNull(accessToken);
|
assertThat(accessToken).isNotNull();
|
||||||
Assertions.assertEquals("access-token-1234", accessToken.getTokenValue());
|
assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234");
|
||||||
Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType());
|
assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER);
|
||||||
Assertions.assertEquals(3600,
|
assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds())
|
||||||
Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds());
|
.isEqualTo(3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
// gh-9685
|
// gh-9685
|
||||||
|
@ -153,24 +152,24 @@ public class DefaultMapOAuth2AccessTokenResponseConverterTests {
|
||||||
map.put("custom_parameter_2", "custom-value-2");
|
map.put("custom_parameter_2", "custom-value-2");
|
||||||
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
OAuth2AccessTokenResponse converted = this.messageConverter.convert(map);
|
||||||
OAuth2AccessToken accessToken = converted.getAccessToken();
|
OAuth2AccessToken accessToken = converted.getAccessToken();
|
||||||
Assertions.assertNotNull(accessToken);
|
assertThat(accessToken).isNotNull();
|
||||||
Assertions.assertEquals("access-token-1234", accessToken.getTokenValue());
|
assertThat(accessToken.getTokenValue()).isEqualTo("access-token-1234");
|
||||||
Assertions.assertEquals(OAuth2AccessToken.TokenType.BEARER, accessToken.getTokenType());
|
assertThat(accessToken.getTokenType()).isEqualTo(OAuth2AccessToken.TokenType.BEARER);
|
||||||
Set<String> scopes = accessToken.getScopes();
|
Set<String> scopes = accessToken.getScopes();
|
||||||
Assertions.assertNotNull(scopes);
|
assertThat(scopes).isNotNull();
|
||||||
Assertions.assertEquals(2, scopes.size());
|
assertThat(scopes.size()).isEqualTo(2);
|
||||||
Assertions.assertTrue(scopes.contains("read"));
|
assertThat(scopes.contains("read")).isTrue();
|
||||||
Assertions.assertTrue(scopes.contains("write"));
|
assertThat(scopes.contains("write")).isTrue();
|
||||||
Assertions.assertEquals(3600,
|
assertThat(Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds())
|
||||||
Duration.between(accessToken.getIssuedAt(), accessToken.getExpiresAt()).getSeconds());
|
.isEqualTo(3600);
|
||||||
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
OAuth2RefreshToken refreshToken = converted.getRefreshToken();
|
||||||
Assertions.assertNotNull(refreshToken);
|
assertThat(refreshToken).isNotNull();
|
||||||
Assertions.assertEquals("refresh-token-1234", refreshToken.getTokenValue());
|
assertThat(refreshToken.getTokenValue()).isEqualTo("refresh-token-1234");
|
||||||
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
Map<String, Object> additionalParameters = converted.getAdditionalParameters();
|
||||||
Assertions.assertNotNull(additionalParameters);
|
assertThat(additionalParameters).isNotNull();
|
||||||
Assertions.assertEquals(2, additionalParameters.size());
|
assertThat(additionalParameters.size()).isEqualTo(2);
|
||||||
Assertions.assertEquals(nestedObject, additionalParameters.get("custom_parameter_1"));
|
assertThat(additionalParameters.get("custom_parameter_1")).isEqualTo(nestedObject);
|
||||||
Assertions.assertEquals("custom-value-2", additionalParameters.get("custom_parameter_2"));
|
assertThat(additionalParameters.get("custom_parameter_2")).isEqualTo("custom-value-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,14 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DefaultOAuth2AccessTokenResponseMapConverter}.
|
* Tests for {@link DefaultOAuth2AccessTokenResponseMapConverter}.
|
||||||
*
|
*
|
||||||
|
@ -61,14 +62,14 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests {
|
||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
Map<String, Object> result = this.messageConverter.convert(build);
|
Map<String, Object> result = this.messageConverter.convert(build);
|
||||||
Assertions.assertEquals(7, result.size());
|
assertThat(result.size()).isEqualTo(7);
|
||||||
Assertions.assertEquals("access-token-value-1234", result.get("access_token"));
|
assertThat(result.get("access_token")).isEqualTo("access-token-value-1234");
|
||||||
Assertions.assertEquals("refresh-token-value-1234", result.get("refresh_token"));
|
assertThat(result.get("refresh_token")).isEqualTo("refresh-token-value-1234");
|
||||||
Assertions.assertEquals("read write", result.get("scope"));
|
assertThat(result.get("scope")).isEqualTo("read write");
|
||||||
Assertions.assertEquals("Bearer", result.get("token_type"));
|
assertThat(result.get("token_type")).isEqualTo("Bearer");
|
||||||
Assertions.assertNotNull(result.get("expires_in"));
|
assertThat(result.get("expires_in")).isNotNull();
|
||||||
Assertions.assertEquals("custom-value-1", result.get("custom_parameter_1"));
|
assertThat(result.get("custom_parameter_1")).isEqualTo("custom-value-1");
|
||||||
Assertions.assertEquals("custom-value-2", result.get("custom_parameter_2"));
|
assertThat(result.get("custom_parameter_2")).isEqualTo("custom-value-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -79,10 +80,10 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests {
|
||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
Map<String, Object> result = this.messageConverter.convert(build);
|
Map<String, Object> result = this.messageConverter.convert(build);
|
||||||
Assertions.assertEquals(3, result.size());
|
assertThat(result.size()).isEqualTo(3);
|
||||||
Assertions.assertEquals("access-token-value-1234", result.get("access_token"));
|
assertThat(result.get("access_token")).isEqualTo("access-token-value-1234");
|
||||||
Assertions.assertEquals("Bearer", result.get("token_type"));
|
assertThat(result.get("token_type")).isEqualTo("Bearer");
|
||||||
Assertions.assertNotNull(result.get("expires_in"));
|
assertThat(result.get("expires_in")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gh-9685
|
// gh-9685
|
||||||
|
@ -107,14 +108,14 @@ public class DefaultOAuth2AccessTokenResponseMapConverterTests {
|
||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
Map<String, Object> result = this.messageConverter.convert(build);
|
Map<String, Object> result = this.messageConverter.convert(build);
|
||||||
Assertions.assertEquals(7, result.size());
|
assertThat(result.size()).isEqualTo(7);
|
||||||
Assertions.assertEquals("access-token-value-1234", result.get("access_token"));
|
assertThat(result.get("access_token")).isEqualTo("access-token-value-1234");
|
||||||
Assertions.assertEquals("refresh-token-value-1234", result.get("refresh_token"));
|
assertThat(result.get("refresh_token")).isEqualTo("refresh-token-value-1234");
|
||||||
Assertions.assertEquals("read write", result.get("scope"));
|
assertThat(result.get("scope")).isEqualTo("read write");
|
||||||
Assertions.assertEquals("Bearer", result.get("token_type"));
|
assertThat(result.get("token_type")).isEqualTo("Bearer");
|
||||||
Assertions.assertNotNull(result.get("expires_in"));
|
assertThat(result.get("expires_in")).isNotNull();
|
||||||
Assertions.assertEquals(nestedObject, result.get("custom_parameter_1"));
|
assertThat(result.get("custom_parameter_1")).isEqualTo(nestedObject);
|
||||||
Assertions.assertEquals("custom-value-2", result.get("custom_parameter_2"));
|
assertThat(result.get("custom_parameter_2")).isEqualTo("custom-value-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.security.saml2.provider.service.web.authentication;
|
package org.springframework.security.saml2.provider.service.web.authentication;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -45,6 +44,7 @@ import org.springframework.security.web.authentication.WebAuthenticationDetails;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
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.assertThatExceptionOfType;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||||
|
@ -93,7 +93,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requiresAuthenticationWhenHappyPathThenReturnsTrue() {
|
public void requiresAuthenticationWhenHappyPathThenReturnsTrue() {
|
||||||
Assertions.assertTrue(this.filter.requiresAuthentication(this.request, this.response));
|
assertThat(this.filter.requiresAuthentication(this.request, this.response)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -101,7 +101,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
||||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
|
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
|
||||||
this.request.setPathInfo("/some/other/path/idp-registration-id");
|
this.request.setPathInfo("/some/other/path/idp-registration-id");
|
||||||
this.request.setParameter(Saml2ParameterNames.SAML_RESPONSE, "xml-data-goes-here");
|
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
|
@Test
|
||||||
|
@ -142,7 +142,7 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
||||||
this.filter.setAuthenticationDetailsSource(authenticationDetailsSource);
|
this.filter.setAuthenticationDetailsSource(authenticationDetailsSource);
|
||||||
this.request.setPathInfo("/some/other/path/idp-registration-id");
|
this.request.setPathInfo("/some/other/path/idp-registration-id");
|
||||||
this.filter.attemptAuthentication(this.request, this.response);
|
this.filter.attemptAuthentication(this.request, this.response);
|
||||||
Assertions.assertEquals(details, token.getDetails());
|
assertThat(token.getDetails()).isEqualTo(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue