From f11e2893cca8105b185d2bfbe8c4f66c01995dc6 Mon Sep 17 00:00:00 2001 From: Mohammed Sazid Al Rashid Date: Fri, 29 Jan 2021 13:13:46 +0600 Subject: [PATCH] add test for frame size exceed --- actix-web-actors/tests/test_ws.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/actix-web-actors/tests/test_ws.rs b/actix-web-actors/tests/test_ws.rs index d196c5470..41194ed0a 100644 --- a/actix-web-actors/tests/test_ws.rs +++ b/actix-web-actors/tests/test_ws.rs @@ -87,6 +87,34 @@ async fn test_builder_with_frame_size() { common_test_code(srv, MAX_FRAME_SIZE).await; } +#[actix_rt::test] +#[should_panic] +async fn test_builder_with_frame_size_exceeded() { + let mut srv = test::start(|| { + App::new().service(web::resource("/").to( + |req: HttpRequest, stream: web::Payload| async move { + ws::WsResponseBuilder::new(Ws, &req, stream) + .frame_size(MAX_FRAME_SIZE) + .start() + }, + )) + }); + + // client service + let mut framed = srv.ws().await.unwrap(); + + // Create a request with a frame size larger than expected. This should + // panic with '`Err` value: Overflow'. + let bytes = Bytes::from(vec![0; MAX_FRAME_SIZE + 1]); + framed + .send(ws::Message::Binary(bytes.clone())) + .await + .unwrap(); + + // try unwrapping to panic. + framed.next().await.unwrap().unwrap(); +} + #[actix_rt::test] async fn test_builder_with_codec() { let srv = test::start(|| {