diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java index a8d888d7..fc043cec 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/EnvironmentController.java @@ -103,13 +103,13 @@ public class EnvironmentController { this.acceptEmpty = acceptEmpty; } - @GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}", + @GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}", produces = MediaType.APPLICATION_JSON_VALUE) public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) { return getEnvironment(name, profiles, null, false); } - @GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}", + @GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}", produces = EnvironmentMediaType.V2_JSON) public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) { return getEnvironment(name, profiles, null, true); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java index 22523fe5..a0a82a2e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentControllerIntegrationTests.java @@ -21,6 +21,8 @@ import java.util.HashMap; import org.hamcrest.Matchers; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -40,8 +42,10 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; + /** * @author Dave Syer * @author Roy Clarkson @@ -87,6 +91,29 @@ class EnvironmentControllerIntegrationTests { verify(this.repository).findOne("foo", "dev-db", null, false); } + @ParameterizedTest + @ValueSource(strings = {"yml", "yaml", "json", "properties"}) + public void profileContainingExtensionKeyword(String extensionKeyword) throws Exception { + String profiles = "dev-" + extensionKeyword; + Environment dashEnvironment = new Environment("foo", profiles); + dashEnvironment.add(new PropertySource("foo", new HashMap<>())); + when(this.repository.findOne("foo", profiles, null, false)).thenReturn(dashEnvironment); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/" + profiles)) + .andExpect(MockMvcResultMatchers.status().isOk()); + verify(this.repository).findOne("foo", profiles, null, false); + } + + @ParameterizedTest + @ValueSource(strings = {"yml", "yaml", "json", "properties"}) + public void profileHavingAnExtension(String extensionKeyword) throws Exception { + String profiles = "dev." + extensionKeyword; + Environment dashEnvironment = new Environment("foo", profiles); + dashEnvironment.add(new PropertySource("foo", new HashMap<>())); + this.mvc.perform(MockMvcRequestBuilders.get("/foo/" + profiles)) + .andExpect(MockMvcResultMatchers.status().isNotFound()); + verifyNoInteractions(this.repository); + } + @Test public void propertiesNoLabel() throws Exception { when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);