Merge remote-tracking branch 'origin/2.0.x' into 2.1.x
This commit is contained in:
@@ -64,7 +64,7 @@ public class GenericResourceRepository
|
||||
String[] locations = this.service.getLocations(application, profile, label)
|
||||
.getLocations();
|
||||
try {
|
||||
for (int i = locations.length; i-- > 0; ) {
|
||||
for (int i = locations.length; i-- > 0;) {
|
||||
String location = locations[i];
|
||||
for (String local : getProfilePaths(profile, path)) {
|
||||
if (!isInvalidPath(local) && !isInvalidEncodedPath(local)) {
|
||||
@@ -116,7 +116,8 @@ public class GenericResourceRepository
|
||||
private boolean isInvalidEncodedPath(String path) {
|
||||
if (path.contains("%")) {
|
||||
try {
|
||||
// Use URLDecoder (vs UriUtils) to preserve potentially decoded UTF-8 chars
|
||||
// Use URLDecoder (vs UriUtils) to preserve potentially decoded UTF-8
|
||||
// chars
|
||||
String decodedPath = URLDecoder.decode(path, "UTF-8");
|
||||
if (isInvalidPath(decodedPath)) {
|
||||
return true;
|
||||
@@ -135,13 +136,13 @@ public class GenericResourceRepository
|
||||
|
||||
/**
|
||||
* Process the given resource path.
|
||||
* <p>The default implementation replaces:
|
||||
* <p>
|
||||
* The default implementation replaces:
|
||||
* <ul>
|
||||
* <li>Backslash with forward slash.
|
||||
* <li>Duplicate occurrences of slash with a single slash.
|
||||
* <li>Any combination of leading slash and control characters (00-1F and 7F)
|
||||
* with a single "/" or "". For example {@code " / // foo/bar"}
|
||||
* becomes {@code "/foo/bar"}.
|
||||
* <li>Any combination of leading slash and control characters (00-1F and 7F) with a
|
||||
* single "/" or "". For example {@code " / // foo/bar"} becomes {@code "/foo/bar"}.
|
||||
* </ul>
|
||||
* @since 3.2.12
|
||||
*/
|
||||
@@ -151,7 +152,6 @@ public class GenericResourceRepository
|
||||
return cleanLeadingSlash(path);
|
||||
}
|
||||
|
||||
|
||||
private String cleanDuplicateSlashes(String path) {
|
||||
StringBuilder sb = null;
|
||||
char prev = 0;
|
||||
@@ -175,7 +175,6 @@ public class GenericResourceRepository
|
||||
return sb != null ? sb.toString() : path;
|
||||
}
|
||||
|
||||
|
||||
private String cleanLeadingSlash(String path) {
|
||||
boolean slash = false;
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
@@ -192,7 +191,6 @@ public class GenericResourceRepository
|
||||
return (slash ? "/" : "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Identifies invalid resource paths. By default rejects:
|
||||
* <ul>
|
||||
@@ -202,9 +200,10 @@ public class GenericResourceRepository
|
||||
* <li>Paths that represent a {@link org.springframework.util.ResourceUtils#isUrl
|
||||
* valid URL} or would represent one after the leading slash is removed.
|
||||
* </ul>
|
||||
* <p><strong>Note:</strong> this method assumes that leading, duplicate '/'
|
||||
* or control characters (e.g. white space) have been trimmed so that the
|
||||
* path starts predictably with a single '/' or does not have one.
|
||||
* <p>
|
||||
* <strong>Note:</strong> this method assumes that leading, duplicate '/' or control
|
||||
* characters (e.g. white space) have been trimmed so that the path starts predictably
|
||||
* with a single '/' or does not have one.
|
||||
* @param path the path to validate
|
||||
* @return {@code true} if the path is invalid, {@code false} otherwise
|
||||
* @since 3.0.6
|
||||
@@ -220,17 +219,20 @@ public class GenericResourceRepository
|
||||
String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path);
|
||||
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
|
||||
logger.warn(
|
||||
"Path represents URL or has \"url:\" prefix: [" + path + "]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]");
|
||||
logger.warn("Path contains \"../\" after call to StringUtils#cleanPath: ["
|
||||
+ path + "]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,6 +53,9 @@ public class BootstrapConfigServerIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws IOException {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo("encrypt-repo");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -52,6 +54,9 @@ public class CompositeIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/repos/svn-config-repo");
|
||||
@@ -110,6 +115,9 @@ public class CompositeIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/repos/svn-config-repo");
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -60,6 +62,9 @@ public class ConfigClientOffIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws IOException {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -65,6 +67,9 @@ public class ConfigClientOnIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws IOException {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
localRepo = ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -46,6 +48,9 @@ public class NativeConfigServerIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws IOException {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.cloud.config.server;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,6 +53,9 @@ public class VanillaConfigServerIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws IOException {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.cloud.config.server.config;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -64,6 +66,9 @@ public class CustomCompositeEnvironmentRepositoryTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
@@ -115,6 +120,9 @@ public class CustomCompositeEnvironmentRepositoryTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
|
||||
ConfigServerTestUtils.prepareLocalRepo();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,15 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException;
|
||||
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
|
||||
import org.eclipse.jgit.api.errors.RefNotFoundException;
|
||||
import org.eclipse.jgit.api.errors.TransportException;
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.FetchResult;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
@@ -72,6 +75,12 @@ public class JGitEnvironmentRepositoryConcurrencyTests {
|
||||
|
||||
private File basedir = new File("target/config");
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
if (this.basedir.exists()) {
|
||||
|
||||
@@ -33,12 +33,15 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ResetCommand.ResetType;
|
||||
import org.eclipse.jgit.api.TransportConfigCallback;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.lib.StoredConfig;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -72,6 +75,12 @@ public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
private File basedir = new File("target/config");
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
if (this.basedir.exists()) {
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException;
|
||||
import org.eclipse.jgit.api.errors.NotMergedException;
|
||||
import org.eclipse.jgit.api.errors.TransportException;
|
||||
import org.eclipse.jgit.attributes.AttributesNodeProvider;
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.lib.BaseRepositoryBuilder;
|
||||
import org.eclipse.jgit.lib.ObjectDatabase;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -58,7 +59,9 @@ import org.eclipse.jgit.transport.TrackingRefUpdate;
|
||||
import org.eclipse.jgit.transport.URIish;
|
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -100,6 +103,12 @@ public class JGitEnvironmentRepositoryTests {
|
||||
|
||||
private File basedir = new File("target/config");
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo();
|
||||
|
||||
@@ -19,7 +19,10 @@ package org.springframework.cloud.config.server.environment;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -42,6 +45,12 @@ public class MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests {
|
||||
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
|
||||
this.environment, new MultipleJGitEnvironmentProperties());
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
@@ -39,6 +42,12 @@ public class MultipleJGitEnvironmentLabelPlaceholderRepositoryTests {
|
||||
|
||||
private String defaultUri;
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
this.defaultUri = ConfigServerTestUtils
|
||||
|
||||
@@ -20,7 +20,10 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.config.environment.Environment;
|
||||
@@ -44,6 +47,12 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests {
|
||||
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
|
||||
this.environment, new MultipleJGitEnvironmentProperties());
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
|
||||
|
||||
@@ -22,9 +22,12 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.matchers.ThrowableMessageMatcher;
|
||||
@@ -59,6 +62,12 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
private File basedir = new File("target/config");
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
if (this.basedir.exists()) {
|
||||
|
||||
@@ -24,7 +24,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jgit.api.TransportConfigCallback;
|
||||
import org.eclipse.jgit.junit.MockSystemReader;
|
||||
import org.eclipse.jgit.util.SystemReader;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -54,6 +57,12 @@ public class MultipleJGitEnvironmentRepositoryTests {
|
||||
|
||||
private MultipleJGitEnvironmentRepository repository;
|
||||
|
||||
@BeforeClass
|
||||
public static void initClass() {
|
||||
// mock Git configuration to make tests independent of local Git configuration
|
||||
SystemReader.setInstance(new MockSystemReader());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
|
||||
|
||||
@@ -98,9 +98,11 @@ public class GenericResourceRepositoryTests {
|
||||
@Test
|
||||
public void invalidPath() {
|
||||
this.exception.expect(NoSuchResourceException.class);
|
||||
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/{profile}");
|
||||
this.nativeRepository
|
||||
.setSearchLocations("file:./src/test/resources/test/{profile}");
|
||||
this.repository.findOne("blah", "local", "master", "..%2F..%2Fdata-jdbc.sql");
|
||||
this.output.expect(containsString("Path contains \"../\" after call to StringUtils#cleanPath"));
|
||||
this.output.expect(containsString(
|
||||
"Path contains \"../\" after call to StringUtils#cleanPath"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user