reta commented on code in PR #3596:
URL: https://github.com/apache/cxf/pull/3596#discussion_r4332274037


##########
rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java:
##########
@@ -134,7 +137,257 @@ public void testBuildWithNonEncodedSubstitutionValue8() {
         assertEquals("/?a=%25&a2=%7B%7D", uri.toString());
     }
 
+    @Test
+    public void testReplaceFullPath() {
+        UriBuilder ub = UriBuilder.fromPath("");
+        URI uri = ub.build();
+        assertEquals("", uri.toString());
+        uri = ub.replacePath("http://foo.com";).build();
+        assertEquals("http://foo.com";, uri.toString());
+
+        uri = ub.buildFromEncoded();
+        assertEquals("http://foo.com";, uri.toString());
+    }
+
+    @Test
+    public void testReplaceFullPathWhenUriIsSet() {
+        UriBuilder ub = UriBuilder.fromPath("http://foo.com";);
+        URI uri = ub.build();
+        assertEquals("http://foo.com";, uri.toString());
+        uri = ub.replacePath("http://bar.com/";).build();
+        assertThat(uri.toString(), startsWith("http://foo.com";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+
+        uri = ub.buildFromEncoded();
+        assertThat(uri.toString(), startsWith("http://foo.com";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+    }
+
+    @Test
+    public void testBuildAndSetFullPath() {
+        UriBuilder ub = UriBuilder.fromPath("");
+        URI uri = ub.build();
+        assertEquals("", uri.toString());
+        uri = ub.path("http://foo.com";).build();
+        assertEquals("http://foo.com";, uri.toString());
+
+        uri = ub.buildFromEncoded();
+        assertThat(uri.toString(), startsWith("http://foo.com";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+    }
+
+    @Test
+    public void testBuildAndSetFullPathWhenUriIsSet() {
+        UriBuilder ub = UriBuilder.fromPath("http://foo.com";);
+        URI uri = ub.build();
+        assertEquals("http://foo.com";, uri.toString());
+        uri = ub.path("http://bar.com/";).build();
+        assertThat(uri.toString(), startsWith("http://foo.com";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+
+        uri = ub.buildFromEncoded();
+        assertThat(uri.toString(), startsWith("http://foo.com";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+    }
+
+    @Test
+    public void testPathDoesNotChangeHost() {
+        UriBuilder ub = UriBuilder.fromPath("http://foo.com";);
+        URI uri = ub.build();
+        assertEquals("http://foo.com";, uri.toString());
+
+        uri = ub.path(".org").build();
+        assertThat(uri.toString(), equalTo("http://foo.com/.org";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+
+        uri = ub.buildFromEncoded();
+        assertThat(uri.toString(), equalTo("http://foo.com/.org";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+    }
+
+    @Test
+    public void testReplacePathDoesNotChangeHost() {
+        UriBuilder ub = UriBuilder.fromPath("http://foo.com";);
+        URI uri = ub.build();
+        assertEquals("http://foo.com";, uri.toString());
+        uri = ub.replacePath(".org").build();
+        assertThat(uri.toString(), equalTo("http://foo.com/.org";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+
+        uri = ub.buildFromEncoded();
+        assertThat(uri.toString(), equalTo("http://foo.com/.org";));
+        assertThat(uri.getHost(), equalTo("foo.com"));
+    }
+
+    @Test
+    public void testUserInfoAndUriWithMatrix() {
+        // The URI will treat `evil.com` as the host name
+        UriBuilder ub = UriBuilder.fromUri("http://foo.com;@evil.com";);
+        URI uri = ub.build();
+        assertEquals("http://foo.com;@evil.com";, uri.toString());
+        assertThat(uri.getHost(), equalTo("evil.com"));

Review Comment:
   @coheigea here (and test case right below) we cannot fix the host issue 
since getting URI instance that is already "screwed" up, equivalent to 
`UriBuilder.fromUri(URI.create("http://foo.com;@evil.com";))`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to