|
|
|
@ -16,6 +16,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.cloudfoundry; |
|
|
|
package org.springframework.boot.actuate.cloudfoundry; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
@ -75,18 +77,20 @@ public class CloudFoundryActuatorAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void cloudFoundryPlatformActive() throws Exception { |
|
|
|
public void cloudFoundryPlatformActive() throws Exception { |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = x(); |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = getHandlerMapping(); |
|
|
|
assertThat(handlerMapping.getPrefix()).isEqualTo("/cloudfoundryapplication"); |
|
|
|
assertThat(handlerMapping.getPrefix()).isEqualTo("/cloudfoundryapplication"); |
|
|
|
CorsConfiguration corsConfiguration = (CorsConfiguration) ReflectionTestUtils |
|
|
|
CorsConfiguration corsConfiguration = (CorsConfiguration) ReflectionTestUtils |
|
|
|
.getField(handlerMapping, "corsConfiguration"); |
|
|
|
.getField(handlerMapping, "corsConfiguration"); |
|
|
|
assertThat(corsConfiguration.getAllowedOrigins()).contains("*"); |
|
|
|
assertThat(corsConfiguration.getAllowedOrigins()).contains("*"); |
|
|
|
assertThat(corsConfiguration.getAllowedMethods()).contains(HttpMethod.GET.name(), |
|
|
|
assertThat(corsConfiguration.getAllowedMethods()).contains(HttpMethod.GET.name(), |
|
|
|
HttpMethod.POST.name()); |
|
|
|
HttpMethod.POST.name()); |
|
|
|
|
|
|
|
assertThat(corsConfiguration.getAllowedHeaders() |
|
|
|
|
|
|
|
.containsAll(Arrays.asList("Authorization", "X-Cf-App-Instance"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void cloudFoundryPlatformActiveSetsApplicationId() throws Exception { |
|
|
|
public void cloudFoundryPlatformActiveSetsApplicationId() throws Exception { |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = x(); |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = getHandlerMapping(); |
|
|
|
Object interceptor = ReflectionTestUtils.getField(handlerMapping, |
|
|
|
Object interceptor = ReflectionTestUtils.getField(handlerMapping, |
|
|
|
"securityInterceptor"); |
|
|
|
"securityInterceptor"); |
|
|
|
String applicationId = (String) ReflectionTestUtils.getField(interceptor, |
|
|
|
String applicationId = (String) ReflectionTestUtils.getField(interceptor, |
|
|
|
@ -96,7 +100,7 @@ public class CloudFoundryActuatorAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void cloudFoundryPlatformActiveSetsCloudControllerUrl() throws Exception { |
|
|
|
public void cloudFoundryPlatformActiveSetsCloudControllerUrl() throws Exception { |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = x(); |
|
|
|
CloudFoundryEndpointHandlerMapping handlerMapping = getHandlerMapping(); |
|
|
|
Object interceptor = ReflectionTestUtils.getField(handlerMapping, |
|
|
|
Object interceptor = ReflectionTestUtils.getField(handlerMapping, |
|
|
|
"securityInterceptor"); |
|
|
|
"securityInterceptor"); |
|
|
|
Object interceptorSecurityService = ReflectionTestUtils.getField(interceptor, |
|
|
|
Object interceptorSecurityService = ReflectionTestUtils.getField(interceptor, |
|
|
|
@ -123,7 +127,7 @@ public class CloudFoundryActuatorAutoConfigurationTests { |
|
|
|
assertThat(interceptorSecurityService).isNull(); |
|
|
|
assertThat(interceptorSecurityService).isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CloudFoundryEndpointHandlerMapping x() { |
|
|
|
private CloudFoundryEndpointHandlerMapping getHandlerMapping() { |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---", |
|
|
|
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:---", |
|
|
|
"vcap.application.application_id:my-app-id", |
|
|
|
"vcap.application.application_id:my-app-id", |
|
|
|
"vcap.application.cf_api:http://my-cloud-controller.com"); |
|
|
|
"vcap.application.cf_api:http://my-cloud-controller.com"); |
|
|
|
|