Repository: asterixdb Updated Branches: refs/heads/master 54a507007 -> 58be3a8e4
[ASTERIXDB-2004][TEST] Prevent Tests from writing outside target - user model changes: no - storage format changes: no - interface changes: no details: - Some tests access data and queries outside the module. When that happens, the base path can contain ../ which can lead to results being written outside target. This change removes all ../ from the path of the actual results. Change-Id: If100c33780fa436ddb2a8e64f3901251156f5524 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1905 Sonar-Qube: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> BAD: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Till Westmann <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/58be3a8e Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/58be3a8e Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/58be3a8e Branch: refs/heads/master Commit: 58be3a8e40caf430982e26a58284f9c6df41836e Parents: 54a5070 Author: Abdullah Alamoudi <[email protected]> Authored: Thu Jul 27 20:58:12 2017 -0700 Committer: abdullah alamoudi <[email protected]> Committed: Fri Jul 28 11:32:27 2017 -0700 ---------------------------------------------------------------------- .../testframework/context/TestCaseContext.java | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/58be3a8e/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java index ff914b5..7a34648 100644 --- a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java +++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java @@ -186,9 +186,20 @@ public class TestCaseContext { public File getActualResultFile(CompilationUnit cUnit, File expectedFile, File actualResultsBase) { File path = actualResultsBase; - path = new File(path, testSuite.getResultOffsetPath()); - path = new File(path, testCase.getFilePath()); - return new File(path, cUnit.getOutputDir().getValue() + File.separator + expectedFile.getName()); + String resultOffsetPath = removeUpward(testSuite.getResultOffsetPath()); + path = new File(path, resultOffsetPath); + String testCaseFilePath = removeUpward(testCase.getFilePath()); + String expectedFilePath = removeUpward(expectedFile.getName()); + path = new File(path, testCaseFilePath); + return new File(path, cUnit.getOutputDir().getValue() + File.separator + expectedFilePath); + } + + private String removeUpward(String filePath) { + String evil = ".." + File.separatorChar; + while (filePath.contains(evil)) { + filePath = filePath.replace(evil, ""); // NOSONAR + } + return filePath; } @Override @@ -224,8 +235,8 @@ public class TestCaseContext { File tsFile = new File(tsRoot, tsXMLFilePath); TestSuiteParser tsp = new TestSuiteParser(); TestSuite ts = tsp.parse(tsFile); - List<TestCaseContext> tccs = new ArrayList<TestCaseContext>(); - List<TestGroup> tgPath = new ArrayList<TestGroup>(); + List<TestCaseContext> tccs = new ArrayList<>(); + List<TestGroup> tgPath = new ArrayList<>(); addContexts(tsRoot, ts, tgPath, ts.getTestGroup(), tccs); return tccs; }
