1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2018 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.
32
32
import org .springframework .http .server .ServletServerHttpResponse ;
33
33
import org .springframework .scheduling .TaskScheduler ;
34
34
import org .springframework .scheduling .concurrent .ThreadPoolTaskScheduler ;
35
+ import org .springframework .web .cors .CorsConfiguration ;
35
36
import org .springframework .web .socket .AbstractHttpRequestTests ;
36
37
import org .springframework .web .socket .WebSocketHandler ;
37
38
import org .springframework .web .socket .sockjs .SockJsException ;
@@ -176,7 +177,7 @@ public void handleInfoOptions() throws Exception {
176
177
}
177
178
178
179
@ Test // SPR-12226 and SPR-12660
179
- public void handleInfoOptionsWithOrigin () throws Exception {
180
+ public void handleInfoOptionsWithAllowedOrigin () throws Exception {
180
181
this .servletRequest .setServerName ("mydomain2.com" );
181
182
this .servletRequest .addHeader (HttpHeaders .ORIGIN , "http://mydomain2.com" );
182
183
this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "GET" );
@@ -196,10 +197,22 @@ public void handleInfoOptionsWithOrigin() throws Exception {
196
197
this .service .setAllowedOrigins (Arrays .asList ("*" ));
197
198
resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .NO_CONTENT );
198
199
assertNotNull (this .service .getCorsConfiguration (this .servletRequest ));
200
+ }
199
201
202
+ @ Test // SPR-16304
203
+ public void handleInfoOptionsWithForbiddenOrigin () throws Exception {
200
204
this .servletRequest .setServerName ("mydomain3.com" );
205
+ this .servletRequest .addHeader (HttpHeaders .ORIGIN , "http://mydomain2.com" );
206
+ this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "GET" );
207
+ this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_HEADERS , "Last-Modified" );
208
+ resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .FORBIDDEN );
209
+ CorsConfiguration corsConfiguration = this .service .getCorsConfiguration (this .servletRequest );
210
+ assertTrue (corsConfiguration .getAllowedOrigins ().isEmpty ());
211
+
201
212
this .service .setAllowedOrigins (Arrays .asList ("http://mydomain1.com" ));
202
213
resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .FORBIDDEN );
214
+ corsConfiguration = this .service .getCorsConfiguration (this .servletRequest );
215
+ assertEquals (Arrays .asList ("http://mydomain1.com" ), corsConfiguration .getAllowedOrigins ());
203
216
}
204
217
205
218
@ Test // SPR-12283
0 commit comments