tst_QDnsLookup: don't require "localhost" to resolve

It must for QHostInfo, but DNS servers are not required to have that
label. It appears to be a good practice the majority of admins follow,
but it's not universal, so we cannot require it.

But if it does resolve, then RFC 2606 requires it resolve to 127.0.0.1.

Task-number: QTBUG-129335
Change-Id: Ib3b11de6616665658a20fffd754f2fbd78780b1c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 252bd7c67ce7a0ed3c41059f551f87f0f77b5606)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-09-27 22:31:36 -07:00 committed by Qt Cherry-pick Bot
parent cff3026140
commit ea871ee2e2

View File

@ -388,9 +388,14 @@ QStringList tst_QDnsLookup::formatReply(const QDnsLookup *lookup) const
void tst_QDnsLookup::lookupLocalhost()
{
// The "localhost" label is reserved by RFC 2606 to point to the IPv4
// address 127.0.0.1. However, DNS servers are not required to answer this
// (though it appears to be a good practice).
auto lookup = lookupCommon(QDnsLookup::Type::A, u"localhost."_s);
QVERIFY(lookup);
QCOMPARE(lookup->error(), QDnsLookup::NoError);
QVERIFY(lookup->error() == QDnsLookup::NoError || lookup->error() == QDnsLookup::NotFoundError);
if (lookup->error() == QDnsLookup::NotFoundError)
return;
QList<QDnsHostAddressRecord> hosts = lookup->hostAddressRecords();
QCOMPARE(hosts.size(), 1);