From d3a590b0c483637ebdb78ecc7bfae474ce7f1b02 Mon Sep 17 00:00:00 2001 From: Ryo Ota Date: Sun, 29 May 2022 15:39:58 +0900 Subject: [PATCH] test: ensure the server should reject a sender connecting a path already another sender connected --- tests/piping_server.rs | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/piping_server.rs b/tests/piping_server.rs index 7df99722f..625b6c36b 100644 --- a/tests/piping_server.rs +++ b/tests/piping_server.rs @@ -579,6 +579,60 @@ async fn f() -> Result<(), BoxError> { Ok(()) } +#[it("should reject a sender connecting a path another sender connected already")] +async fn f() -> Result<(), BoxError> { + let serve: Serve = serve().await; + + let uri = format!("http://{}/mypath", serve.addr).parse::()?; + + { + let send_body_str = "this is a content"; + let send_req = hyper::Request::builder() + .method(hyper::Method::POST) + .header("Content-Type", "text/plain") + .uri(uri.clone()) + .body(hyper::Body::from(send_body_str))?; + + let client = Client::new(); + let send_res = client.request(send_req).await?; + let (send_res_parts, _send_res_body) = send_res.into_parts(); + assert_eq!(send_res_parts.status, http::StatusCode::OK); + assert_eq!( + get_header_value(&send_res_parts.headers, "content-type"), + Some("text/plain") + ); + assert_eq!( + get_header_value(&send_res_parts.headers, "access-control-allow-origin"), + Some("*") + ); + } + + { + let send_body_str = "this is a content"; + let send_req = hyper::Request::builder() + .method(hyper::Method::POST) + .header("Content-Type", "text/plain") + .uri(uri.clone()) + .body(hyper::Body::from(send_body_str))?; + + let client = Client::new(); + let send_res = client.request(send_req).await?; + let (send_res_parts, _send_res_body) = send_res.into_parts(); + assert_eq!(send_res_parts.status, http::StatusCode::BAD_REQUEST); + assert_eq!( + get_header_value(&send_res_parts.headers, "content-type"), + Some("text/plain") + ); + assert_eq!( + get_header_value(&send_res_parts.headers, "access-control-allow-origin"), + Some("*") + ); + } + + serve.shutdown_tx.send(()).expect("shutdown failed"); + Ok(()) +} + // TODO: add tests when sender or receiver receive 400 #[it("should reject invalid n")]