[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp | 46 ++- loolwsd/test/httpwserror.cpp |6 + 2 files changed, 34 insertions(+), 18 deletions(-) New commits: commit f68ece00377ef41e68996f78f2ac4cd868794930 Author: Ashod Nakashian Date: Sun Oct 23 11:51:10 2016 -0400 loolwsd: fix testMaxDocuments unittest Checking for document limit must be done before allocating a child process, otherwise the new child process will not be cleaned up or released, thereby failing the test. Change-Id: I99b1155bdacf2f0b7a24c7b7330d207e4c7beee8 Reviewed-on: https://gerrit.libreoffice.org/30208 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 6694f81..a9aa59d 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -192,17 +192,27 @@ void shutdownLimitReached(WebSocket& ws) int retries = 7; std::vector buffer(READ_BUFFER_SIZE * 100); -// 5 seconds timeout -ws.setReceiveTimeout(500); +const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000); do { -// ignore loolclient, load and partpagerectangles -ws.receiveFrame(buffer.data(), buffer.capacity(), flags); -if (--retries == 4) +if (ws.poll(Poco::Timespan(0), Poco::Net::Socket::SelectMode::SELECT_ERROR)) { -ws.sendFrame(error.data(), error.size()); -ws.shutdown(WebSocket::WS_POLICY_VIOLATION); +// Already disconnected, can't send 'close' frame. +ws.close(); +return; +} + +// Let the client know we are shutting down. +ws.sendFrame(error.data(), error.size()); + +// Ignore incoming messages. +if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ)) +{ +ws.receiveFrame(buffer.data(), buffer.capacity(), flags); } + +// Shutdown. +ws.shutdown(WebSocket::WS_POLICY_VIOLATION); } while (retries > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE); } @@ -684,6 +694,17 @@ private: } else { +// New Document. +#if MAX_DOCUMENTS > 0 +if (DocBrokers.size() + 1 > MAX_DOCUMENTS) +{ +Log::error() << "Limit on maximum number of open documents of " + << MAX_DOCUMENTS << " reached." << Log::end; +shutdownLimitReached(*ws); +return; +} +#endif + // Store a dummy (marked to destroy) document broker until we // have the real one, so that the other requests block Log::debug("Inserting a dummy DocumentBroker for docKey [" + docKey + "] temporarily."); @@ -759,17 +780,6 @@ private: throw WebSocketErrorMessageException(SERVICE_UNAVAILABLE_INTERNAL_ERROR); } -#if MAX_DOCUMENTS > 0 -std::unique_lock DocBrokersLock(DocBrokersMutex); -if (DocBrokers.size() + 1 > MAX_DOCUMENTS) -{ -Log::error("Maximum number of open documents reached."); -shutdownLimitReached(*ws); -return; -} -DocBrokersLock.unlock(); -#endif - // Set one we just created. Log::debug("New DocumentBroker for docKey [" + docKey + "]."); docBroker = std::make_shared(uriPublic, docKey, LOOLWSD::ChildRoot, child); diff --git a/loolwsd/test/httpwserror.cpp b/loolwsd/test/httpwserror.cpp index 011806b..1d686e4 100644 --- a/loolwsd/test/httpwserror.cpp +++ b/loolwsd/test/httpwserror.cpp @@ -103,11 +103,15 @@ void HTTPWSError::testMaxDocuments() // Load a document. std::vector> docs; +std::cerr << "Loading max number of documents: " << MAX_DOCUMENTS << std::endl; for (int it = 1; it <= MAX_DOCUMENTS; ++it) { docs.emplace_back(loadDocAndGetSocket("empty.odt", _uri, testname)); +std::cerr << "Loaded document #" << it << " of " << MAX_DOCUMENTS << std::endl; } +std::cerr << "Loading one more document beyond the limit." << std::endl; + // try to open MAX_DOCUMENTS + 1 std::string docPath; std::string docURL; @@ -121,6 +125,8 @@ void HTTPWSError::testMaxDocuments() sendTextFrame(socket, "load ", testname); sendTextFrame(socket, "partpagerectangles ", testname); +assertResponseString(socket, "error:", testname); + std::string message; const auto statusCode = getErrorCode(socket, message); CPPUNIT_ASSERT_EQUAL(static_cast(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode); ___ Libreoffice-commits maili
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp | 29 - loolwsd/test/httpwstest.cpp |2 +- 2 files changed, 25 insertions(+), 6 deletions(-) New commits: commit a0a87276f99919df82cc3d32a2d3da47adacc2e6 Author: Henry Castro Date: Thu Oct 13 16:51:14 2016 -0400 loolwsd: fix media type diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index cf22bfd..1b176eb 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -155,6 +155,7 @@ using Poco::XML::DOMWriter; using Poco::XML::Element; using Poco::XML::InputSource; using Poco::XML::NodeList; +using Poco::XML::Node; int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER; int MasterPortNumber = DEFAULT_MASTER_PORT_NUMBER; @@ -378,6 +379,28 @@ public: class ClientRequestHandler: public HTTPRequestHandler { private: +static std::string getContentType(const std::string& fileName) +{ +const std::string nodePath = Poco::format("//[@ext='%s']", Poco::Path(fileName).getExtension()); +std::string discPath = Path(Application::instance().commandPath()).parent().toString() + "discovery.xml"; +if (!File(discPath).exists()) +{ +discPath = LOOLWSD_DATADIR "/discovery.xml"; +} + +InputSource input(discPath); +DOMParser domParser; +AutoPtr doc = domParser.parse(&input); +// TODO. discovery.xml missing application/pdf +Node* node = doc->getNodeByPath(nodePath); +if (node && (node = node->parentNode()) && node->hasAttributes()) +{ +return dynamic_cast(node)->getAttribute("name"); +} + +return "application/octet-stream"; +} + static void waitBridgeCompleted(const std::shared_ptr& session) { bool isFound = false; @@ -609,13 +632,9 @@ private: if (filePath.isAbsolute() && File(filePath).exists()) { response.set("Access-Control-Allow-Origin", "*"); -HTMLForm form(request); -const std::string mimeType = form.has("mime_type") - ? form.get("mime_type") - : "application/octet-stream"; try { -response.sendFile(filePath.toString(), mimeType); +response.sendFile(filePath.toString(), getContentType(fileName)); responded = true; } catch (const Exception& exc) diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 83115d2..2218a9f 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -879,7 +879,7 @@ void HTTPWSTest::testSlideShow() std::string encodedDoc; Poco::URI::encode(documentPath, ":/?", encodedDoc); -const std::string path = "/lool/" + encodedDoc + "/" + jail + "/" + dir + "/" + name + "?mime_type=image/svg%2Bxml"; +const std::string path = "/lool/" + encodedDoc + "/" + jail + "/" + dir + "/" + name; std::unique_ptr session(helpers::createSession(_uri)); Poco::Net::HTTPRequest requestSVG(Poco::Net::HTTPRequest::HTTP_GET, path); session->sendRequest(requestSVG); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test loolwsd/UserMessages.hpp
loolwsd/LOOLWSD.cpp | 15 +++ loolwsd/UserMessages.hpp |2 -- loolwsd/test/httpwserror.cpp |2 -- 3 files changed, 7 insertions(+), 12 deletions(-) New commits: commit c62344db814fe351787316accf0faf53ee811db5 Author: Henry Castro Date: Mon Oct 10 22:28:56 2016 -0400 loolwsd: websocket shutdown cleanup diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 2b3b205..79d1986 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -182,7 +182,6 @@ static inline void shutdownLimitReached(WebSocket& ws) { const std::string error = Poco::format(PAYLOAD_UNAVALABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS); -const std::string close = Poco::format(SERVICE_UNAVALABLE_LIMIT_REACHED, static_cast(WebSocket::WS_POLICY_VIOLATION)); /* loleaflet sends loolclient, load and partrectangles message immediately after web socket handshake, so closing web socket fails loading page in @@ -204,7 +203,7 @@ void shutdownLimitReached(WebSocket& ws) if (--retries == 4) { ws.sendFrame(error.data(), error.size()); -ws.shutdown(WebSocket::WS_POLICY_VIOLATION, close); +ws.shutdown(WebSocket::WS_POLICY_VIOLATION, ""); } } while (retries > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE); @@ -212,7 +211,7 @@ void shutdownLimitReached(WebSocket& ws) catch (Exception&) { ws.sendFrame(error.data(), error.size()); -ws.shutdown(WebSocket::WS_POLICY_VIOLATION, close); +ws.shutdown(WebSocket::WS_POLICY_VIOLATION, ""); } } @@ -897,8 +896,8 @@ private: // something wrong, with internal exceptions Log::trace("Abnormal close handshake."); session->closeFrame(); -ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, SERVICE_UNAVALABLE_INTERNAL_ERROR); -session->shutdownPeer(WebSocket::WS_ENDPOINT_GOING_AWAY, SERVICE_UNAVALABLE_INTERNAL_ERROR); +ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, ""); +session->shutdownPeer(WebSocket::WS_ENDPOINT_GOING_AWAY, ""); } } @@ -1050,7 +1049,7 @@ public: const std::string msg = std::string("error: ") + exc.what(); ws->sendFrame(msg.data(), msg.size()); // abnormal close frame handshake -ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, msg); +ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, ""); } catch (const std::exception& exc2) { @@ -1275,8 +1274,8 @@ public: // something wrong, with internal exceptions Log::trace("Abnormal close handshake."); session->closeFrame(); -ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, SERVICE_UNAVALABLE_INTERNAL_ERROR); -session->shutdownPeer(WebSocket::WS_ENDPOINT_GOING_AWAY, SERVICE_UNAVALABLE_INTERNAL_ERROR); +ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, ""); +session->shutdownPeer(WebSocket::WS_ENDPOINT_GOING_AWAY, ""); } } catch (const Exception& exc) diff --git a/loolwsd/UserMessages.hpp b/loolwsd/UserMessages.hpp index 36e6ad3..7883fc0 100644 --- a/loolwsd/UserMessages.hpp +++ b/loolwsd/UserMessages.hpp @@ -13,9 +13,7 @@ #define INCLUDED_USERMESSAGES_HPP //NOTE: For whatever reason Poco seems to trim the first character. - constexpr auto SERVICE_UNAVALABLE_INTERNAL_ERROR = " Service is unavailable. Please try again later and report to your administrator if the issue persists."; -constexpr auto SERVICE_UNAVALABLE_LIMIT_REACHED = "error: cmd=socket kind=close code=%d"; constexpr auto PAYLOAD_UNAVALABLE_LIMIT_REACHED = "error: cmd=socket kind=limitreached params=%d,%d"; #endif diff --git a/loolwsd/test/httpwserror.cpp b/loolwsd/test/httpwserror.cpp index 8e7769d..509046c 100644 --- a/loolwsd/test/httpwserror.cpp +++ b/loolwsd/test/httpwserror.cpp @@ -103,7 +103,6 @@ void HTTPWSError::testMaxDocuments() sendTextFrame(socket, "partpagerectangles "); statusCode = getErrorCode(socket, message); CPPUNIT_ASSERT_EQUAL(static_cast(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode); -CPPUNIT_ASSERT_MESSAGE("Wrong error message ", message.find("error: cmd=socket kind=close") != std::string::npos); } catch (const Poco::Exception& exc) { @@ -144,7 +143,6 @@ void HTTPWSError::testMaxConnections() sendTextFrame(socketN, "partpagerectangles "); statusCode = getErrorCode(*socketN, message); CPPUNIT_ASSERT_EQUAL(static_cast(Poco::Net::WebSocket::WS_POLICY_VIOLATION), statusCode); -CPPUNIT_ASSERT_MESSAGE("Wrong error message ", message.find("error: cmd=socket kind=close") != std::string::npos); }
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp | 17 + loolwsd/test/httpwserror.cpp |8 2 files changed, 13 insertions(+), 12 deletions(-) New commits: commit 0729a3822f11c0d6948b9c12ea84d26ecced Author: Henry Castro Date: Wed Sep 28 17:03:36 2016 -0400 loolwsd: restore MAX_CONNECTIONS Let's do another unit test with http request connections diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 740e048..d4dd59b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -538,14 +538,6 @@ private: { Log::info("Starting GET request handler for session [" + id + "]."); -#if MAX_CONNECTIONS > 0 -if (++LOOLWSD::NumConnections > MAX_CONNECTIONS) -{ -Log::error("Maximum number of connections reached."); -throw WebSocketErrorMessageException(Poco::format(SERVICE_UNAVALABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS, std::string(LOOLWSD_PRODUCT), std::string(LOOLWSD_URL), std::string(LOOLWSD_URL))); -} -#endif - // indicator to the client that document broker is searching std::string status("statusindicator: find"); Log::trace("Sending to Client [" + status + "]."); @@ -865,6 +857,15 @@ public: request, response)) return; +#if MAX_CONNECTIONS > 0 +if (++LOOLWSD::NumConnections > MAX_CONNECTIONS) +{ +--LOOLWSD::NumConnections; +Log::error("Maximum number of connections reached."); +throw WebSocketErrorMessageException(Poco::format(SERVICE_UNAVALABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS, std::string(LOOLWSD_PRODUCT), std::string(LOOLWSD_URL), std::string(LOOLWSD_URL))); +} +#endif + handleClientRequest(request,response); #if MAX_CONNECTIONS > 0 diff --git a/loolwsd/test/httpwserror.cpp b/loolwsd/test/httpwserror.cpp index 6a130bc..ab053b7 100644 --- a/loolwsd/test/httpwserror.cpp +++ b/loolwsd/test/httpwserror.cpp @@ -36,12 +36,12 @@ class HTTPWSError : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE(HTTPWSError); CPPUNIT_TEST(testMaxDocuments); -CPPUNIT_TEST(testMaxConnections); +//CPPUNIT_TEST(testMaxConnections); CPPUNIT_TEST_SUITE_END(); void testMaxDocuments(); -void testMaxConnections(); +//void testMaxConnections(); public: HTTPWSError() @@ -108,7 +108,7 @@ void HTTPWSError::testMaxDocuments() #endif } -void HTTPWSError::testMaxConnections() +/*void HTTPWSError::testMaxConnections() { #if MAX_CONNECTIONS > 0 try @@ -145,7 +145,7 @@ void HTTPWSError::testMaxConnections() CPPUNIT_FAIL(exc.displayText()); } #endif -} +}*/ CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSError); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp |9 - loolwsd/test/httpwstest.cpp | 25 + 2 files changed, 21 insertions(+), 13 deletions(-) New commits: commit 0a92e023394268dbd184250582c671556359c9f3 Author: Henry Castro Date: Sun Apr 17 08:42:07 2016 -0400 loolwsd: test: update changes to WebSocketErrorMessageException diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index f954a53..90a7843 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -504,10 +504,8 @@ private: if (!child) { // Let the client know we can't serve now. -status = "statusindicator: fail"; -ws->sendFrame(status.data(), (int) status.size()); -ws->shutdown(); -throw WebSocketException("Failed to get new child. Client cannot serve now.", WebSocket::WS_ENDPOINT_GOING_AWAY); +Log::error("Failed to get new child. Client cannot serve now."); +throw WebSocketErrorMessageException(SERVICE_UNAVALABLE_INTERNAL_ERROR); } // Set one we just created. @@ -685,7 +683,8 @@ public: { const std::string msg = std::string("error: ") + exc.what(); ws->sendFrame(msg.data(), msg.size()); -ws->shutdown(); +// abnormal close frame handshake +ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY, exc.what()); } catch (const std::exception& exc2) { diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index cda..9b917af 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -170,7 +171,7 @@ void HTTPWSTest::testBadRequest() session.setKeepAlive(true); session.sendRequest(request); session.receiveResponse(response); -CPPUNIT_ASSERT(response.getStatus() == Poco::Net::HTTPResponse::HTTP_BAD_REQUEST); +CPPUNIT_ASSERT(response.getStatus() == Poco::Net::HTTPResponse::HTTPResponse::HTTP_SERVICE_UNAVAILABLE); } catch (const Poco::Exception& exc) { @@ -199,7 +200,7 @@ void HTTPWSTest::testHandShake() Poco::Net::WebSocket socket(session, request, response); const std::string prefixEdit = "editlock:"; -const char* fail = "fail"; +const char* fail = "error:"; std::string payload("statusindicator: find"); std::string receive; @@ -233,18 +234,26 @@ void HTTPWSTest::testHandShake() } else { -payload = "statusindicator: fail"; -CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); -CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); +// check error message +CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr); CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); + +// close frame message +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); +CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr); +CPPUNIT_ASSERT((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) == Poco::Net::WebSocket::FRAME_OP_CLOSE); } } else { -payload = "statusindicator: fail"; -CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); -CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); +// check error message +CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr); CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); + +// close frame message +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); +CPPUNIT_ASSERT(std::strstr(buffer, SERVICE_UNAVALABLE_INTERNAL_ERROR) != nullptr); +CPPUNIT_ASSERT((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) == Poco::Net::WebSocket::FRAME_OP_CLOSE); } socket.shutdown(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp |9 - loolwsd/test/httpwstest.cpp | 40 +--- 2 files changed, 29 insertions(+), 20 deletions(-) New commits: commit a66e73aeb0789a87c6948e6c1e9a2fc3e13b3aa1 Author: Henry Castro Date: Sat Apr 16 13:29:00 2016 -0400 loolwsd: fail when document broker cannot get a child diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index a60d90d..802850b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -543,10 +543,10 @@ private: if (!child) { // Let the client know we can't serve now. - response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE); -response.setContentLength(0); -response.send(); -return; +status = "statusindicator: fail"; +ws->sendFrame(status.data(), (int) status.size()); +ws->shutdown(); +throw WebSocketException("Failed to get new child. Client cannot serve now.", WebSocket::WS_ENDPOINT_GOING_AWAY); } // Set one we just created. @@ -575,7 +575,6 @@ private: if (!waitBridgeCompleted(session, docBroker)) { -Log::error(session->getName() + ": Failed to connect to lokit process. Client cannot serve now."); // Let the client know we can't serve now. status = "statusindicator: fail"; ws->sendFrame(status.data(), (int) status.size()); diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index 91dfb79..cda 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -209,29 +209,39 @@ void HTTPWSTest::testHandShake() CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); -// After document broker finish searching it sends editlok -// it should be at end on handshake bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); -CPPUNIT_ASSERT(prefixEdit.compare(0, prefixEdit.size(), buffer, 0, prefixEdit.size()) == 0); -CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); - -payload = "statusindicator: connect"; -bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); -CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); -CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); -CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); - -bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); -if (std::strstr(buffer, fail)) +if (!std::strstr(buffer, fail)) { -payload = "statusindicator: fail"; +// After document broker finish searching it sends editlok +// it should be at end on handshake +CPPUNIT_ASSERT(prefixEdit.compare(0, prefixEdit.size(), buffer, 0, prefixEdit.size()) == 0); +CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); + +payload = "statusindicator: connect"; +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); + +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); +if (!std::strstr(buffer, fail)) +{ +payload = "statusindicator: ready"; +CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); +CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); +CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); +} +else +{ +payload = "statusindicator: fail"; +CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); +CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); +CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); +} } else { -payload = "statusindicator: ready"; +payload = "statusindicator: fail"; CPPUNIT_ASSERT_EQUAL((int) payload.size(), bytes); CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp | 21 +--- loolwsd/test/httpwstest.cpp | 72 +++- 2 files changed, 86 insertions(+), 7 deletions(-) New commits: commit 096f7db6d06ca2c66d7b69970853b83b03b3d914 Author: Henry Castro Date: Wed Apr 13 14:22:56 2016 -0400 loolwsd: report indicator status before websocket is ready diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 51ac2fe..e53906b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -518,6 +518,10 @@ private: throw; } +// indicator to the client that document broker is searching +std::string status("statusindicator: find"); +ws->sendFrame(status.data(), (int) status.size()); + const auto uriPublic = DocumentBroker::sanitizeURI(uri); const auto docKey = DocumentBroker::getDocKey(uriPublic); std::shared_ptr docBroker; @@ -561,24 +565,29 @@ private: // thread that handles them. This is so that we can empty the queue when we get a // "canceltiles" message. auto queue = std::make_shared(); - auto session = std::make_shared(id, LOOLSession::Kind::ToClient, ws, docBroker, queue); docBroker->addWSSession(id, session); auto wsSessionsCount = docBroker->getWSSessionsCount(); Log::trace(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); docBrokersLock.unlock(); +// indicator to a client that is waiting to connect to lokit process +status = "statusindicator: connect"; +ws->sendFrame(status.data(), (int) status.size()); + if (!waitBridgeCompleted(session, docBroker)) { -Log::error(session->getName() + ": Failed to connect to child. Client cannot serve now."); +Log::error(session->getName() + ": Failed to connect to lokit process. Client cannot serve now."); // Let the client know we can't serve now. - response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE); -response.setContentLength(0); -response.send(); -return; +status = "statusindicator: fail"; +ws->sendFrame(status.data(), (int) status.size()); +ws->shutdown(); +throw WebSocketException("Failed to connect to lokit process", WebSocket::WS_ENDPOINT_GOING_AWAY); } // Now the bridge beetween the client and kit process is connected // Let messages flow +status = "statusindicator: ready"; +ws->sendFrame(status.data(), (int) status.size()); QueueHandler handler(queue, session, "wsd_queue_" + session->getId()); diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp index cf015b5..168242b 100644 --- a/loolwsd/test/httpwstest.cpp +++ b/loolwsd/test/httpwstest.cpp @@ -49,6 +49,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testCountHowManyLoolkits); CPPUNIT_TEST(testBadRequest); +CPPUNIT_TEST(testHandShake); CPPUNIT_TEST(testLoad); CPPUNIT_TEST(testBadLoad); CPPUNIT_TEST(testReload); @@ -70,6 +71,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testCountHowManyLoolkits(); void testBadRequest(); +void testHandShake(); void testLoad(); void testBadLoad(); void testReload(); @@ -172,6 +174,73 @@ void HTTPWSTest::testBadRequest() } } +void HTTPWSTest::testHandShake() +{ +try +{ +int bytes; +int flags; +char buffer[1024]; +// Load a document and get its status. +const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt"); +const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString(); + +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 +Poco::Net::WebSocket socket(session, request, response); + +const std::string prefixEdit = "editlock:"; +const char* fail = "fail"; +std::string payload("statusindicator: find"); + +std::string receive; +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); +CPPUNIT_ASSERT(bytes == (int) payload.size()); +CPPUNIT_ASSERT(payload.compare(0, payload.size(), buffer, 0, bytes) == 0); +CPPUNIT_ASSERT(flags == Poco::Net::WebSocket::FRAME_TEXT); + +// After document broker finish searching it sends editlok +// it should be at end on handshake +bytes = socket.receiveFrame(buffer, sizeof(buffer), flags); +CPPUNIT_ASSERT(prefixEdit.compare(0, prefixEdit.size(), buffer, 0, prefixEdit.size()) == 0); +CPPUNIT_ASSERT(fla
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp | 15 ++- loolwsd/test/httpwstest.cpp | 33 + 2 files changed, 47 insertions(+), 1 deletion(-) New commits: commit 6701dc62ce1c49f7d79ac54dd7123e602826207b Author: Henry Castro 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 ws; +try +{ +ws = std::make_shared(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 docBroker; @@ -548,7 +562,6 @@ private: // "canceltiles" message. auto queue = std::make_shared(); -auto ws = std::make_shared(request, response); auto session = std::make_shared(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 ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/test
loolwsd/LOOLWSD.cpp |9 - loolwsd/test/httpposttest.cpp |2 +- 2 files changed, 5 insertions(+), 6 deletions(-) New commits: commit 36a3810541f82d1f9bf001c6e50bf63c40b787a1 Author: Ashod Nakashian Date: Mon Apr 4 22:50:57 2016 -0400 loolwsd: fixed convert-to and re-enabled test Change-Id: I91ad9ac7dbe394d4a560081379e35442f1469eb8 Reviewed-on: https://gerrit.libreoffice.org/23825 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 6b05fca..93e65ee 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -291,17 +291,16 @@ private: // In that case, we can use a pool and index by publicPath. std::unique_lock lock(docBrokersMutex); +//FIXME: What if the same document is already open? Need a fake dockey here. Log::debug("New DocumentBroker for docKey [" + docKey + "]."); docBrokers.emplace(docKey, docBroker); -// Request a kit process for this doc. -const std::string aMessage = "request " + id + " " + docKey + "\n"; -Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1)); -IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage); - // Load the document. std::shared_ptr ws; auto session = std::make_shared(id, LOOLSession::Kind::ToClient, ws, docBroker, nullptr); +docBroker->addWSSession(id, session); +unsigned wsSessionsCount = docBroker->getWSSessionsCount(); +Log::warn(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); session->setEditLock(true); docBroker->incSessions(); lock.unlock(); diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp index a4b0b03..2a39f58 100644 --- a/loolwsd/test/httpposttest.cpp +++ b/loolwsd/test/httpposttest.cpp @@ -28,7 +28,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(HTTPPostTest); -//CPPUNIT_TEST(testConvertTo); +CPPUNIT_TEST(testConvertTo); CPPUNIT_TEST_SUITE_END(); void testConvertTo(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits