Skip to content

Commit

Permalink
relative redirect server & fetch test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosc90 committed Jul 12, 2020
1 parent fd16577 commit dc910f1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cli/tests/unit/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,27 @@ unitTest(
}
);

unitTest(
{
perms: { net: true },
},
async function fetchWithRelativeRedirectionUrl(): Promise<void> {
const cases = [
["end", "http://localhost:4551/a/b/end"],
["/end", "http://localhost:4551/end"],
];
for (const [loc, redUrl] of cases) {
const response = await fetch("http://localhost:4551/a/b/c", {
headers: new Headers([["x-location", loc]]),
});
assertEquals(response.url, redUrl);
assertEquals(response.redirected, true);
assertEquals(response.ok, true);
assertEquals(await response.text(), "Hello, World!");
}
}
);

unitTest(
{
perms: { net: true },
Expand Down
18 changes: 18 additions & 0 deletions test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ANOTHER_REDIRECT_PORT: u16 = 4547;
const DOUBLE_REDIRECTS_PORT: u16 = 4548;
const INF_REDIRECTS_PORT: u16 = 4549;
const REDIRECT_ABSOLUTE_PORT: u16 = 4550;
const REDIRECT_RELATIVE_PORT: u16 = 4551;
const HTTPS_PORT: u16 = 5545;

pub const PERMISSION_VARIANTS: [&str; 5] =
Expand Down Expand Up @@ -155,6 +156,22 @@ pub async fn run_all_servers() {
let absolute_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], REDIRECT_ABSOLUTE_PORT));

let routes = warp::path!("a" / "b" / "c")
.and(warp::header::<String>("x-location"))
.map(|token: String| {
let uri: Uri = token.parse().unwrap();
warp::redirect(uri)
})
.or(
warp::any()
.map(|| {
"Hello, World!"
})
);

let relative_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], REDIRECT_RELATIVE_PORT));

let echo_server = warp::path("echo_server")
.and(warp::post())
.and(warp::body::bytes())
Expand Down Expand Up @@ -343,6 +360,7 @@ pub async fn run_all_servers() {
inf_redirect_server_fut,
double_redirect_server_fut,
absolute_redirect_server_fut,
relative_redirect_server_fut
)
}
.boxed();
Expand Down

0 comments on commit dc910f1

Please sign in to comment.