зеркало из https://github.com/nextcloud/desktop.git
PropagateDownload: Read Content-md5 header #6088
This commit is contained in:
Родитель
92e90f9c55
Коммит
01c2ffe2ae
|
@ -625,6 +625,9 @@ void PropagateDownloadFile::slotGetFinished()
|
|||
connect(validator, &ValidateChecksumHeader::validationFailed,
|
||||
this, &PropagateDownloadFile::slotChecksumFail);
|
||||
auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
|
||||
auto contentMd5Header = job->reply()->rawHeader(contentMd5HeaderC);
|
||||
if (checksumHeader.isEmpty() && !contentMd5Header.isEmpty())
|
||||
checksumHeader = "MD5:" + contentMd5Header;
|
||||
validator->start(_tmpFile.fileName(), checksumHeader);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace OCC {
|
|||
* It's here for being shared between Upload- and Download Job
|
||||
*/
|
||||
static const char checkSumHeaderC[] = "OC-Checksum";
|
||||
static const char contentMd5HeaderC[] = "Content-MD5";
|
||||
|
||||
/**
|
||||
* @brief Declaration of the other propagation jobs
|
||||
|
|
|
@ -597,6 +597,9 @@ public:
|
|||
size -= len;
|
||||
return len;
|
||||
}
|
||||
|
||||
// useful to be public for testing
|
||||
using QNetworkReply::setRawHeader;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -613,6 +613,60 @@ private slots:
|
|||
QCOMPARE(nDELETE, 5);
|
||||
QCOMPARE(fakeFolder.currentLocalState(), remoteInfo);
|
||||
}
|
||||
|
||||
// Checks whether downloads with bad checksums are accepted
|
||||
void testChecksumValidation()
|
||||
{
|
||||
FakeFolder fakeFolder{ FileInfo::A12_B12_C12_S12() };
|
||||
QObject parent;
|
||||
|
||||
QByteArray checksumValue;
|
||||
QByteArray contentMd5Value;
|
||||
|
||||
fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request) -> QNetworkReply * {
|
||||
if (op == QNetworkAccessManager::GetOperation) {
|
||||
auto reply = new FakeGetReply(fakeFolder.remoteModifier(), op, request, &parent);
|
||||
if (!checksumValue.isNull())
|
||||
reply->setRawHeader("OC-Checksum", checksumValue);
|
||||
if (!contentMd5Value.isNull())
|
||||
reply->setRawHeader("Content-MD5", contentMd5Value);
|
||||
return reply;
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
// Basic case
|
||||
fakeFolder.remoteModifier().create("A/a3", 16, 'A');
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
||||
// Bad OC-Checksum
|
||||
checksumValue = "SHA1:bad";
|
||||
fakeFolder.remoteModifier().create("A/a4", 16, 'A');
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
|
||||
// Good OC-Checksum
|
||||
checksumValue = "SHA1:19b1928d58a2030d08023f3d7054516dbc186f20"; // printf 'A%.0s' {1..16} | sha1sum -
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
checksumValue = QByteArray();
|
||||
|
||||
// Bad Content-MD5
|
||||
contentMd5Value = "bad";
|
||||
fakeFolder.remoteModifier().create("A/a5", 16, 'A');
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
|
||||
// Good Content-MD5
|
||||
contentMd5Value = "d8a73157ce10cd94a91c2079fc9a92c8"; // printf 'A%.0s' {1..16} | md5sum -
|
||||
QVERIFY(fakeFolder.syncOnce());
|
||||
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
|
||||
|
||||
// OC-Checksum has preference
|
||||
checksumValue = "garbage";
|
||||
// contentMd5Value is still good
|
||||
fakeFolder.remoteModifier().create("A/a6", 16, 'A');
|
||||
QVERIFY(!fakeFolder.syncOnce());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(TestSyncEngine)
|
||||
|
|
Загрузка…
Ссылка в новой задаче