summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2021-09-01 19:09:50 -0400
committerMichael Meeks <michael.meeks@collabora.com>2021-09-07 10:23:15 +0100
commitc16ad4447004a72226df7761fb377014c242ea4e (patch)
tree80a73c5d989d350ac6775e402bc42185dae532ce
parentwsd: configuration setting to control embedded-url hexifying (diff)
downloadonline-c16ad4447004a72226df7761fb377014c242ea4e.tar.gz
online-c16ad4447004a72226df7761fb377014c242ea4e.zip
wsd: throw when an invalid URL is used to create an http session
Change-Id: I2d2eb90badf4f02ec4f2e4c4071fc76b23a92928 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
-rw-r--r--net/HttpRequest.cpp3
-rw-r--r--test/HttpRequestTests.cpp12
2 files changed, 12 insertions, 3 deletions
diff --git a/net/HttpRequest.cpp b/net/HttpRequest.cpp
index 58e5403bcf..21b0b30c31 100644
--- a/net/HttpRequest.cpp
+++ b/net/HttpRequest.cpp
@@ -17,6 +17,7 @@
#include <fstream>
#include <memory>
#include <sstream>
+#include <stdexcept>
#include <string>
#include <sys/types.h>
#include <netdb.h>
@@ -650,7 +651,7 @@ std::shared_ptr<Session> Session::create(std::string host, Protocol protocol, in
if (!net::parseUri(host, scheme, hostname, portString))
{
LOG_ERR("Invalid URI [" << host << "] to http::Session::create.");
- return nullptr;
+ throw std::runtime_error("Invalid URI [" + host + "] to http::Session::create.");
}
scheme = Util::toLower(std::move(scheme));
diff --git a/test/HttpRequestTests.cpp b/test/HttpRequestTests.cpp
index 55ed401e2a..be46c53ae4 100644
--- a/test/HttpRequestTests.cpp
+++ b/test/HttpRequestTests.cpp
@@ -159,8 +159,16 @@ constexpr std::chrono::seconds HttpRequestTests::DefTimeoutSeconds;
void HttpRequestTests::testInvalidURI()
{
- // Cannot create from a blank URI.
- LOK_ASSERT(http::Session::createHttp(std::string()) == nullptr);
+ try
+ {
+ // Cannot create from a blank URI.
+ http::Session::createHttp(std::string());
+ LOK_ASSERT_FAIL("Exception expected from http::Session::createHttp for invalid URI");
+ }
+ catch (const std::exception& ex)
+ {
+ // Pass.
+ }
}
void HttpRequestTests::testSimpleGet()