From 88cc2d58b64cf16bcce6190a8cbfa3492c84a0e6 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sat, 20 Feb 2021 16:16:18 -0500 Subject: [PATCH] wsd: test: http::Request with invalid host Change-Id: I88196c38a49d7e70479ea4b1a077447560c001bd Signed-off-by: Ashod Nakashian --- test/HttpRequestTests.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/HttpRequestTests.cpp b/test/HttpRequestTests.cpp index 90c0a125489f..cb7ae59767ec 100644 --- a/test/HttpRequestTests.cpp +++ b/test/HttpRequestTests.cpp @@ -34,6 +34,7 @@ class HttpRequestTests final : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(HttpRequestTests); + CPPUNIT_TEST(testInvalidURI); CPPUNIT_TEST(testSimpleGet); CPPUNIT_TEST(testSimpleGetSync); // CPPUNIT_TEST(test500GetStatuses); // Slow. @@ -44,6 +45,7 @@ class HttpRequestTests final : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE_END(); + void testInvalidURI(); void testSimpleGet(); void testSimpleGetSync(); void test500GetStatuses(); @@ -76,6 +78,27 @@ pocoGet(const std::string& host, const std::string& url) return std::make_pair(response, responseString); } +void HttpRequestTests::testInvalidURI() +{ + const char* Host = ""; + const char* URL = "/"; + + http::Request httpRequest(URL); + + auto httpSession = http::Session::createHttp(Host); + httpSession->setTimeout(std::chrono::seconds(1)); + LOK_ASSERT(httpSession->syncRequest(httpRequest) == false); + + const std::shared_ptr httpResponse = httpSession->response(); + LOK_ASSERT(httpResponse->done() == false); + LOK_ASSERT(httpResponse->state() != http::Response::State::Complete); + LOK_ASSERT(httpResponse->statusLine().statusCode() != Poco::Net::HTTPResponse::HTTP_OK); + LOK_ASSERT(httpResponse->statusLine().statusCode() == 0); + LOK_ASSERT(httpResponse->statusLine().statusCategory() + == http::StatusLine::StatusCodeClass::Invalid); + LOK_ASSERT(httpResponse->getBody().empty()); +} + void HttpRequestTests::testSimpleGet() { const char* Host = "example.com";