2018-11-07 17:00:32 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2018-11-07 17:00:32 -06:00
|
|
|
* 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 <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
#include <Common.hpp>
|
|
|
|
#include <Protocol.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <Util.hpp>
|
|
|
|
#include <FileUtil.hpp>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTMLForm.h>
|
|
|
|
#include <Poco/Net/StringPartSource.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
|
|
|
// Inside the WSD process
|
|
|
|
class UnitConvert : public UnitWSD
|
|
|
|
{
|
|
|
|
bool _workerStarted;
|
|
|
|
std::thread _worker;
|
|
|
|
|
|
|
|
public:
|
2022-02-16 16:22:18 -06:00
|
|
|
UnitConvert()
|
|
|
|
: UnitWSD("UnitConvert")
|
|
|
|
, _workerStarted(false)
|
2018-11-07 17:00:32 -06:00
|
|
|
{
|
|
|
|
setHasKitHooks();
|
2020-12-14 13:00:55 -06:00
|
|
|
setTimeout(std::chrono::hours(1));
|
2018-11-07 17:00:32 -06:00
|
|
|
}
|
2020-12-14 13:00:55 -06:00
|
|
|
|
2018-11-07 17:00:32 -06:00
|
|
|
~UnitConvert()
|
|
|
|
{
|
|
|
|
LOG_INF("Joining test worker thread\n");
|
|
|
|
_worker.join();
|
|
|
|
}
|
|
|
|
|
|
|
|
void configure(Poco::Util::LayeredConfiguration& config) override
|
|
|
|
{
|
|
|
|
UnitWSD::configure(config);
|
|
|
|
|
|
|
|
config.setBool("ssl.enable", true);
|
2020-09-30 16:24:50 -05:00
|
|
|
config.setInt("per_document.limit_load_secs", 30);
|
2020-11-22 16:36:44 -06:00
|
|
|
config.setBool("storage.filesystem[@allow]", false);
|
2020-09-30 16:24:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void sendConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session, const std::string& filename)
|
|
|
|
{
|
2021-11-15 09:41:58 -06:00
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/cool/convert-to/pdf");
|
2020-09-30 16:24:50 -05:00
|
|
|
Poco::Net::HTMLForm form;
|
|
|
|
form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
|
|
|
|
form.set("format", "txt");
|
|
|
|
form.addPart("data", new Poco::Net::StringPartSource("Hello World Content", "text/plain", filename));
|
|
|
|
form.prepareSubmit(request);
|
|
|
|
form.write(session->sendRequest(request));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session)
|
|
|
|
{
|
|
|
|
Poco::Net::HTTPResponse response;
|
|
|
|
try {
|
|
|
|
session->receiveResponse(response);
|
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.getStatus() == Poco::Net::HTTPResponse::HTTPStatus::HTTP_OK;
|
2018-11-07 17:00:32 -06:00
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override
|
2018-11-07 17:00:32 -06:00
|
|
|
{
|
|
|
|
if (_workerStarted)
|
|
|
|
return;
|
|
|
|
_workerStarted = true;
|
|
|
|
std::cerr << "Starting thread ...\n";
|
|
|
|
_worker = std::thread([this]{
|
|
|
|
std::cerr << "Now started thread ...\n";
|
|
|
|
std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(Poco::URI(helpers::getTestServerURI())));
|
2020-09-30 16:24:50 -05:00
|
|
|
session->setTimeout(Poco::Timespan(30, 0)); // 30 seconds.
|
|
|
|
|
|
|
|
sendConvertTo(session, "foo.txt");
|
|
|
|
if(!checkConvertTo(session))
|
|
|
|
{
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendConvertTo(session, "test___á.txt");
|
|
|
|
if(!checkConvertTo(session))
|
|
|
|
{
|
|
|
|
exitTest(TestResult::Failed);
|
2018-11-07 17:00:32 -06:00
|
|
|
return;
|
2020-09-30 16:24:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
exitTest(TestResult::Ok);
|
2018-11-07 17:00:32 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Inside the forkit & kit processes
|
|
|
|
class UnitKitConvert : public UnitKit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UnitKitConvert()
|
2022-04-21 18:14:16 -05:00
|
|
|
: UnitKit("UnitKitConvert")
|
2018-11-07 17:00:32 -06:00
|
|
|
{
|
2020-12-14 13:00:55 -06:00
|
|
|
setTimeout(std::chrono::hours(1));
|
2018-11-07 17:00:32 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitConvert();
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase *unit_create_kit(void)
|
|
|
|
{
|
|
|
|
return new UnitKitConvert();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|