test/Makefile.am | 8 +++- test/UnitWOPILoadEncoded.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++ test/WopiTestServer.hpp | 13 ++++--- wsd/DocumentBroker.cpp | 7 +++- 4 files changed, 91 insertions(+), 8 deletions(-)
New commits: commit 898c47fbb42b6093c6d31bdd08c605f9b0bc0de2 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed May 15 22:14:29 2019 -0400 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Fri May 24 08:57:36 2019 +0200 wsd: fix the exception "Bad URI syntax" if the file name has '%' character it throws exception "Bad URI syntax", so use the encoded file name string Change-Id: I6a8d841761b46ac49a6c79956ba215e1affa53e5 Reviewed-on: https://gerrit.libreoffice.org/72385 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> (cherry picked from commit b934c70f4f1f9f3ee4f873570633a3b1ec931652) Reviewed-on: https://gerrit.libreoffice.org/72890 diff --git a/test/Makefile.am b/test/Makefile.am index eed2abd5d..f1f43aee9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,7 +20,8 @@ noinst_LTLIBRARIES = \ unit-fuzz.la unit-oob.la unit-http.la unit-oauth.la \ unit-wopi.la unit-wopi-saveas.la \ unit-wopi-ownertermination.la unit-wopi-versionrestore.la \ - unit-wopi-documentconflict.la unit_wopi_renamefile.la + unit-wopi-documentconflict.la unit_wopi_renamefile.la \ + unit-wopi-loadencoded.la MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy @@ -113,6 +114,8 @@ unit_wopi_documentconflict_la_SOURCES = UnitWOPIDocumentConflict.cpp unit_wopi_documentconflict_la_LIBADD = $(CPPUNIT_LIBS) unit_wopi_renamefile_la_SOURCES = UnitWOPIRenameFile.cpp unit_wopi_renamefile_la_LIBADD = $(CPPUNIT_LIBS) +unit_wopi_loadencoded_la_SOURCES = UnitWOPILoadEncoded.cpp +unit_wopi_loadencoded_la_LIBADD = $(CPPUNIT_LIBS) if HAVE_LO_PATH SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp @@ -132,7 +135,8 @@ TESTS = unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la \ unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la \ unit-wopi-ownertermination.la unit-wopi-versionrestore.la \ unit-wopi-documentconflict.la unit_wopi_renamefile.la \ - unit-http.la + unit-http.la \ + unit-wopi-loadencoded.la # TESTS = unit-client.la # TESTS += unit-admin.la # TESTS += unit-storage.la diff --git a/test/UnitWOPILoadEncoded.cpp b/test/UnitWOPILoadEncoded.cpp new file mode 100644 index 000000000..8a0bb3ebd --- /dev/null +++ b/test/UnitWOPILoadEncoded.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <config.h> + +#include <WopiTestServer.hpp> +#include <Log.hpp> +#include <Unit.hpp> +#include <UnitHTTP.hpp> +#include <helpers.hpp> +#include <Poco/Net/HTTPRequest.h> +#include <Poco/Util/LayeredConfiguration.h> + +class UnitWOPILoadEncoded : public WopiTestServer +{ + enum class Phase + { + LoadEncoded, + CloseDoc, + Polling + } _phase; + +public: + UnitWOPILoadEncoded() : + _phase(Phase::LoadEncoded) + { + } + + void invokeTest() override + { + constexpr char testName[] = "UnitWOPILoadEncoded"; + + switch (_phase) + { + case Phase::LoadEncoded: + { + initWebsocket("/wopi/files/3?access_token=anything"); + + helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName); + SocketPoll::wakeupWorld(); + + _phase = Phase::CloseDoc; + break; + } + case Phase::CloseDoc: + { + helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "closedocument", testName); + _phase = Phase::Polling; + break; + } + case Phase::Polling: + { + exitTest(TestResult::Ok); + break; + } + } + } +}; + +UnitBase *unit_create_wsd(void) +{ + return new UnitWOPILoadEncoded(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp index 8d5fb4bdf..5d64e7911 100644 --- a/test/WopiTestServer.hpp +++ b/test/WopiTestServer.hpp @@ -102,18 +102,21 @@ protected: virtual bool handleHttpRequest(const Poco::Net::HTTPRequest& request, Poco::MemoryInputStream& message, std::shared_ptr<StreamSocket>& socket) override { Poco::URI uriReq(request.getURI()); + Poco::RegularExpression regInfo("/wopi/files/[0-9]"); + Poco::RegularExpression regContent("/wopi/files/[0-9]/contents"); LOG_INF("Fake wopi host request: " << uriReq.toString()); // CheckFileInfo - if (request.getMethod() == "GET" && (uriReq.getPath() == "/wopi/files/0" || uriReq.getPath() == "/wopi/files/1")) + if (request.getMethod() == "GET" && regInfo.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling CheckFileInfo: " << uriReq.getPath()); assertCheckFileInfoRequest(request); Poco::LocalDateTime now; + const std::string fileName(uriReq.getPath() == "/wopi/files/3" ? "he%llo.txt" : "hello.txt"); Poco::JSON::Object::Ptr fileInfo = new Poco::JSON::Object(); - fileInfo->set("BaseFileName", "hello.txt"); + fileInfo->set("BaseFileName", fileName); fileInfo->set("Size", _fileContent.size()); fileInfo->set("Version", "1.0"); fileInfo->set("OwnerId", "test"); @@ -145,7 +148,7 @@ protected: return true; } // GetFile - else if (request.getMethod() == "GET" && (uriReq.getPath() == "/wopi/files/0/contents" || uriReq.getPath() == "/wopi/files/1/contents")) + else if (request.getMethod() == "GET" && regContent.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling GetFile: " << uriReq.getPath()); @@ -167,7 +170,7 @@ protected: return true; } - else if (request.getMethod() == "POST" && (uriReq.getPath() == "/wopi/files/0" || uriReq.getPath() == "/wopi/files/1")) + else if (request.getMethod() == "POST" && regInfo.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling PutRelativeFile: " << uriReq.getPath()); std::string wopiURL = helpers::getTestServerURI() + "/something wopi/files/1?access_token=anything"; @@ -201,7 +204,7 @@ protected: return true; } - else if (request.getMethod() == "POST" && (uriReq.getPath() == "/wopi/files/0/contents" || uriReq.getPath() == "/wopi/files/1/contents")) + else if (request.getMethod() == "POST" && regContent.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling PutFile: " << uriReq.getPath()); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index eb8fb1eee..30f0619c6 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -742,7 +742,7 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s std::string localPathEncoded; Poco::URI::encode(localPath, "#", localPathEncoded); _uriJailed = Poco::URI(Poco::URI("file://"), localPathEncoded).toString(); - _uriJailedAnonym = Poco::URI(Poco::URI("file://"), LOOLWSD::anonymizeUrl(localPath)).toString(); + _uriJailedAnonym = Poco::URI(Poco::URI("file://"), LOOLWSD::anonymizeUrl(localPathEncoded)).toString(); _filename = fileInfo.getFilename(); @@ -1167,6 +1167,11 @@ size_t DocumentBroker::addSessionInternal(const std::shared_ptr<ClientSession>& alertAllUsers("internal", "diskfull"); throw; } + catch (const std::exception& exc) + { + LOG_ERR("loading document exception: " << exc.what()); + throw; + } const std::string id = session->getId(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits