Skip to content

Commit

Permalink
wsd: test: http::Request with invalid host
Browse files Browse the repository at this point in the history
Change-Id: I88196c38a49d7e70479ea4b1a077447560c001bd
Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod committed Feb 22, 2021
1 parent b0b1d9e commit 88cc2d5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/HttpRequestTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -44,6 +45,7 @@ class HttpRequestTests final : public CPPUNIT_NS::TestFixture

CPPUNIT_TEST_SUITE_END();

void testInvalidURI();
void testSimpleGet();
void testSimpleGetSync();
void test500GetStatuses();
Expand Down Expand Up @@ -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<const http::Response> 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";
Expand Down

0 comments on commit 88cc2d5

Please sign in to comment.