Skip to content

Commit

Permalink
Merge branch '2.1.x' into 2.2.x
Browse files Browse the repository at this point in the history
Closes gh-21070
  • Loading branch information
philwebb committed Apr 21, 2020
2 parents 8cbd7f5 + 6011470 commit 7d0b14f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -402,6 +402,7 @@ public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext ap
new TemplateAvailabilityProviders(applicationContext), applicationContext, getWelcomePage(),
this.mvcProperties.getStaticPathPattern());
welcomePageHandlerMapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider));
welcomePageHandlerMapping.setCorsConfigurations(getCorsConfigurations());
return welcomePageHandlerMapping;
}

Expand Down
Expand Up @@ -76,6 +76,7 @@
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.FormContentFilter;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.filter.RequestContextFilter;
Expand All @@ -87,6 +88,7 @@
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
Expand Down Expand Up @@ -536,7 +538,19 @@ void welcomePageHandlerMappingIsAutoConfigured() {
this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
.run((context) -> {
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
assertThat(context.getBean(WelcomePageHandlerMapping.class).getRootHandler()).isNotNull();
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
assertThat(bean.getRootHandler()).isNotNull();
});
}

@Test
void welcomePageHandlerIncludesCorsConfiguration() {
this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
.withUserConfiguration(CorsConfigurer.class).run((context) -> {
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils
.getField(bean, "corsConfigurationSource");
assertThat(source.getCorsConfigurations()).containsKey("/**");
});
}

Expand Down Expand Up @@ -1157,4 +1171,14 @@ public Example parse(String source, Locale locale) {

}

@Configuration
static class CorsConfigurer implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("GET");
}

}

}

0 comments on commit 7d0b14f

Please sign in to comment.