diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/warp/tests/host.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/warp/tests/host.rs')
-rw-r--r-- | third_party/rust/warp/tests/host.rs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/third_party/rust/warp/tests/host.rs b/third_party/rust/warp/tests/host.rs new file mode 100644 index 0000000000..2fb5f42475 --- /dev/null +++ b/third_party/rust/warp/tests/host.rs @@ -0,0 +1,87 @@ +#![deny(warnings)] +use warp::host::Authority; + +#[tokio::test] +async fn exact() { + let filter = warp::host::exact("known.com"); + + // no authority + let req = warp::test::request(); + assert!(req.filter(&filter).await.unwrap_err().is_not_found()); + + // specified in URI + let req = warp::test::request().path("http://known.com/about-us"); + assert!(req.filter(&filter).await.is_ok()); + + let req = warp::test::request().path("http://unknown.com/about-us"); + assert!(req.filter(&filter).await.unwrap_err().is_not_found()); + + // specified in Host header + let req = warp::test::request() + .header("host", "known.com") + .path("/about-us"); + assert!(req.filter(&filter).await.is_ok()); + + let req = warp::test::request() + .header("host", "unknown.com") + .path("/about-us"); + assert!(req.filter(&filter).await.unwrap_err().is_not_found()); + + // specified in both - matching + let req = warp::test::request() + .header("host", "known.com") + .path("http://known.com/about-us"); + assert!(req.filter(&filter).await.is_ok()); + + let req = warp::test::request() + .header("host", "unknown.com") + .path("http://unknown.com/about-us"); + assert!(req.filter(&filter).await.unwrap_err().is_not_found()); + + // specified in both - mismatch + let req = warp::test::request() + .header("host", "known.com") + .path("http://known2.com/about-us"); + assert!(req + .filter(&filter) + .await + .unwrap_err() + .find::<warp::reject::InvalidHeader>() + .is_some()); + + // bad host header - invalid chars + let req = warp::test::request() + .header("host", "ðŸ˜") + .path("http://known.com/about-us"); + assert!(req + .filter(&filter) + .await + .unwrap_err() + .find::<warp::reject::InvalidHeader>() + .is_some()); + + // bad host header - invalid format + let req = warp::test::request() + .header("host", "hello space.com") + .path("http://known.com//about-us"); + assert!(req + .filter(&filter) + .await + .unwrap_err() + .find::<warp::reject::InvalidHeader>() + .is_some()); +} + +#[tokio::test] +async fn optional() { + let filter = warp::host::optional(); + + let req = warp::test::request().header("host", "example.com"); + assert_eq!( + req.filter(&filter).await.unwrap(), + Some(Authority::from_static("example.com")) + ); + + let req = warp::test::request(); + assert_eq!(req.filter(&filter).await.unwrap(), None); +} |