-
Notifications
You must be signed in to change notification settings - Fork 553
Fix request absolute URI handling #2833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+92
−2
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
vertx-web/src/test/java/io/vertx/ext/web/tests/impl/AbsoluteUriTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright 2023 Red Hat, Inc. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * and Apache License v2.0 which accompanies this distribution. | ||
| * | ||
| * The Eclipse Public License is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * The Apache License v2.0 is available at | ||
| * http://www.opensource.org/licenses/apache2.0.php | ||
| * | ||
| * You may elect to redistribute this code under either of these licenses. | ||
| */ | ||
| package io.vertx.ext.web.tests.impl; | ||
|
|
||
| import io.netty.handler.codec.http.HttpResponseStatus; | ||
| import io.vertx.core.http.HttpMethod; | ||
| import io.vertx.core.net.HostAndPort; | ||
| import io.vertx.ext.web.tests.WebTestBase; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.Parameterized; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| public class AbsoluteUriTest extends WebTestBase { | ||
|
|
||
| @Parameterized.Parameters(name = "target={0}, host={1}, query={2}") | ||
| public static Iterable<Object[]> data() { | ||
| return Arrays.asList( | ||
| // absolute URI, no explicit authority, no query -> the authority in the URI is ignored | ||
| new Object[]{"http://www.example.com:1234/some/path", null, null, "http://localhost:8080/some/path"}, | ||
| // absolute URI, no explicit authority, query present -> the authority in the URI is ignored | ||
| new Object[]{"http://www.example.com:1234/some/path", null, "a=1&b=2", "http://localhost:8080/some/path?a=1&b=2"}, | ||
| // absolute URI, same explicit authority, no query | ||
| new Object[]{"http://www.example.com:1234/some/path", "www.example.com:1234", null, "http://www.example.com:1234/some/path"}, | ||
| // absolute URI, same explicit authority, query present | ||
| new Object[]{"http://www.example.com:1234/some/path", "www.example.com:1234", "a=1&b=2", "http://www.example.com:1234/some/path?a=1&b=2"}, | ||
| // absolute URI, different explicit authority, no query | ||
| new Object[]{"http://www.example.com:1234/some/path", "another-host.com:5678", null, "http://another-host.com:5678/some/path"}, | ||
| // absolute URI, different explicit authority, query present | ||
| new Object[]{"http://www.example.com:1234/some/path", "another-host.com:5678", "a=1&b=2", "http://another-host.com:5678/some/path?a=1&b=2"}, | ||
| // relative URI, no query | ||
| new Object[]{"/some/path", "www.example.com:1234", null, "http://www.example.com:1234/some/path"}, | ||
| // relative URI, query present | ||
| new Object[]{"/some/path", "www.example.com:1234", "a=1&b=2", "http://www.example.com:1234/some/path?a=1&b=2"} | ||
| ); | ||
| } | ||
|
|
||
| private final String target; | ||
| private final String authority; | ||
| private final String query; | ||
| private final String expectedAbsoluteUri; | ||
|
|
||
| public AbsoluteUriTest(String target, String authority, String query, String expectedAbsoluteUri) { | ||
| this.target = target; | ||
| this.authority = authority; | ||
| this.query = query; | ||
| this.expectedAbsoluteUri = expectedAbsoluteUri; | ||
| } | ||
|
|
||
| @Test | ||
| public void testAbsoluteUri() throws Exception { | ||
| String uri = target + (query != null ? "?" + query : ""); | ||
|
|
||
| router.route().handler(event -> { | ||
| assertEquals(expectedAbsoluteUri, event.request().absoluteURI()); | ||
| assertEquals(uri, event.request().uri()); | ||
| event.response().end(); | ||
| }); | ||
|
|
||
| testRequest(HttpMethod.GET, uri, request -> { | ||
| if (authority != null) { | ||
| request.authority(HostAndPort.parseAuthority(authority, 80)); | ||
| } | ||
| }, HttpResponseStatus.OK.code(), HttpResponseStatus.OK.reasonPhrase(), null); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.