From 2ee088de5fa86f613c31d7b5ba34c4013506e7f7 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 3 Jul 2017 19:25:15 -0700 Subject: [PATCH] Add basic_parser tests --- CHANGELOG.md | 1 + test/http/basic_parser.cpp | 48 ++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee5423e..4bd26372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 73: HTTP: * basic_parser optimizations +* Add basic_parser tests -------------------------------------------------------------------------------- diff --git a/test/http/basic_parser.cpp b/test/http/basic_parser.cpp index cba5448e..79f7dd07 100644 --- a/test/http/basic_parser.cpp +++ b/test/http/basic_parser.cpp @@ -783,6 +783,40 @@ public: }); } + void + testPartial() + { + // Make sure the slow-loris defense works and that + // we don't get duplicate or missing fields on a split. + parsegrind>( + "GET / HTTP/1.1\r\n" + "a: 0\r\n" + "b: 1\r\n" + "c: 2\r\n" + "d: 3\r\n" + "e: 4\r\n" + "f: 5\r\n" + "g: 6\r\n" + "h: 7\r\n" + "i: 8\r\n" + "j: 9\r\n" + "\r\n", + [&](test_parser const& p) + { + BEAST_EXPECT(p.fields.size() == 10); + BEAST_EXPECT(p.fields.at("a") == "0"); + BEAST_EXPECT(p.fields.at("b") == "1"); + BEAST_EXPECT(p.fields.at("c") == "2"); + BEAST_EXPECT(p.fields.at("d") == "3"); + BEAST_EXPECT(p.fields.at("e") == "4"); + BEAST_EXPECT(p.fields.at("f") == "5"); + BEAST_EXPECT(p.fields.at("g") == "6"); + BEAST_EXPECT(p.fields.at("h") == "7"); + BEAST_EXPECT(p.fields.at("i") == "8"); + BEAST_EXPECT(p.fields.at("j") == "9"); + }); + } + void testLimits() { @@ -943,7 +977,6 @@ public: // response without Content-Length or // Transfer-Encoding: chunked requires eof. { -#if 0 error_code ec; test_parser p; feed(buf( @@ -952,17 +985,7 @@ public: ), p, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(! p.is_done()); - BEAST_EXPECT(p.state() == parse_state::body_to_eof); - feed(buf( - "hello" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(! p.is_done()); - BEAST_EXPECT(p.state() == parse_state::body_to_eof); - p.put_eof(ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); -#endif + BEAST_EXPECT(p.need_eof()); } // 304 "Not Modified" response does not require eof @@ -1093,6 +1116,7 @@ public: testContentLengthField(); testTransferEncodingField(); testUpgradeField(); + testPartial(); testLimits(); testBody(); testIssue430();