1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
29
29
import org .mockito .junit .jupiter .MockitoExtension ;
30
30
31
31
import org .springframework .context .ApplicationContext ;
32
- import org .springframework .core . ResolvableType ;
32
+ import org .springframework .context . support . GenericApplicationContext ;
33
33
import org .springframework .http .HttpHeaders ;
34
34
import org .springframework .security .test .web .reactive .server .WebTestClientBuilder ;
35
35
import org .springframework .test .web .reactive .server .FluxExchangeResult ;
@@ -51,7 +51,6 @@ public class CorsSpecTests {
51
51
@ Mock
52
52
private CorsConfigurationSource source ;
53
53
54
- @ Mock
55
54
private ApplicationContext context ;
56
55
57
56
ServerHttpSecurity http ;
@@ -62,6 +61,8 @@ public class CorsSpecTests {
62
61
63
62
@ BeforeEach
64
63
public void setup () {
64
+ this .context = new GenericApplicationContext ();
65
+ ((GenericApplicationContext ) this .context ).refresh ();
65
66
this .http = new TestingServerHttpSecurity ().applicationContext (this .context );
66
67
}
67
68
@@ -92,17 +93,14 @@ public void corsWhenEnabledInLambdaThenAccessControlAllowOriginAndSecurityHeader
92
93
@ Test
93
94
public void corsWhenCorsConfigurationSourceBeanThenAccessControlAllowOriginAndSecurityHeaders () {
94
95
givenGetCorsConfigurationWillReturnWildcard ();
95
- given (this .context .getBeanNamesForType (any (ResolvableType .class ))).willReturn (new String [] { "source" },
96
- new String [0 ]);
97
- given (this .context .getBean ("source" )).willReturn (this .source );
96
+ ((GenericApplicationContext ) this .context ).registerBean (CorsConfigurationSource .class , () -> this .source );
98
97
this .expectedHeaders .set ("Access-Control-Allow-Origin" , "*" );
99
98
this .expectedHeaders .set ("X-Frame-Options" , "DENY" );
100
99
assertHeaders ();
101
100
}
102
101
103
102
@ Test
104
103
public void corsWhenNoConfigurationSourceThenNoCorsHeaders () {
105
- given (this .context .getBeanNamesForType (any (ResolvableType .class ))).willReturn (new String [0 ]);
106
104
this .headerNamesNotPresent .add ("Access-Control-Allow-Origin" );
107
105
assertHeaders ();
108
106
}
0 commit comments