diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/restapi/PathTest.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/restapi/PathTest.java | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/container-core/src/test/java/com/yahoo/restapi/PathTest.java b/container-core/src/test/java/com/yahoo/restapi/PathTest.java index 886b3ba9c87..8d5a9bd6591 100644 --- a/container-core/src/test/java/com/yahoo/restapi/PathTest.java +++ b/container-core/src/test/java/com/yahoo/restapi/PathTest.java @@ -3,6 +3,8 @@ package com.yahoo.restapi; import org.junit.Test; +import java.net.URI; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; @@ -15,7 +17,7 @@ public class PathTest { @Test public void testWithPrefix() { // Test that a path with a prefix matches spec without the prefix - Path path = new Path("/ball/a/1/bar/fuz", "/ball"); + Path path = new Path(URI.create("/ball/a/1/bar/fuz"), "/ball"); assertTrue(path.matches("/a/{foo}/bar/{b}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -27,11 +29,11 @@ public class PathTest { @Test public void testPath() { - assertFalse(new Path("").matches("/a/{foo}/bar/{b}")); - assertFalse(new Path("///").matches("/a/{foo}/bar/{b}")); - assertFalse(new Path("///foo").matches("/a/{foo}/bar/{b}")); - assertFalse(new Path("///bar/").matches("/a/{foo}/bar/{b}")); - Path path = new Path("/a/1/bar/fuz"); + assertFalse(new Path(URI.create("")).matches("/a/{foo}/bar/{b}")); + assertFalse(new Path(URI.create("///")).matches("/a/{foo}/bar/{b}")); + assertFalse(new Path(URI.create("///foo")).matches("/a/{foo}/bar/{b}")); + assertFalse(new Path(URI.create("///bar/")).matches("/a/{foo}/bar/{b}")); + Path path = new Path(URI.create("/a/1/bar/fuz")); assertTrue(path.matches("/a/{foo}/bar/{b}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -40,7 +42,7 @@ public class PathTest { @Test public void testPathWithRest() { { - Path path = new Path("/a/1/bar/fuz/"); + Path path = new Path(URI.create("/a/1/bar/fuz/")); assertTrue(path.matches("/a/{foo}/bar/{b}/{*}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -48,7 +50,7 @@ public class PathTest { } { - Path path = new Path("/a/1/bar/fuz/kanoo"); + Path path = new Path(URI.create("/a/1/bar/fuz/kanoo")); assertTrue(path.matches("/a/{foo}/bar/{b}/{*}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -56,7 +58,7 @@ public class PathTest { } { - Path path = new Path("/a/1/bar/fuz/kanoo/trips"); + Path path = new Path(URI.create("/a/1/bar/fuz/kanoo/trips")); assertTrue(path.matches("/a/{foo}/bar/{b}/{*}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -64,7 +66,7 @@ public class PathTest { } { - Path path = new Path("/a/1/bar/fuz/kanoo/trips/"); + Path path = new Path(URI.create("/a/1/bar/fuz/kanoo/trips/")); assertTrue(path.matches("/a/{foo}/bar/{b}/{*}")); assertEquals("1", path.get("foo")); assertEquals("fuz", path.get("b")); @@ -72,4 +74,16 @@ public class PathTest { } } + @Test + public void testUrlEncodedPath() { + assertTrue(new Path(URI.create("/a/%62/c")).matches("/a/b/c")); + assertTrue(new Path(URI.create("/a/%2e%2e/c")).matches("/a/../c")); + assertFalse(new Path(URI.create("/a/b%2fc")).matches("/a/b/c")); + + Path path = new Path(URI.create("/%61/%2f/%63")); + assertTrue(path.matches("/a/{slash}/{c}")); + assertEquals("/", path.get("slash")); + assertEquals("c", path.get("c")); + } + } |