diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-05-03 13:08:15 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-04 02:22:47 +0200 |
commit | 0c8061f608cbc36239e793f8c7baa04c58e40769 (patch) | |
tree | f9f127770c94a5adf677cff8b17015c465002758 /tests | |
parent | 46e6bbd22991dd62040ee1eb24433b5f7316793a (diff) |
QDnsLookup: test MX and SRV records that can change order
The DNS protocol changes the order of the RRs in each reply it sends,
in an effort to balance the load in servers. For most tests, to ensure
that we get always the same result, we simply sort it back.
For MX and SRV, we can't sort because we also need to test that
QDnsLookup sorted correctly according to priority. So instead allow
that test to have multiple alternatives.
Change-Id: I5c119f907b31789de5c9cf2471cc82ecd140d06f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp index 9135c57420..869b082957 100644 --- a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp +++ b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp @@ -61,6 +61,7 @@ class tst_QDnsLookup: public QObject QString domainName(const QString &input); QString domainNameList(const QString &input); + QStringList domainNameListAlternatives(const QString &input); public slots: void initTestCase(); @@ -105,6 +106,14 @@ QString tst_QDnsLookup::domainNameList(const QString &input) return result; } +QStringList tst_QDnsLookup::domainNameListAlternatives(const QString &input) +{ + QStringList alternatives = input.split('|'); + for (int i = 0; i < alternatives.length(); ++i) + alternatives[i] = domainNameList(alternatives[i]); + return alternatives; +} + void tst_QDnsLookup::lookup_data() { QTest::addColumn<int>("type"); @@ -138,6 +147,9 @@ void tst_QDnsLookup::lookup_data() QTest::newRow("mx-single") << int(QDnsLookup::MX) << "mx-single" << int(QDnsLookup::NoError) << "" << "" << "10 multi" << "" << "" << "" << QByteArray(); QTest::newRow("mx-single-cname") << int(QDnsLookup::MX) << "mx-single-cname" << int(QDnsLookup::NoError) << "" << "" << "10 cname" << "" << "" << "" << QByteArray(); QTest::newRow("mx-multi") << int(QDnsLookup::MX) << "mx-multi" << int(QDnsLookup::NoError) << "" << "" << "10 multi;20 a-single" << "" << "" << "" << QByteArray(); + QTest::newRow("mx-multi-sameprio") << int(QDnsLookup::MX) << "mx-multi-sameprio" << int(QDnsLookup::NoError) << "" << "" + << "10 multi;10 a-single|" + "10 a-single;10 multi" << "" << "" << "" << QByteArray(); QTest::newRow("ns-empty") << int(QDnsLookup::NS) << "" << int(QDnsLookup::InvalidRequestError) << "" << "" << "" << "" << "" << "" << QByteArray(); QTest::newRow("ns-notfound") << int(QDnsLookup::NS) << "invalid.invalid" << int(QDnsLookup::NotFoundError) << "" << "" << "" << "" << "" << "" << QByteArray(); @@ -152,6 +164,12 @@ void tst_QDnsLookup::lookup_data() QTest::newRow("srv-notfound") << int(QDnsLookup::SRV) << "invalid.invalid" << int(QDnsLookup::NotFoundError) << "" << "" << "" << "" << "" << "" << QByteArray(); QTest::newRow("srv-single") << int(QDnsLookup::SRV) << "_echo._tcp.srv-single" << int(QDnsLookup::NoError) << "" << "" << "" << "" << "" << "5 0 7 multi" << QByteArray(); QTest::newRow("srv-prio") << int(QDnsLookup::SRV) << "_echo._tcp.srv-prio" << int(QDnsLookup::NoError) << "" << "" << "" << "" << "" << "1 0 7 multi;2 0 7 a-plus-aaaa" << QByteArray(); + QTest::newRow("srv-weighted") << int(QDnsLookup::SRV) << "_echo._tcp.srv-weighted" << int(QDnsLookup::NoError) << "" << "" << "" << "" << "" + << "5 75 7 multi;5 25 7 a-plus-aaaa|" + "5 25 7 a-plus-aaaa;5 75 7 multi" << QByteArray(); + QTest::newRow("srv-multi") << int(QDnsLookup::SRV) << "_echo._tcp.srv-multi" << int(QDnsLookup::NoError) << "" << "" << "" << "" << "" + << "1 50 7 multi;2 50 7 a-single;2 50 7 aaaa-single;3 50 7 a-multi|" + "1 50 7 multi;2 50 7 aaaa-single;2 50 7 a-single;3 50 7 a-multi" << QByteArray(); QTest::newRow("txt-empty") << int(QDnsLookup::TXT) << "" << int(QDnsLookup::InvalidRequestError) << "" << "" << "" << "" << "" << "" << QByteArray(); QTest::newRow("txt-notfound") << int(QDnsLookup::TXT) << "invalid.invalid" << int(QDnsLookup::NotFoundError) << "" << "" << "" << "" << "" << "" << QByteArray(); @@ -174,10 +192,13 @@ void tst_QDnsLookup::lookup() // transform the inputs domain = domainName(domain); cname = domainName(cname); - mx = domainNameList(mx); ns = domainNameList(ns); ptr = domainNameList(ptr); - srv = domainNameList(srv); + + // SRV and MX have reply entries that can change order + // and we can't sort + QStringList mx_alternatives = domainNameListAlternatives(mx); + QStringList srv_alternatives = domainNameListAlternatives(srv); QDnsLookup lookup; lookup.setType(static_cast<QDnsLookup::Type>(type)); @@ -218,7 +239,8 @@ void tst_QDnsLookup::lookup() QCOMPARE(record.name(), domain); mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange()); } - QCOMPARE(mailExchanges.join(';'), mx); + QVERIFY2(mx_alternatives.contains(mailExchanges.join(';')), + qPrintable("Actual: " + mailExchanges.join(';') + "\nExpected one of:\n" + mx_alternatives.join('\n'))); // name servers QStringList nameServers; @@ -250,7 +272,8 @@ void tst_QDnsLookup::lookup() QString::number(record.port()), record.target()); } - QCOMPARE(services.join(';'), srv); + QVERIFY2(srv_alternatives.contains(services.join(';')), + qPrintable("Actual: " + services.join(';') + "\nExpected one of:\n" + srv_alternatives.join('\n'))); // text if (!txt.isEmpty()) { |