2022-02-05 17:14:38 -06: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 "WOPIUploadConflictCommon.hpp"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
|
|
|
|
#include "Util.hpp"
|
|
|
|
#include "Log.hpp"
|
|
|
|
#include "Unit.hpp"
|
|
|
|
#include "UnitHTTP.hpp"
|
|
|
|
#include "helpers.hpp"
|
|
|
|
#include "lokassert.hpp"
|
|
|
|
|
|
|
|
class UnitWOPISaveOnExit : public WOPIUploadConflictCommon
|
|
|
|
{
|
2022-02-19 18:57:47 -06:00
|
|
|
using Base = WOPIUploadConflictCommon;
|
2022-02-05 17:14:38 -06:00
|
|
|
|
2022-02-19 18:57:47 -06:00
|
|
|
using Base::Phase;
|
|
|
|
using Base::Scenario;
|
|
|
|
|
|
|
|
using Base::ConflictingDocContent;
|
|
|
|
using Base::ModifiedOriginalDocContent;
|
|
|
|
using Base::OriginalDocContent;
|
2022-02-05 17:14:38 -06:00
|
|
|
|
|
|
|
public:
|
|
|
|
UnitWOPISaveOnExit()
|
2022-02-19 18:57:47 -06:00
|
|
|
: Base("UnitWOPISaveOnExit", OriginalDocContent)
|
2022-02-05 17:14:38 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-10 05:45:22 -06:00
|
|
|
void configure(Poco::Util::LayeredConfiguration& config) override
|
2022-02-05 17:14:38 -06:00
|
|
|
{
|
2022-02-19 18:57:47 -06:00
|
|
|
Base::configure(config);
|
2022-02-05 17:14:38 -06:00
|
|
|
|
2022-02-16 19:07:23 -06:00
|
|
|
// Small value to shorten the test run time.
|
|
|
|
config.setUInt("per_document.limit_store_failures", 2);
|
2022-02-05 17:14:38 -06:00
|
|
|
config.setBool("per_document.always_save_on_exit", true);
|
|
|
|
}
|
|
|
|
|
2022-02-16 19:07:23 -06:00
|
|
|
void assertGetFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
|
|
|
|
{
|
|
|
|
LOG_TST("Testing " << toString(_scenario));
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
assertGetFileCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-26 15:55:04 -06:00
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
|
2022-02-05 17:14:38 -06:00
|
|
|
{
|
|
|
|
LOG_TST("Testing " << toString(_scenario));
|
2022-02-26 15:55:04 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
2022-02-05 17:14:38 -06:00
|
|
|
|
2022-02-16 19:07:23 -06:00
|
|
|
assertPutFileCount();
|
|
|
|
|
2022-02-05 17:14:38 -06:00
|
|
|
switch (_scenario)
|
|
|
|
{
|
|
|
|
case Scenario::Disconnect:
|
2022-02-26 15:55:04 -06:00
|
|
|
LOG_TST("Clobbered in the disconnect scenario");
|
2022-02-05 17:14:38 -06:00
|
|
|
break;
|
|
|
|
case Scenario::SaveDiscard:
|
|
|
|
case Scenario::CloseDiscard:
|
2022-02-26 15:55:04 -06:00
|
|
|
case Scenario::VerifyOverwrite:
|
|
|
|
break;
|
2022-02-05 17:14:38 -06:00
|
|
|
case Scenario::SaveOverwrite:
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Unexpected contents in storage",
|
2022-02-26 15:54:47 -06:00
|
|
|
std::string(ConflictingDocContent), getFileContent());
|
2022-02-26 15:55:04 -06:00
|
|
|
LOG_TST("Closing the document to verify its contents after reloading");
|
|
|
|
WSD_CMD("closedocument");
|
2022-02-05 17:14:38 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-26 15:55:04 -06:00
|
|
|
return nullptr;
|
2022-02-05 17:14:38 -06:00
|
|
|
}
|
|
|
|
|
2022-02-26 15:55:04 -06:00
|
|
|
void onDocBrokerCreate(const std::string& docKey) override
|
2022-02-05 17:14:38 -06:00
|
|
|
{
|
2022-02-26 15:55:04 -06:00
|
|
|
Base::onDocBrokerCreate(docKey);
|
|
|
|
|
|
|
|
// When overwriting, we will do so twice.
|
|
|
|
// Once to find out that we have a conflict and another time to force it.
|
|
|
|
if (_scenario == Scenario::SaveOverwrite)
|
|
|
|
{
|
|
|
|
setExpectedPutFile(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// With always_save_on_exit, we expect exactly one PutFile per document.
|
|
|
|
if (_scenario == Scenario::VerifyOverwrite)
|
|
|
|
{
|
|
|
|
//FIXME: this uncovers a bug with unmodified files!
|
|
|
|
setExpectedPutFile(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setExpectedPutFile(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDocBrokerDestroy(const std::string& docKey) override
|
|
|
|
{
|
|
|
|
LOG_TST("Testing " << toString(_scenario) << " with dockey [" << docKey << "] closed.");
|
2022-02-05 17:14:38 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
|
2022-02-26 15:55:04 -06:00
|
|
|
std::string expectedContents;
|
2022-02-05 17:14:38 -06:00
|
|
|
switch (_scenario)
|
|
|
|
{
|
|
|
|
case Scenario::Disconnect:
|
2022-02-26 15:55:04 -06:00
|
|
|
expectedContents = ModifiedOriginalDocContent; //TODO: save-as in this case.
|
2022-02-05 17:14:38 -06:00
|
|
|
break;
|
|
|
|
case Scenario::SaveDiscard:
|
2022-02-26 15:55:04 -06:00
|
|
|
expectedContents = ConflictingDocContent;
|
|
|
|
break;
|
2022-02-05 17:14:38 -06:00
|
|
|
case Scenario::CloseDiscard:
|
2022-02-26 15:55:04 -06:00
|
|
|
expectedContents = ConflictingDocContent;
|
2022-02-05 17:14:38 -06:00
|
|
|
break;
|
|
|
|
case Scenario::SaveOverwrite:
|
2022-02-26 15:55:04 -06:00
|
|
|
expectedContents = ModifiedOriginalDocContent;
|
|
|
|
break;
|
|
|
|
case Scenario::VerifyOverwrite:
|
|
|
|
expectedContents = OriginalDocContent;
|
2022-02-05 17:14:38 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-26 15:55:04 -06:00
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Unexpected contents in storage", expectedContents,
|
|
|
|
getFileContent());
|
|
|
|
|
|
|
|
Base::onDocBrokerDestroy(docKey);
|
2022-02-05 17:14:38 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWOPISaveOnExit(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|