--- a/tests/protocol/tst_filehost.cpp +++ b/tests/protocol/tst_filehost.cpp @@ -36,6 +36,31 @@ .trimmed() .toInt(&ok); return ok && raw.size() >= headerEnd + 4 + length; +} + +// Qt 6.11 and earlier wrote header names in lowercase. Qt 6.12 uses the +// canonical spelling, so match the name case-insensitively. +bool wireHasHeader(const QByteArray &raw, const char *name, const QByteArray &value) +{ + const QByteArray expectedName = QByteArray(name).toLower(); + const int headerEnd = raw.indexOf("\r\n\r\n"); + const int limit = headerEnd < 0 ? raw.size() : headerEnd; + int start = 0; + while (start < limit) { + int end = raw.indexOf("\r\n", start); + if (end < 0 || end > limit) + end = limit; + const QByteArray line = raw.mid(start, end - start); + const int colon = line.indexOf(':'); + if (colon > 0 + && line.left(colon).trimmed().toLower() == expectedName + && line.mid(colon + 1).contains(value)) + return true; + if (end >= limit) + break; + start = end + 2; + } + return false; } struct UploadCatcher @@ -182,10 +207,10 @@ QCOMPARE(ready.at(0).at(0).toString(), QStringLiteral("http://127.0.0.1:%1/upload/hoh5eFThae4e.txt") .arg(server.serverPort())); - // Qt writes header names in lowercase. - QVERIFY(caught.captured.contains("authorization: Basic c2V1bmdoeWU6bm8=")); - QVERIFY(caught.captured.contains("content-type: text/plain")); - QVERIFY(caught.captured.contains("content-disposition: attachment; filename=\"note.txt\"")); + QVERIFY(wireHasHeader(caught.captured, "authorization", "Basic c2V1bmdoeWU6bm8=")); + QVERIFY(wireHasHeader(caught.captured, "content-type", "text/plain")); + QVERIFY(wireHasHeader(caught.captured, "content-disposition", + "attachment; filename=\"note.txt\"")); QVERIFY(caught.captured.contains("hello file")); } @@ -214,7 +239,7 @@ QTRY_COMPARE(ready.size(), 1); const QByteArray header = QByteArray::fromStdString( basicAuthorizationValue("alice", "s3cret-token")); - QVERIFY(caught.captured.contains("authorization: " + header)); + QVERIFY(wireHasHeader(caught.captured, "authorization", header)); QVERIFY(!caught.captured.contains("s3cret-token")); }