From f4c1a7f775a03dea3b804db9754159f524947a54 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Mon, 21 Jun 2021 14:23:18 +0200 Subject: HTTP 302 Found - remember the correct resource address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: Id14c5209eb1d9ffc7c24d7e02f0c7c32a60568b7 --- test/UnitWOPIHttpRedirect.cpp | 49 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'test') 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; } } -- cgit