Merge branch 'master' into resource-default-label
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -11,7 +11,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>1.3.5.RELEASE</version>
|
||||
<version>1.3.5.BUILD-SNAPSHOT</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<scm>
|
||||
|
||||
@@ -117,7 +117,7 @@ class EnvironmentPrefixHelper {
|
||||
if (value.contains(ESCAPE)) {
|
||||
return value.substring(value.indexOf(ESCAPE) + ESCAPE.length());
|
||||
}
|
||||
return value.substring(value.lastIndexOf("}") + 1);
|
||||
return value.replaceFirst("^(\\{.*?:.*?\\})+", "");
|
||||
}
|
||||
|
||||
private String removeEnvironmentPrefix(String input) {
|
||||
|
||||
@@ -102,6 +102,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
|
||||
@@ -131,6 +136,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
|
||||
|
||||
@@ -135,6 +135,20 @@ public class EncryptionControllerTests {
|
||||
assertThat("Prefix must be stripped prior to encrypt", captor.getValue(), not(containsString("{key:test}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptDecyptTextWithCurlyBrace() {
|
||||
this.controller = new EncryptionController(
|
||||
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
|
||||
|
||||
String plain = "textwith}brace";
|
||||
|
||||
String cipher = this.controller.encrypt(plain,
|
||||
MediaType.APPLICATION_FORM_URLENCODED);
|
||||
String decrypt = this.controller.decrypt(cipher,
|
||||
MediaType.APPLICATION_FORM_URLENCODED);
|
||||
assertEquals(plain, decrypt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addEnvironment() {
|
||||
TextEncryptorLocator locator = new TextEncryptorLocator() {
|
||||
|
||||
@@ -81,4 +81,14 @@ public class EnvironmentPrefixHelperTests {
|
||||
assertEquals("mykey", keys.get("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextWithCurlyBracesNoPrefix() {
|
||||
assertEquals("textwith}brac{es", this.helper.stripPrefix("textwith}brac{es"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextWithCurlyBracesPrefix() {
|
||||
assertEquals("textwith}brac{es{and}prefix", this.helper
|
||||
.stripPrefix("{key:foo}{name:bar}textwith}brac{es{and}prefix"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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