summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/restapi/PathTest.java
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2019-04-02 20:06:22 +0200
committerGitHub <noreply@github.com>2019-04-02 20:06:22 +0200
commit4a2506315ac3a4f1c2fc89b7f3ffeb9cef3af7c2 (patch)
tree2bc168c1ac37372aae063f09e690e66f17f4f47d /container-core/src/test/java/com/yahoo/restapi/PathTest.java
parent6ad65a6ce0b7e56cde45a61db3dfb6314d9e8caf (diff)
parent1111eab23ae0d796496550b466009818f9f73fbc (diff)
Merge pull request #8990 from vespa-engine/jvenstad/consistent-normalising
Jvenstad/consistent normalising
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.java34
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"));
+ }
+
}