diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2017-11-26 14:33:38 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2017-11-26 14:33:38 +0300 |
commit | 04a8a5db8160adc970eb706ffddcd6fa34ed4399 (patch) | |
tree | 1669415c6c09f2f49e022f5e189c159ddb3778c0 | |
parent | fba1d65b3e66455da205e4f1951cf2e6f1c84d24 (diff) |
ServerResolver: fix bug where ServerResolver_qt5 would always pass on the original port given to the resolver.
Instead of using the port from the QDnsServiceRecord, the
srvResolved() slot used m_origPort. Oops.
Fixes mumble-voip/mumble#3267
-rw-r--r-- | src/ServerResolver_qt5.cpp | 2 | ||||
-rw-r--r-- | src/tests/TestServerResolver/TestServerResolver.cpp | 48 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/ServerResolver_qt5.cpp b/src/ServerResolver_qt5.cpp index 1f4e7e60d..8be1c0081 100644 --- a/src/ServerResolver_qt5.cpp +++ b/src/ServerResolver_qt5.cpp @@ -98,7 +98,7 @@ void ServerResolverPrivate::hostResolved(QHostInfo hostInfo) { } qint64 priority = normalizeSrvPriority(record.priority(), record.weight()); - m_resolved << ServerResolverRecord(m_origHostname, m_origPort, priority, addresses); + m_resolved << ServerResolverRecord(m_origHostname, record.port(), priority, addresses); } m_srvQueueRemain -= 1; diff --git a/src/tests/TestServerResolver/TestServerResolver.cpp b/src/tests/TestServerResolver/TestServerResolver.cpp index c09fe8b2b..aa5f6a569 100644 --- a/src/tests/TestServerResolver/TestServerResolver.cpp +++ b/src/tests/TestServerResolver/TestServerResolver.cpp @@ -25,6 +25,7 @@ class TestServerResolver : public QObject { Q_OBJECT private slots: void simpleSrv(); + void srvCustomPort(); void simpleA(); void simpleAAAA(); void simpleCNAME(); @@ -77,6 +78,53 @@ void TestServerResolver::simpleSrv() { QVERIFY(hasipv4 || hasipv6); } +void TestServerResolver::srvCustomPort() { +#ifdef USE_NO_SRV + return; +#endif + + ServerResolver r; + QSignalSpy spy(&r, SIGNAL(resolved())); + + QString hostname = QString::fromLatin1("customport.serverresolver.mumble.info"); + quint16 customPort = 36001; + r.resolve(hostname, 64738); + + signalSpyWait(spy); + + QCOMPARE(spy.count(), 1); + + QList<ServerResolverRecord> records = r.records(); + QCOMPARE(records.size(), 1); + + ServerResolverRecord record = records.at(0); + QCOMPARE(record.hostname(), hostname); + QCOMPARE(record.port(), customPort); + // Allow 1 or 2 results. The answer depends on whether + // the system supports IPv4, IPv6, or both. + QVERIFY(record.addresses().size() == 1 || record.addresses().size() == 2); + QCOMPARE(record.priority(), 65545); // priority=1, weight=10 -> 1 * 65535 + 10 + + bool hasipv4 = false; + bool hasipv6 = false; + + HostAddress v4(QHostAddress(QLatin1String("127.0.0.1"))); + HostAddress v6(QHostAddress(QLatin1String("::1"))); + + foreach (HostAddress ha, record.addresses()) { + if (ha == v4) { + hasipv4 = true; + } + if (ha == v6) { + hasipv6 = true; + } + } + + // Require either an IPv4 match, or an IPv6 match. + QVERIFY(hasipv4 || hasipv6); +} + + void TestServerResolver::simpleCNAME() { ServerResolver r; QSignalSpy spy(&r, SIGNAL(resolved())); |