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.
31
31
import org .springframework .http .server .ServletServerHttpResponse ;
32
32
import org .springframework .scheduling .TaskScheduler ;
33
33
import org .springframework .scheduling .concurrent .ThreadPoolTaskScheduler ;
34
+ import org .springframework .web .cors .CorsConfiguration ;
34
35
import org .springframework .web .socket .AbstractHttpRequestTests ;
35
36
import org .springframework .web .socket .WebSocketHandler ;
36
37
import org .springframework .web .socket .sockjs .SockJsException ;
@@ -172,7 +173,7 @@ public void handleInfoOptions() throws Exception {
172
173
}
173
174
174
175
@ Test // SPR-12226 and SPR-12660
175
- public void handleInfoOptionsWithOrigin () throws Exception {
176
+ public void handleInfoOptionsWithAllowedOrigin () throws Exception {
176
177
this .servletRequest .setServerName ("mydomain2.com" );
177
178
this .servletRequest .addHeader (HttpHeaders .ORIGIN , "http://mydomain2.com" );
178
179
this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "GET" );
@@ -191,10 +192,22 @@ public void handleInfoOptionsWithOrigin() throws Exception {
191
192
this .service .setAllowedOrigins (Arrays .asList ("*" ));
192
193
resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .NO_CONTENT );
193
194
assertNotNull (this .service .getCorsConfiguration (this .servletRequest ));
195
+ }
194
196
197
+ @ Test // SPR-16304
198
+ public void handleInfoOptionsWithForbiddenOrigin () throws Exception {
195
199
this .servletRequest .setServerName ("mydomain3.com" );
200
+ this .servletRequest .addHeader (HttpHeaders .ORIGIN , "http://mydomain2.com" );
201
+ this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_METHOD , "GET" );
202
+ this .servletRequest .addHeader (HttpHeaders .ACCESS_CONTROL_REQUEST_HEADERS , "Last-Modified" );
203
+ resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .FORBIDDEN );
204
+ CorsConfiguration corsConfiguration = this .service .getCorsConfiguration (this .servletRequest );
205
+ assertTrue (corsConfiguration .getAllowedOrigins ().isEmpty ());
206
+
196
207
this .service .setAllowedOrigins (Arrays .asList ("http://mydomain1.com" ));
197
208
resetResponseAndHandleRequest ("OPTIONS" , "/echo/info" , HttpStatus .FORBIDDEN );
209
+ corsConfiguration = this .service .getCorsConfiguration (this .servletRequest );
210
+ assertEquals (Arrays .asList ("http://mydomain1.com" ), corsConfiguration .getAllowedOrigins ());
198
211
}
199
212
200
213
@ Test // SPR-12283
0 commit comments