[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
Henry Castro
hcastro at collabora.com
Tue Apr 12 21:44:07 UTC 2016
loolwsd/LOOLWSD.cpp | 15 ++++++++++++++-
loolwsd/test/httpwstest.cpp | 33 +++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
New commits:
commit 6701dc62ce1c49f7d79ac54dd7123e602826207b
Author: Henry Castro <hcastro at collabora.com>
Date: Tue Apr 12 17:44:39 2016 -0400
loolwsd: response bad request
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ace66b1..cc7d6c0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -504,6 +504,20 @@ private:
uri.erase(0, 1);
}
+ // accept websocket connection with client
+ std::shared_ptr<WebSocket> ws;
+ try
+ {
+ ws = std::make_shared<WebSocket>(request, response);
+ }
+ catch (WebSocketException& exc)
+ {
+ response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
+ response.setContentLength(0);
+ response.send();
+ throw;
+ }
+
const auto uriPublic = DocumentBroker::sanitizeURI(uri);
const auto docKey = DocumentBroker::getDocKey(uriPublic);
std::shared_ptr<DocumentBroker> docBroker;
@@ -548,7 +562,6 @@ private:
// "canceltiles" message.
auto queue = std::make_shared<BasicTileQueue>();
- auto ws = std::make_shared<WebSocket>(request, response);
auto session = std::make_shared<MasterProcessSession>(id, LOOLSession::Kind::ToClient, ws, docBroker, queue);
docBroker->addWSSession(id, session);
auto wsSessionsCount = docBroker->getWSSessionsCount();
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index aeef532..90711ac 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -39,6 +39,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
Poco::Net::HTTPResponse _response;
CPPUNIT_TEST_SUITE(HTTPWSTest);
+ CPPUNIT_TEST(testBadRequest);
CPPUNIT_TEST(testLoad);
CPPUNIT_TEST(testBadLoad);
CPPUNIT_TEST(testReload);
@@ -54,6 +55,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testImpressPartCountChanged);
CPPUNIT_TEST_SUITE_END();
+ void testBadRequest();
void testLoad();
void testBadLoad();
void testReload();
@@ -113,6 +115,37 @@ public:
}
};
+void HTTPWSTest::testBadRequest()
+{
+ try
+ {
+ // Load a document and get its status.
+ const std::string documentURL = "file:///fake.doc";
+
+ Poco::Net::HTTPResponse response;
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+#ifdef ENABLE_SSL
+ Poco::Net::HTTPSClientSession session(_uri.getHost(), _uri.getPort());
+#else
+ Poco::Net::HTTPClientSession session(_uri.getHost(), _uri.getPort());
+#endif
+
+ request.set("Connection", "Upgrade");
+ request.set("Upgrade", "websocket");
+ request.set("Sec-WebSocket-Version", "13");
+ request.set("Sec-WebSocket-Key", "");
+ request.setChunkedTransferEncoding(false);
+ session.setKeepAlive(true);
+ session.sendRequest(request);
+ session.receiveResponse(response);
+ CPPUNIT_ASSERT(response.getStatus() == Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+}
+
void HTTPWSTest::testLoad()
{
try
More information about the Libreoffice-commits
mailing list