Fix OAuth2AuthorizationRequestRedirectFilter constructor tests

OAuth2AuthorizationRequestRedirectFilterTests attempt to validate the constructors throw IllegalArgumentException if an invalid argument is provided, but
they are flawed because it is the relective code that is throwing the IllegalArgumentException due to imprecise type information.

This changes the tests to no longer use unnecessary reflection and casts the types so that the type information is used to target the correct
constructor.

Closes gh-18507
This commit is contained in:
Robert Winch 2026-01-14 09:32:54 -06:00
parent 30d6b3a02b
commit 48f958cbbf
No known key found for this signature in database

View File

@ -16,7 +16,6 @@
package org.springframework.security.oauth2.client.web;
import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
@ -43,7 +42,6 @@ import org.springframework.security.oauth2.client.registration.TestClientRegistr
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.util.ClassUtils;
import org.springframework.web.util.UriComponentsBuilder;
import static org.assertj.core.api.Assertions.assertThat;
@ -87,9 +85,8 @@ public class OAuth2AuthorizationRequestRedirectFilterTests {
@Test
public void constructorWhenClientRegistrationRepositoryIsNullThenThrowIllegalArgumentException() {
Constructor<OAuth2AuthorizationRequestRedirectFilter> constructor = ClassUtils.getConstructorIfAvailable(
OAuth2AuthorizationRequestRedirectFilter.class, ClientRegistrationRepository.class);
assertThatIllegalArgumentException().isThrownBy(() -> constructor.newInstance(null));
assertThatIllegalArgumentException()
.isThrownBy(() -> new OAuth2AuthorizationRequestRedirectFilter((ClientRegistrationRepository) null));
}
@Test
@ -100,9 +97,8 @@ public class OAuth2AuthorizationRequestRedirectFilterTests {
@Test
public void constructorWhenAuthorizationRequestResolverIsNullThenThrowIllegalArgumentException() {
Constructor<OAuth2AuthorizationRequestRedirectFilter> constructor = ClassUtils.getConstructorIfAvailable(
OAuth2AuthorizationRequestRedirectFilter.class, OAuth2AuthorizationRequestResolver.class);
assertThatIllegalArgumentException().isThrownBy(() -> constructor.newInstance(null));
assertThatIllegalArgumentException()
.isThrownBy(() -> new OAuth2AuthorizationRequestRedirectFilter((OAuth2AuthorizationRequestResolver) null));
}
@Test