From fa0a403664df275a5c6e71ebd2fd1a5dd5042dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 31 Mar 2022 18:48:42 +0200 Subject: QNetworkReply: update decompress error message and handling The error message was quite vague since it would then not require any additional translations. However, in hindsight this was a mistake since now developers just thought their downloads were being corrupted. Fixes: QTBUG-101942 Change-Id: Ie9af42510ca027d15248e5bcf21e836e709898d9 Reviewed-by: Timur Pocheptsov (cherry picked from commit d642c16fe745e156a93129fbb3750784b361ee39) Reviewed-by: Qt Cherry-pick Bot --- .../qdecompresshelper/tst_qdecompresshelper.cpp | 7 +++-- .../access/qnetworkreply/tst_qnetworkreply.cpp | 35 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp index 3177cf02c1..27fb8c8ac5 100644 --- a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp +++ b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp @@ -432,10 +432,13 @@ void tst_QDecompressHelper::archiveBomb() QVERIFY(bytesRead <= output.size()); QVERIFY(helper.isValid()); - if (shouldFail) + if (shouldFail) { QCOMPARE(bytesRead, -1); - else + QVERIFY(!helper.errorString().isEmpty()); + } else { QVERIFY(bytesRead > 0); + QVERIFY(helper.errorString().isEmpty()); + } } void tst_QDecompressHelper::bigZlib() diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index ac504fe34a..40a909894d 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -529,6 +529,8 @@ private Q_SLOTS: void cacheWithContentEncoding(); void downloadProgressWithContentEncoding_data(); void downloadProgressWithContentEncoding(); + void contentEncodingError_data(); + void contentEncodingError(); // NOTE: This test must be last! void parentingRepliesToTheApp(); @@ -7102,7 +7104,7 @@ void tst_QNetworkReply::compressedHttpReplyBrokenGzip() QCOMPARE(waitForFinish(reply), int(Failure)); - QCOMPARE(reply->error(), QNetworkReply::ProtocolFailure); + QCOMPARE(reply->error(), QNetworkReply::UnknownContentError); } // TODO add similar test for FTP @@ -9867,6 +9869,37 @@ void tst_QNetworkReply::downloadProgressWithContentEncoding() QCOMPARE(bytesReceived, expected.size()); } +void tst_QNetworkReply::contentEncodingError_data() +{ + QTest::addColumn("encoding"); + QTest::addColumn("path"); + QTest::addColumn("expectedError"); + + QTest::addRow("archive-bomb") << QByteArray("gzip") << (":/4G.gz") + << QNetworkReply::UnknownContentError; +} + +void tst_QNetworkReply::contentEncodingError() +{ + QFETCH(QString, path); + QFile compressedFile(path); + QVERIFY(compressedFile.open(QIODevice::ReadOnly)); + QByteArray body = compressedFile.readAll(); + + QFETCH(QByteArray, encoding); + QString header("HTTP/1.0 200 OK\r\nContent-Encoding: %1\r\nContent-Length: %2\r\n\r\n"); + header = header.arg(encoding, QString::number(body.size())); + + MiniHttpServer server(header.toLatin1() + body); + + QNetworkRequest request( + QUrl(QLatin1String("http://localhost:%1").arg(QString::number(server.serverPort())))); + QNetworkReplyPtr reply(manager.get(request)); + + QTRY_VERIFY2_WITH_TIMEOUT(reply->isFinished(), qPrintable(reply->errorString()), 15000); + QTEST(reply->error(), "expectedError"); +} + // NOTE: This test must be last testcase in tst_qnetworkreply! void tst_QNetworkReply::parentingRepliesToTheApp() { -- cgit v1.2.3