Skip to content

Commit

Permalink
test: ensure the server should reject a sender connecting a path alre…
Browse files Browse the repository at this point in the history
…ady another sender connected
  • Loading branch information
nwtgck committed May 29, 2022
1 parent 841b533 commit e675966
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/piping_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,60 @@ async fn f() -> Result<(), BoxError> {
Ok(())
}

#[it("should reject a sender connecting a path already another sender connected")]
async fn f() -> Result<(), BoxError> {
let serve: Serve = serve().await;

let uri = format!("http://{}/mypath", serve.addr).parse::<http::Uri>()?;

{
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")]
Expand Down

0 comments on commit e675966

Please sign in to comment.