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 6781c59c0209730c813c1161cefe4964a4cbc49b
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Wed May 15 22:14:29 2019 -0400
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jun 11 14:36:27 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>
    Reviewed-on: https://gerrit.libreoffice.org/72889

diff --git a/test/Makefile.am b/test/Makefile.am
index bf6d5a473..eacb3355a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,7 +20,8 @@ noinst_LTLIBRARIES = \
        unit-fuzz.la unit-oob.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
@@ -108,6 +109,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
@@ -125,7 +128,8 @@ check-local:
 TESTS = 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-wopi-documentconflict.la unit_wopi_renamefile.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 b71212f0f..0c7770a09 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -96,18 +96,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");
@@ -139,7 +142,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());
 
@@ -161,7 +164,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";
@@ -195,7 +198,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 7731776a8..7ef373763 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -726,7 +726,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();
 
@@ -1144,6 +1144,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

Reply via email to