diff options
author | Christian Kamm <mail@ckamm.de> | 2019-05-07 09:08:24 +0300 |
---|---|---|
committer | Christian Kamm <mail@ckamm.de> | 2019-05-07 11:09:18 +0300 |
commit | 87a6e039a734f0bf17a5e8188ba2f1f82fae6492 (patch) | |
tree | 984a0696d6c2a6a91f98d76c6ae1104f7ac2bfb2 /test | |
parent | f0d306430c4f622fa2aa3d2b318fcbeb275ad487 (diff) |
Chunked upload: Fix percent encoding in If header #7176
Diffstat (limited to 'test')
-rw-r--r-- | test/syncenginetestutils.h | 13 | ||||
-rw-r--r-- | test/testchunkingng.cpp | 16 |
2 files changed, 25 insertions, 4 deletions
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index a515c7e1d..bbf966c5d 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -347,7 +347,7 @@ public: auto writeFileResponse = [&](const FileInfo &fileInfo) { xml.writeStartElement(davUri, QStringLiteral("response")); - xml.writeTextElement(davUri, QStringLiteral("href"), prefix + fileInfo.path()); + xml.writeTextElement(davUri, QStringLiteral("href"), prefix + QUrl::toPercentEncoding(fileInfo.path(), "/")); xml.writeStartElement(davUri, QStringLiteral("propstat")); xml.writeStartElement(davUri, QStringLiteral("prop")); @@ -663,9 +663,14 @@ public: Q_ASSERT(!fileName.isEmpty()); if ((fileInfo = remoteRootFileInfo.find(fileName))) { - QVERIFY(request.hasRawHeader("If")); // The client should put this header - if (request.rawHeader("If") != QByteArray("<" + request.rawHeader("Destination") + - "> ([\"" + fileInfo->etag.toLatin1() + "\"])")) { + // The client should put this header + Q_ASSERT(request.hasRawHeader("If")); + + // And it should condition on the destination file + auto start = QByteArray("<" + request.rawHeader("Destination") + ">"); + Q_ASSERT(request.rawHeader("If").startsWith(start)); + + if (request.rawHeader("If") != start + " ([\"" + fileInfo->etag.toLatin1() + "\"])") { QMetaObject::invokeMethod(this, "respondPreconditionFailed", Qt::QueuedConnection); return; } diff --git a/test/testchunkingng.cpp b/test/testchunkingng.cpp index 3ded3ff6d..2807368fc 100644 --- a/test/testchunkingng.cpp +++ b/test/testchunkingng.cpp @@ -575,6 +575,22 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QCOMPARE(nGET, 0); } + + void testPercentEncoding() { + FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; + fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{ {"chunking", "1.0"} } } }); + const int size = 5 * 1000 * 1000; + setChunkSize(fakeFolder.syncEngine(), 1 * 1000 * 1000); + + fakeFolder.localModifier().insert("A/file % \u20ac", size); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + // Only the second upload contains an "If" header + fakeFolder.localModifier().appendByte("A/file % \u20ac"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestChunkingNG) |