diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2022-03-24 12:59:47 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2022-03-24 12:59:47 +0100 |
commit | 04927f9142d5582d79757b9b66e2924f7d84dd93 (patch) | |
tree | e2a692f50d248adcdf15cfa738e9ca9091784004 /config-application-package/src/test | |
parent | 73b080b527e303a60a365b2bb95b72dcc2f81f4c (diff) |
Add a top layer path to virtual file system
Diffstat (limited to 'config-application-package/src/test')
3 files changed, 34 insertions, 0 deletions
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java index 56ba4f01048..3de624c78ac 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java @@ -2,6 +2,7 @@ package com.yahoo.config.application; import com.yahoo.config.application.api.ApplicationPackage; +import org.junit.Assert; import org.junit.Test; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -13,6 +14,9 @@ import java.io.File; import java.io.IOException; import java.nio.file.NoSuchFileException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * @author Ulf Lilleengen */ @@ -78,11 +82,33 @@ public class IncludeProcessorTest { TestBase.assertDocument(expected, doc); } + @Test + public void testIllegalParent() throws ParserConfigurationException, IOException, SAXException, TransformerException { + try { + File app = new File("src/test/resources/multienvapp_fail_parent"); + DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); + new IncludeProcessor(app).process(docBuilder.parse(getServices(app))); + fail("sibling to package should not be allowed"); + } + catch (IllegalArgumentException e) { + assertEquals("src/test/resources/multienvapp_fail_parent/../multienvapp/services.xml is not a descendant of src/test/resources/multienvapp_fail_parent", e.getMessage()); + } + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalParent2() throws ParserConfigurationException, IOException, SAXException, TransformerException { + File app = new File("src/test/resources/multienvapp_fail_parent2"); + DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); + new IncludeProcessor(app).process(docBuilder.parse(getServices(app))); + fail("absolute include path should not be allowed"); + } + @Test(expected = NoSuchFileException.class) public void testRequiredIncludeIsDefault() throws ParserConfigurationException, IOException, SAXException, TransformerException { File app = new File("src/test/resources/multienvapp_failrequired"); DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); new IncludeProcessor(app).process(docBuilder.parse(getServices(app))); + fail("should fail by default to include a non-existent file"); } static File getServices(File app) { diff --git a/config-application-package/src/test/resources/multienvapp_fail_parent/services.xml b/config-application-package/src/test/resources/multienvapp_fail_parent/services.xml new file mode 100644 index 00000000000..b68e304e4c9 --- /dev/null +++ b/config-application-package/src/test/resources/multienvapp_fail_parent/services.xml @@ -0,0 +1,4 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version='1.0' xmlns:deploy="vespa" xmlns:preprocess="properties"> + <preprocess:include file='../multienvapp/services.xml' /> +</services> diff --git a/config-application-package/src/test/resources/multienvapp_fail_parent2/services.xml b/config-application-package/src/test/resources/multienvapp_fail_parent2/services.xml new file mode 100644 index 00000000000..e3f6bc3bd4c --- /dev/null +++ b/config-application-package/src/test/resources/multienvapp_fail_parent2/services.xml @@ -0,0 +1,4 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version='1.0' xmlns:deploy="vespa" xmlns:preprocess="properties"> + <preprocess:include file='/absolute/path' /> +</services> |