From 8777033b46c4686d0f1190a51c5d0633690b6fa6 Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Mon, 23 Sep 2013 23:48:02 +0000 Subject: QPID-5161: make QBTC use the canonical working dir, and throw an exception if the relative path handling cant generate an appropriate path git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1525746 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/test/utils/QpidBrokerTestCase.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'qpid/java') diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java index 38a7b90ebd..c3b3090f1f 100755 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java @@ -19,6 +19,7 @@ package org.apache.qpid.test.utils; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.net.URI; import java.net.URISyntaxException; @@ -643,7 +644,25 @@ public class QpidBrokerTestCase extends QpidTestCase { File configLocation = new File(file); File workingDirectory = new File(System.getProperty("user.dir")); - return configLocation.getAbsolutePath().replace(workingDirectory.getAbsolutePath(), "").substring(1); + + _logger.debug("Converting path to be relative to working directory: " + file); + + try + { + if(!configLocation.getAbsolutePath().startsWith(workingDirectory.getCanonicalPath())) + { + throw new RuntimeException("Provided path is not a child of the working directory: " + workingDirectory.getCanonicalPath()); + } + + String substring = configLocation.getAbsolutePath().replace(workingDirectory.getCanonicalPath(), "").substring(1); + _logger.debug("Converted relative path: " + substring); + + return substring; + } + catch (IOException e) + { + throw new RuntimeException("Problem while converting to relative path", e); + } } protected String saveTestConfiguration(int port, TestBrokerConfiguration testConfiguration) -- cgit v1.2.1