2019-10-29 08:26:27 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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 UnitWOPIWatermark : public WopiTestServer
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
STATE_ENUM(Phase, Load, TileRequest, Done)
|
|
|
|
_phase;
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWOPIWatermark()
|
|
|
|
: WopiTestServer("UnitWOPIWatermark")
|
|
|
|
, _phase(Phase::Load)
|
2019-10-29 08:26:27 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2023-01-23 15:53:27 -06:00
|
|
|
LOG_INF("FakeWOPIHost: Request: " << uriReq.toString());
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
// CheckFileInfo
|
|
|
|
if (request.getMethod() == "GET" && regInfo.match(uriReq.getPath()))
|
|
|
|
{
|
2023-01-23 15:53:27 -06:00
|
|
|
LOG_INF("FakeWOPIHost: Handling CheckFileInfo: " << uriReq.getPath());
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
assertCheckFileInfoRequest(request);
|
|
|
|
|
|
|
|
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", fileName);
|
|
|
|
fileInfo->set("Size", getFileContent().size());
|
|
|
|
fileInfo->set("Version", "1.0");
|
|
|
|
fileInfo->set("OwnerId", "test");
|
|
|
|
fileInfo->set("UserId", "test");
|
|
|
|
fileInfo->set("UserFriendlyName", "test");
|
|
|
|
fileInfo->set("UserCanWrite", "true");
|
|
|
|
fileInfo->set("PostMessageOrigin", "localhost");
|
|
|
|
fileInfo->set("LastModifiedTime", Util::getIso8601FracformatTime(getFileLastModifiedTime()));
|
|
|
|
fileInfo->set("EnableOwnerTermination", "true");
|
|
|
|
fileInfo->set("WatermarkText", "WatermarkTest");
|
|
|
|
|
|
|
|
std::ostringstream jsonStream;
|
|
|
|
fileInfo->stringify(jsonStream);
|
|
|
|
|
2023-01-16 17:38:59 -06:00
|
|
|
http::Response httpResponse(http::StatusCode::OK);
|
2022-02-01 07:33:25 -06:00
|
|
|
httpResponse.set("Last-Modified", Util::getHttpTime(getFileLastModifiedTime()));
|
|
|
|
httpResponse.setBody(jsonStream.str(), "application/json; charset=utf-8");
|
|
|
|
socket->sendAndShutdown(httpResponse);
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// GetFile
|
|
|
|
else if (request.getMethod() == "GET" && regContent.match(uriReq.getPath()))
|
|
|
|
{
|
2023-01-23 15:53:27 -06:00
|
|
|
LOG_INF("FakeWOPIHost: Handling GetFile: " << uriReq.getPath());
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
assertGetFileRequest(request);
|
|
|
|
|
2023-01-16 17:38:59 -06:00
|
|
|
http::Response httpResponse(http::StatusCode::OK);
|
2022-02-01 07:33:25 -06:00
|
|
|
httpResponse.set("Last-Modified", Util::getHttpTime(getFileLastModifiedTime()));
|
|
|
|
httpResponse.setBody(getFileContent(), "text/plain; charset=utf-8");
|
|
|
|
socket->sendAndShutdown(httpResponse);
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override
|
2019-10-29 08:26:27 -05:00
|
|
|
{
|
|
|
|
constexpr char testName[] = "UnitWOPIWatermark";
|
|
|
|
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::TileRequest);
|
2019-10-29 08:26:27 -05:00
|
|
|
|
2022-07-22 18:54:44 -05:00
|
|
|
initWebsocket("/wopi/files/5?access_token=anything");
|
2019-10-29 08:26:27 -05:00
|
|
|
|
2022-07-22 18:54:44 -05:00
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
2019-10-29 08:26:27 -05:00
|
|
|
break;
|
|
|
|
}
|
2022-07-22 18:54:44 -05:00
|
|
|
case Phase::Done:
|
2019-10-29 08:26:27 -05:00
|
|
|
{
|
|
|
|
exitTest(TestResult::Ok);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::TileRequest:
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
WSD_CMD("tilecombine nviewid=0 part=0 width=256 height=256 tileposx=0,3840 "
|
|
|
|
"tileposy=0,0 tilewidth=3840 tileheight=3840");
|
2022-07-19 18:09:10 -05:00
|
|
|
std::string tile =
|
|
|
|
helpers::getResponseString(getWs()->getWebSocket(), "tile:", testName);
|
2019-10-29 08:26:27 -05:00
|
|
|
|
|
|
|
if(!tile.empty())
|
|
|
|
{
|
2022-03-29 20:37:57 -05:00
|
|
|
StringVector tokens(StringVector::tokenize(tile, ' '));
|
2019-10-29 08:26:27 -05:00
|
|
|
std::string nviewid = tokens[1].substr(std::string("nviewid=").size());
|
|
|
|
if (!nviewid.empty() && nviewid != "0")
|
|
|
|
{
|
|
|
|
LOG_INF("Watermark is hashed into integer successfully nviewid=" << nviewid);
|
2022-07-22 18:54:44 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::Done);
|
2019-10-29 08:26:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitWOPIWatermark();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|