Feature/organization project level enablement (#814)
* Changes to provide partial functionality for Issue #779 * Corrected formatting * Additional tests to ensure backwards compatibility * Corrected test * Further testing to try to address code coverage concerns * Additional tests to hopefully aid in code coverage diff * Expect exceptions for null name (handle branch coverage)
This commit is contained in:
committed by
Spencer Gibb
parent
ac76f6e970
commit
b333bd4ff9
@@ -87,6 +87,11 @@ public class ResourceController {
|
||||
|
||||
synchronized String retrieve(String name, String profile, String label, String path,
|
||||
boolean resolvePlaceholders) throws IOException {
|
||||
if (name != null && name.contains("(_)")) {
|
||||
// "(_)" is uncommon in a git repo name, but "/" cannot be matched
|
||||
// by Spring MVC
|
||||
name = name.replace("(_)", "/");
|
||||
}
|
||||
if (label != null && label.contains("(_)")) {
|
||||
// "(_)" is uncommon in a git branch name, but "/" cannot be matched
|
||||
// by Spring MVC
|
||||
@@ -116,6 +121,11 @@ public class ResourceController {
|
||||
|
||||
synchronized byte[] binary(String name, String profile, String label, String path)
|
||||
throws IOException {
|
||||
if (name != null && name.contains("(_)")) {
|
||||
// "(_)" is uncommon in a git repo name, but "/" cannot be matched
|
||||
// by Spring MVC
|
||||
name = name.replace("(_)", "/");
|
||||
}
|
||||
if (label != null && label.contains("(_)")) {
|
||||
// "(_)" is uncommon in a git branch name, but "/" cannot be matched
|
||||
// by Spring MVC
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.config.server.resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -87,6 +88,52 @@ public class ResourceControllerTests {
|
||||
assertEquals("foo: ${foo}", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationAndLabelPlaceholdersWithoutSlash() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}/{label}");
|
||||
String resource = this.controller.retrieve("dev", "bar", "spam", "foo.txt", true);
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPlaceholderWithSlash() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}");
|
||||
String resource = this.controller.retrieve("dev(_)spam", "bar", "", "foo.txt", true);
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPlaceholderWithSlashNullLabel() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}");
|
||||
String resource = this.controller.retrieve("dev(_)spam", "bar", null, "foo.txt", true);
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelPlaceholderWithSlash() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{label}");
|
||||
String resource = this.controller.retrieve("dev", "bar", "dev(_)spam", "foo.txt", true);
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void profilePlaceholderNullLabel() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{profile}");
|
||||
String resource = this.controller.retrieve("bar", "dev", null, "spam/foo.txt", true);
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullNameAndLabel() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test");
|
||||
try {
|
||||
this.controller.retrieve(null, "foo", "bar", "spam/foo.txt", true);
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelWithSlash() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test");
|
||||
@@ -143,6 +190,52 @@ public class ResourceControllerTests {
|
||||
assertEquals("foo: dev_bar/spam", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationAndLabelPlaceholdersWithoutSlashForBinary() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}/{label}");
|
||||
byte[] resource = this.controller.binary("dev", "bar", "spam", "foo.txt");
|
||||
assertEquals("foo: dev_bar/spam", new String(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPlaceholderWithSlashForBinary() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}");
|
||||
byte[] resource = this.controller.binary("dev(_)spam", "bar", "", "foo.txt");
|
||||
assertEquals("foo: dev_bar/spam", new String(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationPlaceholderWithSlashForBinaryNullLabel() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{application}");
|
||||
byte[] resource = this.controller.binary("dev(_)spam", "bar", null, "foo.txt");
|
||||
assertEquals("foo: dev_bar/spam", new String(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelPlaceholderWithSlashForBinary() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{label}");
|
||||
byte[] resource = this.controller.binary("dev", "bar", "dev(_)spam", "foo.txt");
|
||||
assertEquals("foo: dev_bar/spam", new String(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void profilePlaceholderForBinaryNullLabel() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test/{profile}");
|
||||
byte[] resource = this.controller.binary("bar", "dev", null, "spam/foo.txt");
|
||||
assertEquals("foo: dev_bar/spam", new String(resource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forBinaryNullName() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test");
|
||||
try {
|
||||
this.controller.binary(null, "foo", "bar", "spam/foo.txt");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelWithSlashForBinary() throws Exception {
|
||||
this.environmentRepository.setSearchLocations("classpath:/test");
|
||||
|
||||
Reference in New Issue
Block a user