Update environment controller to specifically capture all profile names unless they are specific file extensions (#2059)

Fixes #2058
This commit is contained in:
Ryan Baxter
2022-03-10 19:55:00 -05:00
committed by GitHub
parent be7a22ce60
commit 5fe6690877
2 changed files with 14 additions and 2 deletions

View File

@@ -104,12 +104,14 @@ public class EnvironmentController {
this.acceptEmpty = acceptEmpty;
}
@GetMapping(path = "/{name}/{profiles:[^-]+}", produces = MediaType.APPLICATION_JSON_VALUE)
@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:[^-]+}", produces = EnvironmentMediaType.V2_JSON)
@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);
}

View File

@@ -77,6 +77,16 @@ class EnvironmentControllerIntegrationTests {
verify(this.repository).findOne("foo", "default", null, false);
}
@Test
public void profileWithDash() throws Exception {
Environment dashEnvironment = new Environment("foo", "dev-db");
dashEnvironment.add(new PropertySource("foo", new HashMap<>()));
when(this.repository.findOne("foo", "dev-db", null, false)).thenReturn(dashEnvironment);
this.mvc.perform(MockMvcRequestBuilders.get("/foo/dev-db"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(this.repository).findOne("foo", "dev-db", null, false);
}
@Test
public void propertiesNoLabel() throws Exception {
when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);