|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 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.
|
|
72 | 72 | import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
73 | 73 | import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
74 | 74 | import org.springframework.web.context.request.ServletWebRequest;
|
| 75 | +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
75 | 76 | import org.springframework.web.filter.FormContentFilter;
|
76 | 77 | import org.springframework.web.filter.HiddenHttpMethodFilter;
|
77 | 78 | import org.springframework.web.filter.RequestContextFilter;
|
|
83 | 84 | import org.springframework.web.servlet.ViewResolver;
|
84 | 85 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
|
85 | 86 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
| 87 | +import org.springframework.web.servlet.config.annotation.CorsRegistry; |
86 | 88 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
87 | 89 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
88 | 90 | import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
@@ -554,7 +556,19 @@ public void welcomePageHandlerMappingIsAutoConfigured() {
|
554 | 556 | this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
|
555 | 557 | .run((context) -> {
|
556 | 558 | assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
557 |
| - assertThat(context.getBean(WelcomePageHandlerMapping.class).getRootHandler()).isNotNull(); |
| 559 | + WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); |
| 560 | + assertThat(bean.getRootHandler()).isNotNull(); |
| 561 | + }); |
| 562 | + } |
| 563 | + |
| 564 | + @Test |
| 565 | + public void welcomePageHandlerIncludesCorsConfiguration() { |
| 566 | + this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/") |
| 567 | + .withUserConfiguration(CorsConfigurer.class).run((context) -> { |
| 568 | + WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); |
| 569 | + UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils |
| 570 | + .getField(bean, "corsConfigurationSource"); |
| 571 | + assertThat(source.getCorsConfigurations()).containsKey("/**"); |
558 | 572 | });
|
559 | 573 | }
|
560 | 574 |
|
@@ -1096,4 +1110,14 @@ public FilterRegistrationBean<RequestContextFilter> customRequestContextFilterRe
|
1096 | 1110 |
|
1097 | 1111 | }
|
1098 | 1112 |
|
| 1113 | + @Configuration |
| 1114 | + static class CorsConfigurer implements WebMvcConfigurer { |
| 1115 | + |
| 1116 | + @Override |
| 1117 | + public void addCorsMappings(CorsRegistry registry) { |
| 1118 | + registry.addMapping("/**").allowedMethods("GET"); |
| 1119 | + } |
| 1120 | + |
| 1121 | + } |
| 1122 | + |
1099 | 1123 | }
|
0 commit comments