diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-06-21 14:23:18 +0200 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2021-06-28 11:04:39 +0200 |
commit | f4c1a7f775a03dea3b804db9754159f524947a54 (patch) | |
tree | 21075b00b3c13684104cc48244d40eaa71bec534 | |
parent | HTTP 302 Found - redirrect support for getWOPIFileInfo (diff) | |
download | online-f4c1a7f775a03dea3b804db9754159f524947a54.tar.gz online-f4c1a7f775a03dea3b804db9754159f524947a54.zip |
HTTP 302 Found - remember the correct resource address
remember correct URI so all the following communication
(eg. downloading the file, upload) will be performed on new location.
Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: Id14c5209eb1d9ffc7c24d7e02f0c7c32a60568b7
-rw-r--r-- | test/UnitWOPIHttpRedirect.cpp | 49 | ||||
-rw-r--r-- | wsd/Storage.cpp | 1 | ||||
-rw-r--r-- | wsd/Storage.hpp | 5 |
3 files changed, 48 insertions, 7 deletions
diff --git a/test/UnitWOPIHttpRedirect.cpp b/test/UnitWOPIHttpRedirect.cpp index fc4ae9cc98..9ede5e898a 100644 --- a/test/UnitWOPIHttpRedirect.cpp +++ b/test/UnitWOPIHttpRedirect.cpp @@ -21,6 +21,8 @@ class UnitWopiHttpRedirect : public WopiTestServer { Load, Redirected, + GetFile, + Loaded } _phase; const std::string params = "access_token=anything"; @@ -39,20 +41,22 @@ public: { Poco::URI uriReq(request.getURI()); Poco::RegularExpression regInfo("/wopi/files/1"); - Poco::RegularExpression regContents("/wopi/files/[0-9]/contents"); std::string redirectUri = "/wopi/files/0"; Poco::RegularExpression regRedirected(redirectUri); + Poco::RegularExpression regContents("/wopi/files/0/contents"); LOG_INF("Fake wopi host request URI [" << uriReq.toString() << "]:\n"); // CheckFileInfo - returns redirect response - if (request.getMethod() == "GET" && regInfo.match(uriReq.getPath()) && !regContents.match(uriReq.getPath())) + if (request.getMethod() == "GET" && regInfo.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling CheckFileInfo (1/2)"); - LOK_ASSERT_MESSAGE("Expected to be in Phase::Load", _phase == Phase::Load); assertCheckFileInfoRequest(request); + LOK_ASSERT_MESSAGE("Expected to be in Phase::Load", _phase == Phase::Load); + _phase = Phase::Redirected; + std::ostringstream oss; oss << "HTTP/1.1 302 Found\r\n" "Location: " << helpers::getTestServerURI() << redirectUri << "?" << params << "\r\n" @@ -61,18 +65,19 @@ public: socket->send(oss.str()); socket->shutdown(); - _phase = Phase::Redirected; - return true; } // CheckFileInfo - for redirected URI else if (request.getMethod() == "GET" && regRedirected.match(uriReq.getPath()) && !regContents.match(uriReq.getPath())) { LOG_INF("Fake wopi host request, handling CheckFileInfo: (2/2)"); - LOK_ASSERT_MESSAGE("Expected to be in Phase::Redirected", _phase == Phase::Redirected); assertCheckFileInfoRequest(request); + LOK_ASSERT_MESSAGE("Expected to be in Phase::Redirected or Phase::Loaded", _phase == Phase::Redirected || _phase == Phase::Loaded); + if (_phase == Phase::Redirected) + _phase = Phase::GetFile; + 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(); @@ -105,6 +110,32 @@ public: socket->send(oss.str()); socket->shutdown(); + return true; + } + // GetFile - for redirected URI + else if (request.getMethod() == "GET" && regContents.match(uriReq.getPath())) + { + LOG_TST("Fake wopi host request, handling GetFile: " << uriReq.getPath()); + + assertGetFileRequest(request); + + LOK_ASSERT_MESSAGE("Expected to be in Phase::GetFile", _phase == Phase::GetFile); + _phase = Phase::Loaded; + + const std::string mimeType = "text/plain; charset=utf-8"; + + std::ostringstream oss; + oss << "HTTP/1.1 200 OK\r\n" + "Last-Modified: " << Util::getHttpTime(_fileLastModifiedTime) << "\r\n" + "User-Agent: " WOPI_AGENT_STRING "\r\n" + "Content-Length: " << _fileContent.size() << "\r\n" + "Content-Type: " << mimeType << "\r\n" + "\r\n" + << _fileContent; + + socket->send(oss.str()); + socket->shutdown(); + exitTest(TestResult::Ok); return true; @@ -127,7 +158,13 @@ public: break; } case Phase::Redirected: + case Phase::GetFile: + { + break; + } + case Phase::Loaded: { + exitTest(TestResult::Ok); break; } } diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 94be72f5ea..b153cfb6d8 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -686,6 +686,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfoForUri(Po LOG_TRC("WOPI::CheckFileInfo redirect to URI [" << LOOLWSD::anonymizeUrl(location) << "]:\n"); Poco::URI redirectUriObject(location); + setUri(redirectUriObject); return getWOPIFileInfoForUri(redirectUriObject, auth, cookies, lockCtx); } diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index 5fbe044064..d9766c05d3 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -338,6 +338,9 @@ public: protected: + /// Saves new URI when resource was moved + void setUri(const Poco::URI& uri) { _uri = uri; } + /// Returns the root path of the jail directory of docs. std::string getLocalRootPath() const; @@ -345,7 +348,7 @@ protected: const std::string& getExtendedData() const { return _extendedData; } private: - const Poco::URI _uri; + Poco::URI _uri; const std::string _localStorePath; const std::string _jailPath; std::string _jailedFilePath; |