Add connection window overflow test (#72)
This commit is contained in:
committed by
Carl Lerche
parent
5c0efcf8c4
commit
460afa41c8
@@ -186,9 +186,79 @@ fn expand_window_sends_window_update() {
|
||||
fn expand_window_calls_are_coalesced() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recv_data_overflows_connection_window() {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
let (io, srv) = mock::new();
|
||||
|
||||
let mock = srv.assert_client_handshake().unwrap()
|
||||
.recv_settings()
|
||||
.recv_frame(
|
||||
frames::headers(1)
|
||||
.request("GET", "https://http2.akamai.com/")
|
||||
.eos()
|
||||
)
|
||||
.send_frame(
|
||||
frames::headers(1)
|
||||
.response(200)
|
||||
)
|
||||
// fill the whole window
|
||||
.send_frame(frames::data(1, vec![0u8; 16_384]))
|
||||
.send_frame(frames::data(1, vec![0u8; 16_384]))
|
||||
.send_frame(frames::data(1, vec![0u8; 16_384]))
|
||||
.send_frame(frames::data(1, vec![0u8; 16_383]))
|
||||
// this frame overflows the window!
|
||||
.send_frame(frames::data(1, vec![0u8; 128]).eos())
|
||||
// expecting goaway for the conn, not stream
|
||||
.recv_frame(frames::go_away(0).flow_control());
|
||||
// connection is ended by client
|
||||
|
||||
let h2 = Client::handshake(io).unwrap()
|
||||
.and_then(|mut h2| {
|
||||
let request = Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri("https://http2.akamai.com/")
|
||||
.body(()).unwrap();
|
||||
|
||||
let req = h2.request(request, true).unwrap()
|
||||
.unwrap()
|
||||
.and_then(|resp| {
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
let body = resp.into_parts().1;
|
||||
body.concat2()
|
||||
.unwrap()
|
||||
/* FIXME: body stream should error also
|
||||
.then(|res| {
|
||||
let err = res.unwrap_err();
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"protocol error: flow-control protocol violated"
|
||||
);
|
||||
Ok::<(), ()>(())
|
||||
})
|
||||
*/
|
||||
});
|
||||
|
||||
// client should see a flow control error
|
||||
let conn = h2.then(|res| {
|
||||
let err = res.unwrap_err();
|
||||
assert_eq!(
|
||||
err.to_string(),
|
||||
"protocol error: flow-control protocol violated"
|
||||
);
|
||||
Ok::<(), ()>(())
|
||||
});
|
||||
conn.unwrap().join(req)
|
||||
});
|
||||
h2.join(mock).wait().unwrap();
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn recv_data_overflows_window() {
|
||||
fn recv_data_overflows_stream_window() {
|
||||
// this tests for when streams have smaller windows than their connection
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -34,6 +34,12 @@ pub fn window_update<T>(id: T, sz: u32) -> frame::WindowUpdate
|
||||
frame::WindowUpdate::new(id.into(), sz)
|
||||
}
|
||||
|
||||
pub fn go_away<T>(id: T) -> MockGoAway
|
||||
where T: Into<StreamId>,
|
||||
{
|
||||
MockGoAway(frame::GoAway::new(id.into(), frame::Reason::NoError))
|
||||
}
|
||||
|
||||
// Headers helpers
|
||||
|
||||
pub struct MockHeaders(frame::Headers);
|
||||
@@ -139,6 +145,35 @@ impl From<MockData> for SendFrame {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// GoAway helpers
|
||||
|
||||
pub struct MockGoAway(frame::GoAway);
|
||||
|
||||
impl MockGoAway {
|
||||
pub fn flow_control(self) -> Self {
|
||||
MockGoAway(frame::GoAway::new(self.0.last_stream_id(), frame::Reason::FlowControlError))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for MockGoAway {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MockGoAway> for Frame {
|
||||
fn from(src: MockGoAway) -> Self {
|
||||
Frame::GoAway(src.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MockGoAway> for SendFrame {
|
||||
fn from(src: MockGoAway) -> Self {
|
||||
Frame::GoAway(src.0)
|
||||
}
|
||||
}
|
||||
|
||||
// ==== "trait alias" for types that are HttpTryFrom and have Debug Errors ====
|
||||
|
||||
pub trait HttpTryInto<T> {
|
||||
|
||||
Reference in New Issue
Block a user