Add POST to allowed CORS methods for CF actuators
Update CORS configuration to support POST. See gh-7108
This commit is contained in:
parent
1005feb27d
commit
862a06eb7a
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.actuate.cloudfoundry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -32,6 +33,7 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
|
@ -86,6 +88,8 @@ public class CloudFoundryActuatorAutoConfiguration {
|
|||
private CorsConfiguration getCorsConfiguration() {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL);
|
||||
corsConfiguration.setAllowedMethods(
|
||||
Arrays.asList(HttpMethod.GET.name(), HttpMethod.POST.name()));
|
||||
return corsConfiguration;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,11 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi
|
|||
import org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
@ -75,6 +77,11 @@ public class CloudFoundryActuatorAutoConfigurationTests {
|
|||
public void cloudFoundryPlatformActive() throws Exception {
|
||||
CloudFoundryEndpointHandlerMapping handlerMapping = x();
|
||||
assertThat(handlerMapping.getPrefix()).isEqualTo("/cloudfoundryapplication");
|
||||
CorsConfiguration corsConfiguration = (CorsConfiguration) ReflectionTestUtils
|
||||
.getField(handlerMapping, "corsConfiguration");
|
||||
assertThat(corsConfiguration.getAllowedOrigins()).contains("*");
|
||||
assertThat(corsConfiguration.getAllowedMethods()).contains(HttpMethod.GET.name(),
|
||||
HttpMethod.POST.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue