Skip to content

Commit

Permalink
wsd: move RedirectionLimit to Common.hpp
Browse files Browse the repository at this point in the history
Change-Id: Ia1f0710a8cd078a65913ee41c937402b577685f6
Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod committed Sep 12, 2024
1 parent e6fdd15 commit 2f78932
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
3 changes: 3 additions & 0 deletions common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ constexpr long READ_BUFFER_SIZE = 64 * 1024;
/// or as intentionally flooding the server.
constexpr int MAX_MESSAGE_SIZE = 2 * 1024 * READ_BUFFER_SIZE;

/// Limits number of HTTP redirections to prevent endless redirection loops.
static constexpr int HTTP_REDIRECTION_LIMIT = 21;

constexpr const char JAILED_DOCUMENT_ROOT[] = "/tmp/user/docs/";
constexpr const char CHILD_URI[] = "/coolws/child?";
constexpr const char NEW_CHILD_URI[] = "/coolws/newchild";
Expand Down
6 changes: 3 additions & 3 deletions test/UnitWOPIHttpRedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ class UnitWopiHttpRedirectLoop : public WopiTestServer
assertCheckFileInfoRequest(request);

std::string sExpectedMessage = "It is expected to stop requesting after " +
std::to_string(RedirectionLimit) + " redirections";
LOK_ASSERT_MESSAGE(sExpectedMessage, redirectionCount <= RedirectionLimit);
std::to_string(HTTP_REDIRECTION_LIMIT) + " redirections";
LOK_ASSERT_MESSAGE(sExpectedMessage, redirectionCount <= HTTP_REDIRECTION_LIMIT);

LOK_ASSERT_MESSAGE("Expected to be in Phase::Load or Phase::Redirected",
_phase == Phase::Load || _phase == Phase::Redirected);

if (redirectionCount == RedirectionLimit)
if (redirectionCount == HTTP_REDIRECTION_LIMIT)
{
exitTest(TestResult::Ok);
return true;
Expand Down
2 changes: 1 addition & 1 deletion wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ bool DocumentBroker::download(
auto poller = std::make_shared<TerminatingPoll>("CFISynReqPoll");
poller->runOnClientThread();
CheckFileInfo checkFileInfo(poller, session->getPublicUri(), [](CheckFileInfo&) {});
checkFileInfo.checkFileInfoSync(RedirectionLimit);
checkFileInfo.checkFileInfoSync(HTTP_REDIRECTION_LIMIT);
wopiFileInfo = checkFileInfo.wopiFileInfo(session->getPublicUri());
if (!wopiFileInfo)
{
Expand Down
4 changes: 2 additions & 2 deletions wsd/RequestVettingStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void RequestVettingStation::handleRequest(const std::string& id)
<< docKey << "] is for a WOPI document");

// CheckFileInfo asynchronously.
checkFileInfo(uriPublic, isReadOnly, RedirectionLimit);
checkFileInfo(uriPublic, isReadOnly, HTTP_REDIRECTION_LIMIT);
break;
#endif //!MOBILEAPP
}
Expand Down Expand Up @@ -254,7 +254,7 @@ void RequestVettingStation::handleRequest(const std::string& id,
{
// We haven't tried or we timed-out. Retry.
_checkFileInfo.reset();
checkFileInfo(uriPublic, isReadOnly, RedirectionLimit);
checkFileInfo(uriPublic, isReadOnly, HTTP_REDIRECTION_LIMIT);
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions wsd/Storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include <string>
#include <chrono>

/// Limits number of HTTP redirections to prevent from redirection loops
static constexpr auto RedirectionLimit = 21;

class LockContext;

/// Base class of all Storage abstractions.
Expand Down
6 changes: 3 additions & 3 deletions wsd/wopi/WopiProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void WopiProxy::handleRequest([[maybe_unused]] const std::shared_ptr<Terminating
poll->insertNewSocket(moveSocket);

// CheckFileInfo and only when it's good create DocBroker.
checkFileInfo(poll, uriPublic, RedirectionLimit);
checkFileInfo(poll, uriPublic, HTTP_REDIRECTION_LIMIT);
});
break;
#endif //!MOBILEAPP
Expand Down Expand Up @@ -165,7 +165,7 @@ void WopiProxy::checkFileInfo(const std::shared_ptr<TerminatingPoll>& poll, cons
try
{
LOG_INF("WOPI::GetFile using FileUrl: " << fileUrlAnonym);
return download(poll, url, Poco::URI(fileUrl), RedirectionLimit);
return download(poll, url, Poco::URI(fileUrl), HTTP_REDIRECTION_LIMIT);
}
catch (const std::exception& ex)
{
Expand All @@ -186,7 +186,7 @@ void WopiProxy::checkFileInfo(const std::shared_ptr<TerminatingPoll>& poll, cons
try
{
LOG_INF("WOPI::GetFile using default URI: " << uriAnonym);
return download(poll, url, uriObject, RedirectionLimit);
return download(poll, url, uriObject, HTTP_REDIRECTION_LIMIT);
}
catch (const std::exception& ex)
{
Expand Down
7 changes: 4 additions & 3 deletions wsd/wopi/WopiStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ std::string WopiStorage::downloadStorageFileToLocal(const Authorization& auth,
{
LOG_INF("WOPI::GetFile template source: " << templateUriAnonym);
return downloadDocument(Poco::URI(templateUri), templateUriAnonym, auth,
RedirectionLimit);
HTTP_REDIRECTION_LIMIT);
}
catch (const std::exception& ex)
{
Expand All @@ -576,7 +576,8 @@ std::string WopiStorage::downloadStorageFileToLocal(const Authorization& auth,
try
{
LOG_INF("WOPI::GetFile using FileUrl: " << fileUrlAnonym);
return downloadDocument(Poco::URI(_fileUrl), fileUrlAnonym, auth, RedirectionLimit);
return downloadDocument(Poco::URI(_fileUrl), fileUrlAnonym, auth,
HTTP_REDIRECTION_LIMIT);
}
catch (const StorageSpaceLowException&)
{
Expand Down Expand Up @@ -604,7 +605,7 @@ std::string WopiStorage::downloadStorageFileToLocal(const Authorization& auth,
try
{
LOG_INF("WOPI::GetFile using default URI: " << uriAnonym);
return downloadDocument(uriObject, uriAnonym, auth, RedirectionLimit);
return downloadDocument(uriObject, uriAnonym, auth, HTTP_REDIRECTION_LIMIT);
}
catch (const std::exception& ex)
{
Expand Down

0 comments on commit 2f78932

Please sign in to comment.