diff options
-rw-r--r-- | src/libsync/propagatedownload.cpp | 2 | ||||
-rw-r--r-- | test/syncenginetestutils.h | 12 | ||||
-rw-r--r-- | test/testdownload.cpp | 28 |
3 files changed, 38 insertions, 4 deletions
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 0601e9fba..eaae1b813 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -589,7 +589,7 @@ void PropagateDownloadFile::slotGetFinished() &propagator()->_anotherSyncNeeded); } - done(status, job->errorString()); + done(status,_item->_httpErrorCode >= 400 ? job->errorStringParsingBody() : job->errorString()); return; } diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 06c35d300..f07f93fda 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -715,8 +715,8 @@ class FakeErrorReply : public QNetworkReply Q_OBJECT public: FakeErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &request, - QObject *parent, int httpErrorCode) - : QNetworkReply{parent}, _httpErrorCode(httpErrorCode) { + QObject *parent, int httpErrorCode, const QByteArray &body = QByteArray()) + : QNetworkReply{parent}, _httpErrorCode(httpErrorCode), _body(body) { setRequest(request); setUrl(request.url()); setOperation(op); @@ -732,9 +732,15 @@ public: } void abort() override { } - qint64 readData(char *, qint64) override { return 0; } + qint64 readData(char *buf, qint64 max) override { + max = qMin<qint64>(max, _body.size()); + memcpy(buf, _body.constData(), max); + _body = _body.mid(max); + return max; + } int _httpErrorCode; + QByteArray _body; }; // A reply that never responds diff --git a/test/testdownload.cpp b/test/testdownload.cpp index 94003c287..4d9098e41 100644 --- a/test/testdownload.cpp +++ b/test/testdownload.cpp @@ -88,6 +88,34 @@ private slots: QCOMPARE(ranges, QByteArray("bytes=" + QByteArray::number(stopAfter) + "-")); QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); } + + void testErrorMessage () { + // This test's main goal is to test that the error string from the server is shown in the UI + + FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; + QSignalSpy completeSpy(&fakeFolder.syncEngine(), SIGNAL(itemCompleted(const SyncFileItemPtr &))); + auto size = 3'500'000; + fakeFolder.remoteModifier().insert("A/broken", size); + + QByteArray serverMessage = "The file was not downloaded because the tests wants so!"; + + // First, download only the first 3 MB of the file + fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { + if (op == QNetworkAccessManager::GetOperation && request.url().path().endsWith("A/broken")) { + return new FakeErrorReply(op, request, this, 400, + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n" + "<s:exception>Sabre\\DAV\\Exception\\Forbidden</s:exception>\n" + "<s:message>"+serverMessage+"</s:message>\n" + "</d:error>"); + } + return nullptr; + }); + + QVERIFY(!fakeFolder.syncOnce()); // Fail because A/broken + QCOMPARE(getItem(completeSpy, "A/broken")->_status, SyncFileItem::NormalError); + QVERIFY(getItem(completeSpy, "A/broken")->_errorString.contains(serverMessage)); + } }; QTEST_GUILESS_MAIN(TestDownload) |