Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assert to ensure we used _remotePath as base #8456

Merged
merged 2 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libsync/abstractnetworkjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ void AbstractNetworkJob::adoptRequest(QNetworkReply *reply)

QUrl AbstractNetworkJob::makeAccountUrl(const QString &relativePath) const
{
// ensure we always used the remote folder
OC_ASSERT(relativePath.startsWith(QLatin1Char('/')));
return Utility::concatUrlPath(_account->url(), relativePath);
}

QUrl AbstractNetworkJob::makeDavUrl(const QString &relativePath) const
{
// ensure we always used the remote folder
OC_ASSERT(relativePath.startsWith(QLatin1Char('/')));
return Utility::concatUrlPath(_account->davUrl(), relativePath);
}

Expand Down
25 changes: 18 additions & 7 deletions test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ QString FileInfo::path() const
return (parentPath.isEmpty() ? QString() : (parentPath + QLatin1Char('/'))) + name;
}

QString FileInfo::absolutePath() const
{
if (parentPath.endsWith(QLatin1Char('/'))) {
return parentPath + name;
} else {
return parentPath + QLatin1Char('/') + name;
}
}

void FileInfo::fixupParentPathRecursively()
{
auto p = path();
Expand Down Expand Up @@ -293,7 +302,7 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces
QMetaObject::invokeMethod(this, "respond404", Qt::QueuedConnection);
return;
}
QString prefix = request.url().path().left(request.url().path().size() - fileName.size());
const QString prefix = request.url().path().left(request.url().path().size() - fileName.size());

// Don't care about the request and just return a full propfind
const QString davUri { QStringLiteral("DAV:") };
Expand All @@ -307,8 +316,8 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces
xml.writeStartElement(davUri, QStringLiteral("multistatus"));
auto writeFileResponse = [&](const FileInfo &fileInfo) {
xml.writeStartElement(davUri, QStringLiteral("response"));

xml.writeTextElement(davUri, QStringLiteral("href"), prefix + QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.path(), "/")));
const auto href = OCC::Utility::concatUrlPath(prefix, QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.absolutePath(), "/"))).path();
xml.writeTextElement(davUri, QStringLiteral("href"), href);
xml.writeStartElement(davUri, QStringLiteral("propstat"));
xml.writeStartElement(davUri, QStringLiteral("prop"));

Expand Down Expand Up @@ -504,9 +513,11 @@ FakeGetReply::FakeGetReply(FileInfo &remoteRootFileInfo, QNetworkAccessManager::
QString fileName = getFilePathFromUrl(request.url());
Q_ASSERT(!fileName.isEmpty());
fileInfo = remoteRootFileInfo.find(fileName);
if (!fileInfo)
qWarning() << "Could not find file" << fileName << "on the remote";
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
if (!fileInfo) {
qDebug() << "meh;";
}
Q_ASSERT_X(fileInfo, Q_FUNC_INFO, "Could not find file on the remote");
QMetaObject::invokeMethod(this, &FakeGetReply::respond, Qt::QueuedConnection);
}

void FakeGetReply::respond()
Expand Down Expand Up @@ -760,7 +771,7 @@ FakeErrorReply::FakeErrorReply(QNetworkAccessManager::Operation op, const QNetwo
open(QIODevice::ReadOnly);
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, httpErrorCode);
setError(InternalServerError, QStringLiteral("Internal Server Fake Error"));
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, &FakeErrorReply::respond, Qt::QueuedConnection);
}

void FakeErrorReply::respond()
Expand Down
1 change: 1 addition & 0 deletions test/syncenginetestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class FileInfo : public FileModifier
}

QString path() const;
QString absolutePath() const;

void fixupParentPathRecursively();

Expand Down
2 changes: 1 addition & 1 deletion test/testjobqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestJob : public AbstractNetworkJob
// AbstractNetworkJob interface
public:
TestJob(AccountPtr account)
: AbstractNetworkJob(account, QStringLiteral("A/a1"))
: AbstractNetworkJob(account, QStringLiteral("/A/a1"))
{
}

Expand Down