From 764cd1731694ec1529db87557cea983220e96540 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 8 Jul 2015 22:48:12 +0900 Subject: [PATCH] Add test when nghttp2_http_on_data_chunk failed without auto flow control --- tests/nghttp2_session_test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index c541283b..33f8ef54 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -810,6 +810,7 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { uint8_t data[8192]; ssize_t rv; size_t sendlen; + nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.send_callback = null_send_callback; @@ -838,6 +839,9 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { rv = nghttp2_session_mem_recv(session, data, sendlen); CU_ASSERT((ssize_t)sendlen == rv); + /* We consumed pad length field (1 byte) */ + CU_ASSERT(1 == session->consumed_size); + /* close stream here */ nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); nghttp2_session_send(session); @@ -852,6 +856,24 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { CU_ASSERT((int32_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen + 1) == session->consumed_size); + nghttp2_session_del(session); + + /* Reuse DATA created previously. */ + + nghttp2_session_server_new2(&session, &callbacks, &ud, option); + + /* Now we are expecting final response header, which means receiving + DATA for that stream is illegal. */ + stream = open_stream(session, 1); + stream->http_flags |= NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE; + + rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length); + CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == rv); + + /* Whole payload must be consumed now because HTTP messaging rule + was not honored. */ + CU_ASSERT((int32_t)hd.length == session->consumed_size); + nghttp2_session_del(session); nghttp2_option_del(option); }