37
37
38
38
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
39
39
import static org .mockito .ArgumentMatchers .any ;
40
- import static org .mockito .Mockito .*;
40
+ import static org .mockito .Mockito .mock ;
41
+ import static org .mockito .Mockito .spy ;
42
+ import static org .mockito .Mockito .verify ;
41
43
import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .csrf ;
42
44
import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .user ;
43
- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
45
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
46
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
47
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
48
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .put ;
44
49
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .redirectedUrl ;
45
50
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
46
51
@@ -77,6 +82,26 @@ protected void configure(HttpSecurity http) throws Exception {
77
82
}
78
83
}
79
84
85
+ @ Test
86
+ public void configureWhenDefaultLogoutSuccessHandlerForHasNullLogoutHandlerInLambdaThenException () {
87
+ assertThatThrownBy (() -> this .spring .register (NullLogoutSuccessHandlerInLambdaConfig .class ).autowire ())
88
+ .isInstanceOf (BeanCreationException .class )
89
+ .hasRootCauseInstanceOf (IllegalArgumentException .class );
90
+ }
91
+
92
+ @ EnableWebSecurity
93
+ static class NullLogoutSuccessHandlerInLambdaConfig extends WebSecurityConfigurerAdapter {
94
+ @ Override
95
+ protected void configure (HttpSecurity http ) throws Exception {
96
+ // @formatter:off
97
+ http
98
+ .logout (logout ->
99
+ logout .defaultLogoutSuccessHandlerFor (null , mock (RequestMatcher .class ))
100
+ );
101
+ // @formatter:on
102
+ }
103
+ }
104
+
80
105
@ Test
81
106
public void configureWhenDefaultLogoutSuccessHandlerForHasNullMatcherThenException () {
82
107
assertThatThrownBy (() -> this .spring .register (NullMatcherConfig .class ).autowire ())
@@ -96,6 +121,26 @@ protected void configure(HttpSecurity http) throws Exception {
96
121
}
97
122
}
98
123
124
+ @ Test
125
+ public void configureWhenDefaultLogoutSuccessHandlerForHasNullMatcherInLambdaThenException () {
126
+ assertThatThrownBy (() -> this .spring .register (NullMatcherInLambdaConfig .class ).autowire ())
127
+ .isInstanceOf (BeanCreationException .class )
128
+ .hasRootCauseInstanceOf (IllegalArgumentException .class );
129
+ }
130
+
131
+ @ EnableWebSecurity
132
+ static class NullMatcherInLambdaConfig extends WebSecurityConfigurerAdapter {
133
+ @ Override
134
+ protected void configure (HttpSecurity http ) throws Exception {
135
+ // @formatter:off
136
+ http
137
+ .logout (logout ->
138
+ logout .defaultLogoutSuccessHandlerFor (mock (LogoutSuccessHandler .class ), null )
139
+ );
140
+ // @formatter:on
141
+ }
142
+ }
143
+
99
144
@ Test
100
145
public void configureWhenRegisteringObjectPostProcessorThenInvokedOnLogoutFilter () {
101
146
this .spring .register (ObjectPostProcessorConfig .class ).autowire ();
@@ -263,6 +308,29 @@ protected void configure(HttpSecurity http) throws Exception {
263
308
}
264
309
}
265
310
311
+ @ Test
312
+ public void logoutWhenCustomLogoutUrlInLambdaThenRedirectsToLogin () throws Exception {
313
+ this .spring .register (CsrfDisabledAndCustomLogoutInLambdaConfig .class ).autowire ();
314
+
315
+ this .mvc .perform (get ("/custom/logout" ))
316
+ .andExpect (status ().isFound ())
317
+ .andExpect (redirectedUrl ("/login?logout" ));
318
+ }
319
+
320
+ @ EnableWebSecurity
321
+ static class CsrfDisabledAndCustomLogoutInLambdaConfig extends WebSecurityConfigurerAdapter {
322
+
323
+ @ Override
324
+ protected void configure (HttpSecurity http ) throws Exception {
325
+ // @formatter:off
326
+ http
327
+ .csrf ()
328
+ .disable ()
329
+ .logout (logout -> logout .logoutUrl ("/custom/logout" ));
330
+ // @formatter:on
331
+ }
332
+ }
333
+
266
334
// SEC-3170
267
335
@ Test
268
336
public void configureWhenLogoutHandlerNullThenException () {
@@ -283,6 +351,24 @@ protected void configure(HttpSecurity http) throws Exception {
283
351
}
284
352
}
285
353
354
+ @ Test
355
+ public void configureWhenLogoutHandlerNullInLambdaThenException () {
356
+ assertThatThrownBy (() -> this .spring .register (NullLogoutHandlerInLambdaConfig .class ).autowire ())
357
+ .isInstanceOf (BeanCreationException .class )
358
+ .hasRootCauseInstanceOf (IllegalArgumentException .class );
359
+ }
360
+
361
+ @ EnableWebSecurity
362
+ static class NullLogoutHandlerInLambdaConfig extends WebSecurityConfigurerAdapter {
363
+ @ Override
364
+ protected void configure (HttpSecurity http ) throws Exception {
365
+ // @formatter:off
366
+ http
367
+ .logout (logout -> logout .addLogoutHandler (null ));
368
+ // @formatter:on
369
+ }
370
+ }
371
+
286
372
// SEC-3170
287
373
@ Test
288
374
public void rememberMeWhenRememberMeServicesNotLogoutHandlerThenRedirectsToLogin () throws Exception {
0 commit comments