Polish core format
Issue gh-8945
This commit is contained in:
@@ -79,7 +79,11 @@ public class ReactiveAuthenticationManagerAdapterTests {
|
||||
public void authenticateWhenBadCredentialsThenError() {
|
||||
given(this.delegate.authenticate(any())).willThrow(new BadCredentialsException("Failed"));
|
||||
Mono<Authentication> result = this.manager.authenticate(this.authentication);
|
||||
StepVerifier.create(result).expectError(BadCredentialsException.class).verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(result)
|
||||
.expectError(BadCredentialsException.class)
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,11 @@ public class ReactiveUserDetailsServiceAuthenticationManagerTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(this.username,
|
||||
this.password);
|
||||
Mono<Authentication> authentication = this.manager.authenticate(token);
|
||||
StepVerifier.create(authentication).expectError(BadCredentialsException.class).verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(authentication)
|
||||
.expectError(BadCredentialsException.class)
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +93,11 @@ public class ReactiveUserDetailsServiceAuthenticationManagerTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(this.username,
|
||||
this.password + "INVALID");
|
||||
Mono<Authentication> authentication = this.manager.authenticate(token);
|
||||
StepVerifier.create(authentication).expectError(BadCredentialsException.class).verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(authentication)
|
||||
.expectError(BadCredentialsException.class)
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,7 +136,11 @@ public class ReactiveUserDetailsServiceAuthenticationManagerTests {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(this.username,
|
||||
this.password);
|
||||
Mono<Authentication> authentication = this.manager.authenticate(token);
|
||||
StepVerifier.create(authentication).expectError(BadCredentialsException.class).verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(authentication)
|
||||
.expectError(BadCredentialsException.class)
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,11 @@ public class AuthenticatedReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenErrorThenError() {
|
||||
Mono<AuthorizationDecision> result = this.manager.check(Mono.error(new RuntimeException("ooops")), null);
|
||||
StepVerifier.create(result).expectError().verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(result)
|
||||
.expectError()
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,11 @@ public class AuthorityReactiveAuthorizationManagerTests {
|
||||
@Test
|
||||
public void checkWhenHasAuthorityAndErrorThenError() {
|
||||
Mono<AuthorizationDecision> result = this.manager.check(Mono.error(new RuntimeException("ooops")), null);
|
||||
StepVerifier.create(result).expectError().verify();
|
||||
// @formatter:off
|
||||
StepVerifier.create(result)
|
||||
.expectError()
|
||||
.verify();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
public class RsaKeyConvertersTests {
|
||||
|
||||
// @formatter:off
|
||||
private static final String PKCS8_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----\n"
|
||||
+ "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCMk7CKSTfu3QoV\n"
|
||||
+ "HoPVXxwZO+qweztd36cVWYqGOZinrOR2crWFu50AgR2CsdIH0+cqo7F4Vx7/3O8i\n"
|
||||
@@ -60,9 +61,12 @@ public class RsaKeyConvertersTests {
|
||||
+ "OHjxffBM0hH+fySx8m53gFfr2BpaqDX5f6ZGBlly1SlsWZ4CchCVsc71nshipi7I\n"
|
||||
+ "k8HL9F5/OpQdDNprJ5RMBNfkWE65Nrcsb1e6oPkCgYAxwgdiSOtNg8PjDVDmAhwT\n"
|
||||
+ "Mxj0Dtwi2fAqQ76RVrrXpNp3uCOIAu4CfruIb5llcJ3uak0ZbnWri32AxSgk80y3\n"
|
||||
+ "EWiRX/WEDu5znejF+5O3pI02atWWcnxifEKGGlxwkcMbQdA67MlrJLFaSnnGpNXo\n" + "yPfcul058SOqhafIZQMEKQ==\n"
|
||||
+ "EWiRX/WEDu5znejF+5O3pI02atWWcnxifEKGGlxwkcMbQdA67MlrJLFaSnnGpNXo\n"
|
||||
+ "yPfcul058SOqhafIZQMEKQ==\n"
|
||||
+ "-----END PRIVATE KEY-----";
|
||||
// @formatter:on
|
||||
|
||||
// @formatter:off
|
||||
private static final String PKCS1_PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\n"
|
||||
+ "MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw\n"
|
||||
+ "33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW\n"
|
||||
@@ -76,13 +80,18 @@ public class RsaKeyConvertersTests {
|
||||
+ "6Z8KWrfYzJoI/Q9FuBo6rKwl4BFoToD7WIUS+hpkagwWiz+6zLoX1dbOZwJACmH5\n"
|
||||
+ "fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523\n"
|
||||
+ "Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP\n"
|
||||
+ "FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n" + "-----END RSA PRIVATE KEY-----";
|
||||
+ "FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==\n"
|
||||
+ "-----END RSA PRIVATE KEY-----";
|
||||
// @formatter:on
|
||||
|
||||
// @formatter:off
|
||||
private static final String X509_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
|
||||
+ "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd\n"
|
||||
+ "UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs\n"
|
||||
+ "HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D\n" + "o2kQ+X5xK9cipRgEKwIDAQAB\n"
|
||||
+ "HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D\n"
|
||||
+ "o2kQ+X5xK9cipRgEKwIDAQAB\n"
|
||||
+ "-----END PUBLIC KEY-----";
|
||||
// @formatter:on
|
||||
|
||||
private static final String MALFORMED_X509_KEY = "malformed";
|
||||
|
||||
|
||||
@@ -32,7 +32,10 @@ public class ReactiveSecurityContextHolderTests {
|
||||
@Test
|
||||
public void getContextWhenEmpty() {
|
||||
Mono<SecurityContext> context = ReactiveSecurityContextHolder.getContext();
|
||||
StepVerifier.create(context).verifyComplete();
|
||||
// @formatter:off
|
||||
StepVerifier.create(context)
|
||||
.verifyComplete();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,17 +45,26 @@ public class ReactiveSecurityContextHolderTests {
|
||||
Mono<SecurityContext> context = Mono.subscriberContext()
|
||||
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
|
||||
StepVerifier.create(context).expectNext(expectedContext).verifyComplete();
|
||||
// @formatter:off
|
||||
StepVerifier.create(context)
|
||||
.expectNext(expectedContext)
|
||||
.verifyComplete();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demo() {
|
||||
Authentication authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
||||
// @formatter:off
|
||||
Mono<String> messageByUsername = ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication).map(Authentication::getName)
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.map(Authentication::getName)
|
||||
.flatMap(this::findMessageByUsername)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));
|
||||
StepVerifier.create(messageByUsername).expectNext("Hi user").verifyComplete();
|
||||
StepVerifier.create(messageByUsername)
|
||||
.expectNext("Hi user")
|
||||
.verifyComplete();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
private Mono<String> findMessageByUsername(String username) {
|
||||
@@ -63,20 +75,28 @@ public class ReactiveSecurityContextHolderTests {
|
||||
public void setContextAndClearAndGetContextThenEmitsEmpty() {
|
||||
SecurityContext expectedContext = new SecurityContextImpl(
|
||||
new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
||||
// @formatter:off
|
||||
Mono<SecurityContext> context = Mono.subscriberContext()
|
||||
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
||||
.subscriberContext(ReactiveSecurityContextHolder.clearContext())
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
|
||||
StepVerifier.create(context).verifyComplete();
|
||||
StepVerifier.create(context)
|
||||
.verifyComplete();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAuthenticationAndGetContextThenEmitsContext() {
|
||||
Authentication expectedAuthentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
||||
// @formatter:off
|
||||
Mono<Authentication> authentication = Mono.subscriberContext()
|
||||
.flatMap((c) -> ReactiveSecurityContextHolder.getContext()).map(SecurityContext::getAuthentication)
|
||||
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(expectedAuthentication));
|
||||
StepVerifier.create(authentication).expectNext(expectedAuthentication).verifyComplete();
|
||||
StepVerifier.create(authentication)
|
||||
.expectNext(expectedAuthentication)
|
||||
.verifyComplete();
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ public class PasswordEncodedUser {
|
||||
}
|
||||
|
||||
public static User.UserBuilder withUserDetails(UserDetails userDetails) {
|
||||
return User.withUserDetails(userDetails).passwordEncoder(passwordEncoder());
|
||||
// @formatter:off
|
||||
return User
|
||||
.withUserDetails(userDetails)
|
||||
.passwordEncoder(passwordEncoder());
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
private static Function<String, String> passwordEncoder() {
|
||||
|
||||
@@ -51,8 +51,11 @@ public class SecurityJackson2ModulesTests {
|
||||
@Test
|
||||
public void readValueWhenNotAllowedOrMappedThenThrowsException() {
|
||||
String content = "{\"@class\":\"org.springframework.security.jackson2.SecurityJackson2ModulesTests$NotAllowlisted\",\"property\":\"bar\"}";
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> this.mapper.readValue(content, Object.class))
|
||||
// @formatter:off
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
.isThrownBy(() -> this.mapper.readValue(content, Object.class))
|
||||
.withStackTraceContaining("allowlist");
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user