Avoid registering CorsConfiguration for methods without @CrossOrigin

Issue: SPR-12931
This commit is contained in:
Sebastien Deleuze
2015-04-20 09:03:25 +02:00
parent e829b2aa1d
commit 9a65eec36f
2 changed files with 30 additions and 5 deletions

View File

@@ -66,7 +66,7 @@ public class CrossOriginTests {
}
@Test
public void noAnnotation() throws Exception {
public void noAnnotationWithoutOrigin() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/no");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
@@ -74,6 +74,25 @@ public class CrossOriginTests {
assertNull(config);
}
@Test // SPR-12931
public void noAnnotationWithOrigin() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
this.request.setRequestURI("/no");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
CorsConfiguration config = getCorsConfiguration(chain, false);
assertNull(config);
}
@Test // SPR-12931
public void noAnnotationPostWithOrigin() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
this.request.setMethod("POST");
this.request.setRequestURI("/no");
HandlerExecutionChain chain = this.handlerMapping.getHandler(request);
CorsConfiguration config = getCorsConfiguration(chain, false);
assertNull(config);
}
@Test
public void defaultAnnotation() throws Exception {
this.handlerMapping.registerHandler(new MethodLevelController());
@@ -203,6 +222,10 @@ public class CrossOriginTests {
public void noAnnotation() {
}
@RequestMapping(value = "/no", method = RequestMethod.POST)
public void noAnnotationPost() {
}
@CrossOrigin
@RequestMapping(value = "/default", method = RequestMethod.GET)
public void defaultAnnotation() {