Skip to content

Commit

Permalink
Fix tests to adapt to Qt 6.8's QNAM sending lowercase headers
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaure-kdab committed Aug 21, 2024
1 parent f89999e commit 84fff36
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion testtools/httpserver_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class HttpServerThread : public QThread
QByteArray header(const QByteArray &value) const
{
QMutexLocker lock(&m_mutex);
return m_headers.value(value);
return m_headers.value(value, m_headers.value(value.toLower()));
}

/**
Expand Down
16 changes: 12 additions & 4 deletions unittests/serverlib/test_serverlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,10 +1345,18 @@ private Q_SLOTS:
loop.exec();
reply->readAll();

QVERIFY(reply->rawHeaderList().contains("Access-Control-Allow-Origin"));
QCOMPARE(reply->rawHeader("Access-Control-Allow-Origin").constData(), "*");
QVERIFY(reply->rawHeaderList().contains("Access-Control-Allow-Headers"));
QCOMPARE(reply->rawHeader("Access-Control-Allow-Headers").constData(), "Content-Type");
const bool titleCase = reply->rawHeaderList().contains("Access-Control-Allow-Origin");
const bool lowerCase = reply->rawHeaderList().contains("access-control-allow-origin");
QVERIFY(titleCase || lowerCase);
if (titleCase) {
QCOMPARE(reply->rawHeader("Access-Control-Allow-Origin").constData(), "*");
QVERIFY(reply->rawHeaderList().contains("Access-Control-Allow-Headers"));
QCOMPARE(reply->rawHeader("Access-Control-Allow-Headers").constData(), "Content-Type");
} else { // Qt >= 6.8
QCOMPARE(reply->rawHeader("access-control-allow-origin").constData(), "*");
QVERIFY(reply->rawHeaderList().contains("access-control-allow-headers"));
QCOMPARE(reply->rawHeader("access-control-allow-headers").constData(), "Content-Type");
}
}

void testTimeout()
Expand Down
8 changes: 6 additions & 2 deletions unittests/wsdl_document/test_wsdl_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ private Q_SLOTS:
expectedRequestXml.replace("%1", expectedHeader());
QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml));
QCOMPARE(QString::fromUtf8(server.receivedData().constData()), QString::fromUtf8(expectedRequestXml.constData()));
QVERIFY(server.receivedHeaders().contains("SoapAction: \"http://www.kdab.com/AddEmployee\""));
const QByteArray headers = server.receivedHeaders();
QVERIFY(headers.contains("SoapAction: \"http://www.kdab.com/AddEmployee\"")
|| headers.contains("soapaction: \"http://www.kdab.com/AddEmployee\"")); // Qt >= 6.8
}

// Test utf8
Expand Down Expand Up @@ -393,7 +395,9 @@ private Q_SLOTS:
expectedRequestXml.replace("%1", expectedHeader());
QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml));
QCOMPARE(QString::fromUtf8(server.receivedData().constData()), QString::fromUtf8(expectedRequestXml.constData()));
QVERIFY(server.receivedHeaders().contains("SoapAction: \"http://www.kdab.com/AddEmployee\""));
const QByteArray headers = server.receivedHeaders();
QVERIFY(headers.contains("SoapAction: \"http://www.kdab.com/AddEmployee\"")
|| headers.contains("soapaction: \"http://www.kdab.com/AddEmployee\""));
#endif
}

Expand Down
4 changes: 3 additions & 1 deletion unittests/wsdl_rpc/test_wsdl_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ private Q_SLOTS:
expectedRequestXml.replace("%1", expectedHeader);
QVERIFY(xmlBufferCompare(server.receivedData(), expectedRequestXml));
QCOMPARE(QString::fromUtf8(server.receivedData().constData()), QString::fromUtf8(expectedRequestXml.constData()));
QVERIFY(server.receivedHeaders().contains("SoapAction: \"http://www.kdab.com/AddEmployee\""));
const QByteArray headers = server.receivedHeaders();
QVERIFY(headers.contains("SoapAction: \"http://www.kdab.com/AddEmployee\"")
|| headers.contains("soapaction: \"http://www.kdab.com/AddEmployee\"")); // Qt >= 6.8
}

// Test utf8
Expand Down

0 comments on commit 84fff36

Please sign in to comment.