Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public void loadConfigWhenMultipleWebSecurityConfigurationThenContextLoads() {
// SEC-2773
@Test
public void getMethodDelegatingApplicationListenerWhenWebSecurityConfigurationThenIsStatic() {
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener", null);
Method method = ClassUtils.getMethod(WebSecurityConfiguration.class, "delegatingApplicationListener",
(Class<?>[]) null);
assertThat(Modifier.isStatic(method.getModifiers())).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class OneTimeTokenAuthenticationTokenTests {

// gh-18095
@Test
@SuppressWarnings("removal")
void shouldBeAbleToDeserializeFromJsonWithDefaultTypingActivated() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class OneTimeTokenReactiveAuthenticationManagerTests {
private static final String TOKEN = "token";

@Test
@SuppressWarnings("removal")
public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException() {
ReactiveUserDetailsService userDetailsService = mock(ReactiveUserDetailsService.class);
// @formatter:off
Expand All @@ -68,6 +69,7 @@ public void constructorWhenOneTimeTokenServiceNullThenIllegalArgumentException()
}

@Test
@SuppressWarnings("removal")
public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
// @formatter:off
Expand All @@ -77,6 +79,7 @@ public void constructorWhenUserDetailsServiceNullThenIllegalArgumentException()
}

@Test
@SuppressWarnings("removal")
void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
Expand All @@ -103,6 +106,7 @@ void authenticateWhenOneTimeTokenAuthenticationTokenIsPresentThenSuccess() {
}

@Test
@SuppressWarnings("removal")
void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
Expand All @@ -120,6 +124,7 @@ void authenticateWhenInvalidOneTimeTokenAuthenticationTokenIsPresentThenFail() {
}

@Test
@SuppressWarnings("removal")
void authenticateWhenIncorrectTypeOfAuthenticationIsPresentThenFail() {
ReactiveOneTimeTokenService oneTimeTokenService = mock(ReactiveOneTimeTokenService.class);
given(oneTimeTokenService.consume(ArgumentMatchers.any(OneTimeTokenAuthenticationToken.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void hasAuthorityWhenNullThenException() {

@Test
public void hasAnyRoleWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole(null))
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyRole((String[]) null))
.withMessage("roles cannot be empty");
}

Expand Down Expand Up @@ -97,7 +97,8 @@ public void hasAnyRoleWhenContainRoleWithRolePrefixThenException() {

@Test
public void hasAnyAuthorityWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority(null))
assertThatIllegalArgumentException()
.isThrownBy(() -> AuthorityAuthorizationManager.hasAnyAuthority((String[]) null))
.withMessage("authorities cannot be empty");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Map::class.java)
val result = (filtered as Map<String, String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Map<String, String>
assertThat(result).hasSize(1)
assertThat(result).containsKey("key2")
assertThat(result).containsValue("value2")
Expand All @@ -95,7 +96,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Map::class.java)
val result = (filtered as Map<String, String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Map<String, String>
assertThat(result).hasSize(0)
}

Expand All @@ -119,7 +121,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Collection::class.java)
val result = (filtered as Collection<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Collection<String>
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
}
Expand All @@ -140,7 +143,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Collection::class.java)
val result = (filtered as Collection<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Collection<String>
assertThat(result).hasSize(0)
}

Expand All @@ -164,7 +168,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Array<String>::class.java)
val result = (filtered as Array<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Array<String>
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
}
Expand All @@ -185,7 +190,8 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Array<String>::class.java)
val result = (filtered as Array<String>)
@Suppress("UNCHECKED_CAST")
val result = filtered as Array<String>
assertThat(result).hasSize(0)
}

Expand All @@ -209,6 +215,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(1)
assertThat(result).contains("string2")
Expand All @@ -230,6 +237,7 @@ class DefaultMethodSecurityExpressionHandlerKotlinTests {
)

assertThat(filtered).isInstanceOf(Stream::class.java)
@Suppress("UNCHECKED_CAST")
val result = (filtered as Stream<String>).toList()
assertThat(result).hasSize(0)
}
Expand Down
1 change: 1 addition & 0 deletions test/spring-security-test.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'security-nullability'
id 'javadoc-warnings-error'
id 'compile-warnings-error'
}

apply plugin: 'io.spring.convention.spring-module'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void before() {
}

@Test
@SuppressWarnings("removal")
public void testDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand All @@ -78,6 +79,7 @@ public void testDefaultEntryPoint() throws Exception {
}

@Test
@SuppressWarnings("removal")
public void testFirstEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand All @@ -96,6 +98,7 @@ public void testFirstEntryPoint() throws Exception {
}

@Test
@SuppressWarnings("removal")
public void testSecondEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand All @@ -114,20 +117,23 @@ public void testSecondEntryPoint() throws Exception {
}

@Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullEntryPoints() {
List<RequestMatcherEntry<AuthenticationEntryPoint>> entryPoints = null;
assertThatIllegalArgumentException().isThrownBy(
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
}

@Test
@SuppressWarnings("removal")
public void constructorAepListWhenEmptyEntryPoints() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class),
Collections.emptyList()));
}

@Test
@SuppressWarnings("removal")
public void constructorAepListWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class);
Expand All @@ -138,20 +144,23 @@ public void constructorAepListWhenNullDefaultEntryPoint() {
}

@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = null;
assertThatIllegalArgumentException().isThrownBy(
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
}

@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenEmptyEntryPoints() {
RequestMatcherEntry<AuthenticationEntryPoint>[] entryPoints = new RequestMatcherEntry[0];
assertThatIllegalArgumentException().isThrownBy(
() -> new DelegatingAuthenticationEntryPoint(mock(AuthenticationEntryPoint.class), entryPoints));
}

@Test
@SuppressWarnings("removal")
public void constructorAepVargsWhenNullDefaultEntryPoint() {
AuthenticationEntryPoint entryPoint = mock(AuthenticationEntryPoint.class);
RequestMatcher matcher = mock(RequestMatcher.class);
Expand All @@ -162,6 +171,7 @@ public void constructorAepVargsWhenNullDefaultEntryPoint() {
}

@Test
@SuppressWarnings("removal")
public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand All @@ -174,6 +184,7 @@ public void commenceWhenNoMatchThenDefaultEntryPoint() throws Exception {
}

@Test
@SuppressWarnings("removal")
public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand All @@ -192,6 +203,7 @@ public void commenceWhenMatchFirstEntryPointThenOthersNotInvoked() throws Except
}

@Test
@SuppressWarnings("removal")
public void commenceWhenSecondMatchesThenDefaultNotInvoked() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
Expand Down Expand Up @@ -220,6 +232,7 @@ void builderWhenDefaultNullAndSingleEntryPointThenReturnsSingle() {
}

@Test
@SuppressWarnings("removal")
void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOException {
AuthenticationEntryPoint firstEntryPoint = mock(AuthenticationEntryPoint.class);
AuthenticationEntryPoint secondEntryPoint = mock(AuthenticationEntryPoint.class);
Expand All @@ -237,6 +250,7 @@ void builderWhenDefaultNullThenFirstIsDefault() throws ServletException, IOExcep
}

@Test
@SuppressWarnings("removal")
void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
AuthenticationEntryPoint defaultEntryPoint = mock(AuthenticationEntryPoint.class);

Expand All @@ -248,6 +262,7 @@ void builderWhenDefaultAndEmptyEntryPointsThenReturnsDefault() {
}

@Test
@SuppressWarnings("removal")
void builderWhenNoEntryPointsThenIllegalStateException() {
DelegatingAuthenticationEntryPoint.Builder builder = DelegatingAuthenticationEntryPoint.builder();
assertThatIllegalStateException().isThrownBy(builder::build);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ void setUp() {
}

@Test
@SuppressWarnings("removal")
void setAuthenticationConverterWhenNullThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setAuthenticationConverter(null));
}

@Test
@SuppressWarnings("removal")
void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Expand All @@ -85,6 +87,7 @@ void doFilterWhenUrlDoesNotMatchThenContinues() throws ServletException, IOExcep
}

@Test
@SuppressWarnings("removal")
void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOException {
OneTimeTokenAuthenticationConverter converter = mock(OneTimeTokenAuthenticationConverter.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Expand All @@ -95,13 +98,15 @@ void doFilterWhenMethodDoesNotMatchThenContinues() throws ServletException, IOEx
}

@Test
@SuppressWarnings("removal")
void doFilterWhenMissingTokenThenPropagatesRequest() throws ServletException, IOException {
FilterChain chain = mock(FilterChain.class);
this.filter.doFilter(post("/login/ott").buildRequest(new MockServletContext()), this.response, chain);
verify(chain).doFilter(any(), any());
}

@Test
@SuppressWarnings("removal")
void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any())).willThrow(new BadCredentialsException("invalid token"));
this.filter.doFilter(
Expand All @@ -112,6 +117,7 @@ void doFilterWhenInvalidTokenThenUnauthorized() throws ServletException, IOExcep
}

@Test
@SuppressWarnings("removal")
void doFilterWhenValidThenRedirectsToSavedRequest() throws ServletException, IOException {
given(this.authenticationManager.authenticate(any()))
.willReturn(OneTimeTokenAuthenticationToken.authenticated("username", AuthorityUtils.NO_AUTHORITIES));
Expand Down
Loading