diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2022-03-31 11:20:06 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2022-03-31 12:59:25 +0200 |
commit | 6478c2a16603f2f2163eb2116e58c363ab1cf37b (patch) | |
tree | 70420dae9deadd5282f1598bfd66b6f66490120a /config-lib/src/test/java/com/yahoo | |
parent | f52ebfd454eb7b3c334e03b5c0ab47d4cb753e1f (diff) |
Improve error message for invalid config
Diffstat (limited to 'config-lib/src/test/java/com/yahoo')
-rw-r--r-- | config-lib/src/test/java/com/yahoo/config/FileNodeTest.java | 7 | ||||
-rw-r--r-- | config-lib/src/test/java/com/yahoo/config/PathNodeTest.java | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/config-lib/src/test/java/com/yahoo/config/FileNodeTest.java b/config-lib/src/test/java/com/yahoo/config/FileNodeTest.java index 56dd7dd116d..1ad9f722eca 100644 --- a/config-lib/src/test/java/com/yahoo/config/FileNodeTest.java +++ b/config-lib/src/test/java/com/yahoo/config/FileNodeTest.java @@ -4,6 +4,7 @@ package com.yahoo.config; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; /** @@ -11,6 +12,7 @@ import static org.junit.Assert.assertTrue; * @since 5.1 */ public class FileNodeTest { + @Test public void testSetValue() { FileNode n = new FileNode(); @@ -20,5 +22,10 @@ public class FileNodeTest { assertTrue(n.doSetValue("\"foo.txt\"")); assertEquals("foo.txt", n.value().value()); assertEquals("\"foo.txt\"", n.toString()); + + assertThrows("path may not start with '..', but got: foo/../../boo", + IllegalArgumentException.class, + () -> new FileNode("foo/../../boo")); } + } diff --git a/config-lib/src/test/java/com/yahoo/config/PathNodeTest.java b/config-lib/src/test/java/com/yahoo/config/PathNodeTest.java index 37313bbcdf3..2240f647726 100644 --- a/config-lib/src/test/java/com/yahoo/config/PathNodeTest.java +++ b/config-lib/src/test/java/com/yahoo/config/PathNodeTest.java @@ -6,6 +6,7 @@ import org.junit.Test; import java.io.File; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; /** * @author gjoranv @@ -20,6 +21,10 @@ public class PathNodeTest { n = new PathNode(new FileReference("foo.txt")); assertEquals(new File("foo.txt").toPath(), n.value()); + + assertThrows("path may not start with '..', but got: foo/../../boo", + IllegalArgumentException.class, + () -> new PathNode(new FileReference("foo/../../boo"))); } } |