瀏覽代碼

Polish OTT Tests

Improve tests so that they do not rely on OneTimeTokenAuthenticationToken
as the concrete type.

Issue gh-17799
Josh Cummings 21 小時之前
父節點
當前提交
6663eea65f

+ 2 - 2
core/src/test/java/org/springframework/security/authentication/ott/OneTimeTokenAuthenticationProviderTests.java

@@ -26,6 +26,7 @@ import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
 
 import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.core.Authentication;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetailsService;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -69,8 +70,7 @@ public class OneTimeTokenAuthenticationProviderTests {
 			.willReturn(new User(USERNAME, PASSWORD, List.of()));
 		OneTimeTokenAuthenticationToken token = new OneTimeTokenAuthenticationToken(TOKEN);
 
-		OneTimeTokenAuthenticationToken authentication = (OneTimeTokenAuthenticationToken) this.provider
-			.authenticate(token);
+		Authentication authentication = this.provider.authenticate(token);
 
 		User user = (User) authentication.getPrincipal();
 		assertThat(authentication.isAuthenticated()).isTrue();

+ 2 - 3
core/src/test/java/org/springframework/security/authentication/ott/reactive/OneTimeTokenReactiveAuthenticationManagerTests.java

@@ -88,13 +88,12 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
 		this.authenticationManager = new OneTimeTokenReactiveAuthenticationManager(oneTimeTokenService,
 				userDetailsService);
 
-		Authentication auth = this.authenticationManager
+		Authentication token = this.authenticationManager
 			.authenticate(OneTimeTokenAuthenticationToken.unauthenticated(TOKEN))
 			.block();
 
-		OneTimeTokenAuthenticationToken token = (OneTimeTokenAuthenticationToken) auth;
 		UserDetails user = (UserDetails) token.getPrincipal();
-		Collection<GrantedAuthority> authorities = token.getAuthorities();
+		Collection<? extends GrantedAuthority> authorities = token.getAuthorities();
 
 		assertThat(user).isNotNull();
 		assertThat(user.getUsername()).isEqualTo(USERNAME);