diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/warp/tests/header.rs | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/warp/tests/header.rs')
-rw-r--r-- | third_party/rust/warp/tests/header.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/third_party/rust/warp/tests/header.rs b/third_party/rust/warp/tests/header.rs new file mode 100644 index 0000000000..ea882b44a1 --- /dev/null +++ b/third_party/rust/warp/tests/header.rs @@ -0,0 +1,71 @@ +#![deny(warnings)] +use warp::Filter; + +#[tokio::test] +async fn exact() { + let _ = pretty_env_logger::try_init(); + + let host = warp::header::exact("host", "localhost"); + + let req = warp::test::request().header("host", "localhost"); + + assert!(req.matches(&host).await); + + let req = warp::test::request(); + assert!(!req.matches(&host).await, "header missing"); + + let req = warp::test::request().header("host", "hyper.rs"); + assert!(!req.matches(&host).await, "header value different"); +} + +#[tokio::test] +async fn exact_rejections() { + let _ = pretty_env_logger::try_init(); + + let host = warp::header::exact("host", "localhost").map(warp::reply); + + let res = warp::test::request() + .header("host", "nope") + .reply(&host) + .await; + + assert_eq!(res.status(), 400); + assert_eq!(res.body(), "Invalid request header \"host\""); + + let res = warp::test::request() + .header("not-even-a-host", "localhost") + .reply(&host) + .await; + + assert_eq!(res.status(), 400); + assert_eq!(res.body(), "Missing request header \"host\""); +} + +#[tokio::test] +async fn optional() { + let _ = pretty_env_logger::try_init(); + + let con_len = warp::header::optional::<u64>("content-length"); + + let val = warp::test::request() + .filter(&con_len) + .await + .expect("missing header matches"); + assert_eq!(val, None); + + let val = warp::test::request() + .header("content-length", "5") + .filter(&con_len) + .await + .expect("existing header matches"); + + assert_eq!(val, Some(5)); + + assert!( + !warp::test::request() + .header("content-length", "boom") + .matches(&con_len) + .await, + "invalid optional header still rejects", + ); +} |