Commit Graph

293 Commits (bb10)

Author SHA1 Message Date
Thiago Macieira 4374f3ce41 tst_QDnsLookup: don't add duplicate 'nameserver' lines
I don't know why systemd-resolved did have those for me, but it did, so
QtTest complains.

QWARN  : tst_QDnsLookup::setNameserver() Duplicate data tag "..." - please rename.

Change-Id: I8df70eb429682b529ecefffd0aca735f94d77225
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 1420ee85165c03bac2aa1678b295f7b1ebe44f51)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-10-03 03:43:03 +00:00
Thiago Macieira c2df419edf tst_QDnsLookup: add the ability to specify an alternate default server
For people running this test who are burdened with a broken DNS server
and for whom the check added in the previous commit fails, skipping the
test.

Incidentally, this is useful for developing QDnsLookup itself, because
some otherwise-reasonable servers are known to fail for some queries.
For example, dnsmasq doesn't like queries of type ANY:

SKIP   : tst_QDnsLookup::lookup(any-a-single) Server refused or was unable to answer query; a-single type ANY: Server failure
SKIP   : tst_QDnsLookup::lookup(any-a-plus-aaaa) Server refused or was unable to answer query; a-plus-aaaa type ANY: Server failure
SKIP   : tst_QDnsLookup::lookup(any-multi) Server refused or was unable to answer query; multi type ANY: Server failure

Now I can get it to pass with QTEST_DNS_SERVER='[2001:4860:4860::8888]':

PASS   : tst_QDnsLookup::lookup(any-a-single)
PASS   : tst_QDnsLookup::lookup(any-a-plus-aaaa)
PASS   : tst_QDnsLookup::lookup(any-multi)

Note for the future: setting a non-default server may exercise different
code paths inside QDnsLookup, so this is not a replacement for having
proper DNS servers in the CI.

Fixes: QTBUG-129335
Change-Id: I81dcd4834972efa84c9ffffdd8aaafb68f20560b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 10fea78bdcad2086c980fa1c1bbcd5bb543e4366)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-10-03 03:43:01 +00:00
Thiago Macieira 5ce4677f2e tst_QDnsLookup: check for DNS server sanity
Instead of failing tst_QDnsLookup and blaming the class for problems,
let's first verify that the resolver can resolve an address. If it can't
and we're not in the CI, then just skip the test.

I chose "a-multi" because a) it required the least variability in the
command-line and b) it has more than one RR in the RR set so it may find
more problems than "a-single".

Output when I forced a domain that doesn't exist:

QWARN  : tst_QDnsLookup::initTestCase() Default DNS server in this
system cannot correctly resolve "a-multix.test.qt-project.org"
QWARN  : tst_QDnsLookup::initTestCase() Please check if you are
connected to the Internet.
QDEBUG : tst_QDnsLookup::initTestCase() Output was:
Server:		127.0.0.53
Address:	127.0.0.53#53

** server can't find a-multix.test.qt-project.org: NXDOMAIN

SKIP   : tst_QDnsLookup::initTestCase() DNS server does not appear to
work

Task-number: QTBUG-129335
Change-Id: Id2dcc2ce7cfdd83c556ffffddb88a1f1b4339606
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 40986460e3f372cdb42ad80377455dc43b7cdb42)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-10-03 03:43:00 +00:00
Thiago Macieira ea871ee2e2 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>
2024-10-03 03:42:59 +00:00
Tor Arne Vestbø fb69c5a354 tst_QDnsLookup::lookupReuse(): Rewrite using lookupCommon helper
Task-number: QTBUG-129335
Change-Id: I8417ff9e76076d0b1a40270edc1b2692a122657f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 41768db300b70dda36344ab1cafb6b99937da435)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-10-02 12:43:37 +00:00
Timur Pocheptsov 3ba0bb61ad tst_QHostInfo: re-enable back the test on macOS
It went unnoticed (by me) the test was disabled via *.pro and later CMakeLists.txt
rather than BLACKLIST I was checking back then.

Fixes: QTBUG-129349
Change-Id: I509485bac9f32d544ef4bec120590a00d85ed608
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit e498a076ae035588ed6f29e91a20eb727d608342)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-09-26 18:10:35 +00:00
Assam Boudjelthia f1c6c66985 Android: prefer wlan IPv6 connection over other interfaces
Android doesn't allow connection from interfaces like (radio0, eth0,
etc.) when wlan0 is already connected, so prefer testing that.

Task-number: QTBUG-125023
Change-Id: Id48a6717755edc22909a4a0d58631d8132a42b1a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-05-23 10:26:20 +03:00
Thiago Macieira a6d26ef64b tst_QDnsLookup: add debugging information with the query time
Change-Id: I455fe22ef4ad4b2f9b01fffd17c805aa76d2b314
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:49 -07:00
Thiago Macieira 4503dabfbd QDnsLookup: add support for TLSA records
[ChangeLog][QtNetwork][QDnsLookup] Added support for querying records of
type TLSA, which are useful in DNS-based Authentication of Named
Entities (DANE).

Change-Id: I455fe22ef4ad4b2f9b01fffd17c723aa6ab7f278
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:47 -07:00
Thiago Macieira f2f00b2a46 QDnsLookup: implement DNS-over-TLS
For the libresolv (Unix) implementation, we already had the packet
prepared by res_nmkquery(). This commit moves the res_nsend() to a
separate function so QDnsLookupRunnable::query() can be more concise.

On the Windows side, this commit creates a separate function for the DoT
case, because we now need to use two other functions from WinDNS so we
can create a query and parse the reply.

The rest is just QSslSocket.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c805a3cb0466eb
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-09 04:13:44 +00:00
Thiago Macieira 9724b039ca QDnsLookup: add initial support for DNS-over-TLS (DoT)
This is just an empty shell for now. The implementation will come in the
next commit.

[ChangeLog][QtNetwork][QDnsLookup] The class now supports DNS-over-TLS
and some other DNSSEC experimental features, on some platforms. Use
QDnsLookup::isProtocolSupported to know if the protocol is supported on
a given platform.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c7e034dee75533
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-05-08 21:13:43 -07:00
Jari Helaakoski 30cc8a28de Fix test compilation issues with QtLite configuration
Now developer build tests compile, but some are not working.
Functional fix will come later via separate tasks.

Task-number: QTBUG-122999
Change-Id: I70487b46c1b32ba4279cb02a4978e4f55ac0d310
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-05-06 14:29:02 +00:00
Thiago Macieira f110bd2663 tst_QDnsLookup: add testing of PTR records on global names
The DNS servers from Google and CloudFare are probably stable enough
over the long-term.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c748dc1233bc1b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 6800e168d5 tst_QDnsLookup: also use the nameservers behind systemd-resolved
If the file exists, we are using systemd-resolved, so let's try directly
using the nameservers it uses.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c7476a2385bf4b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira f7d293d3da tst_QDnsLookup refactor: use the new helpers in other test functions
Change-Id: I455fe22ef4ad4b2f9b01fffd17c7414e111cb8ed
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 4b8bdab27d tst_QDnsLookup refactor: rewrite lookup() function
This is a major simplification to use only one column in the QtTest
tables for the results, which makes it far easier to read the code as
well as to add more record types.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c745d13c9c4037
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 121a081d20 tst_QDnsLookup refactor: split the NXDOMAIN tests from lookup()
This will allow making lookup() require positive results only.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c740e36002d25e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:30 -07:00
Thiago Macieira 41675df695 tst_QDnsLookup: use the 4-argument writeDatagram() overload
When using writeDatagram(QNetworkDatagram), the sendmsg() call on
FreeBSD is failing. It works on Linux and on macOS, so my guess is that
IP_PKTINFO works to set the sender address but IP_SENDSRCADDR is not
allowed in this context for some reason.

Before:
 recvmsg(5,{{ AF_INET 127.0.0.1:19530 },16,[{"H\M-p\^A\0\0\^A\0\0\0\0\0\^A\tso"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}},{level=IPPROTO_IP,type=IP_RECVTTL,data={0x40}}},48,0},0) = 49 (0x31)
 sendmsg(5,{{ AF_INET 127.0.0.1:19530 },16,[{"H\M-p\M^@\^C\0\^A\0\0\0\0\0\^A\t"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}}},24,0},MSG_NOSIGNAL) ERR#22 'Invalid argument'

After:
 recvmsg(5,{{ AF_INET 127.0.0.1:16018 },16,[{"\^U\M-X\^A\0\0\^A\0\0\0\0\0\^A\t"...,49}],1,{{level=IPPROTO_IP,type=IP_RECVDSTADDR,data={0x7f,0x00,0x00,0x01}},{level=IPPROTO_IP,type=IP_RECVTTL,data={0x40}}},48,0},0) = 49 (0x31)
 sendmsg(5,{{ AF_INET 127.0.0.1:16018 },16,[{"\^U\M-X\M^@\^C\0\^A\0\0\0\0\0\^A"...,49}],1,{},0,0},MSG_NOSIGNAL) = 49 (0x31)

Pick-to: 6.7
Change-Id: I455fe22ef4ad4b2f9b01fffd17c77565e230ce31
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:29 -07:00
Thiago Macieira 2dfb7f3337 tst_QDnsLookup: fix MSVC 'truncation of constant value' warning
0x80 is too big for a signed char (range is -0x80 to 0x7f).

Pick-to: 6.7
Change-Id: I455fe22ef4ad4b2f9b01fffd17c7746f4ea3c536
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-22 21:36:29 -07:00
Thiago Macieira d18d8a7ad1 tst_QHostInfo: increase the timeout to 15s
That seems to be enough for me when trying to reverse-resolve host names
inside the corporate network.

Pick-to: 6.7
Change-Id: I6818d78a57394e37857bfffd17bc6b0ebd39f51b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-13 18:29:12 -07:00
Thiago Macieira 78cf5740a9 tst_QHostInfo: don't use the test class to store results
Because QHostInfo is threaded, so if the look up times out and we exit a
given test, the results may still be delivered to the next test.
Especially if the next test is also about to time out -- in which case
it doesn't and prints a nonsensical output.

Before:

FAIL!  : tst_QHostInfo::lookupIPv4(WithCache:literal_ip4) '!QTestEventLoop::instance().timeout()' returned FALSE. ()
   Loc: [tst_qhostinfo.cpp(220)]
FAIL!  : tst_QHostInfo::lookupIPv6(WithCache:aaaa-single) Compared values are not the same
   Actual   (tmp.join(' ').toLower())     : "192.0.2.1"
   Expected (expected.join(' ').toLower()): "2001:db8::1"
   Loc: [tst_qhostinfo.cpp(281)]

Now:

FAIL!  : tst_QHostInfo::lookupIPv4(WithCache:literal_ip4) 'helper.waitForResults()' returned FALSE. ()
   Loc: [tst_qhostinfo.cpp(278)]
PASS   : tst_QHostInfo::lookupIPv6(WithCache:aaaa-single)

Pick-to: 6.7
Change-Id: I6818d78a57394e37857bfffd17bc66e241cab24d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-14 01:29:12 +00:00
Lucie Gérard ff1039c217 Change license for tests files
According to QUIP-18 [1], all tests file should be
LicenseRef-Qt-Commercial OR GPL-3.0-only

[1]: https://contribute.qt-project.org/quips/18

Pick-to: 6.7
Task-number: QTBUG-121787
Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2024-02-04 09:56:42 +01:00
Thiago Macieira 4d7b64cd2f tst_QHostInfo: enable the IPv6 reverse lookups in more systems
I've noticed that on some Windows systems, the resolver refuses to
resolve IPv6-only addresses. But it can still do reverse resolution from
IPv6.

Change-Id: I5dd50a1a7ca5424d9e7afffd17adfe739ded932e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-30 13:28:19 -08:00
Thiago Macieira 7b981a4f1a tst_QHostInfo: remove QProcess dependency
Our ideal scenario was to run python to run its getnameinfo()... so just
use getnameinfo() directly. This also avoids the problem of Python not
being present and our falling back to nslookup.

Pick-to: 6.7
Change-Id: I5dd50a1a7ca5424d9e7afffd17adfc830386306f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-30 13:28:19 -08:00
Thiago Macieira 133c918650 tst_QHostInfo: reorganize the #includes
Pick-to: 6.7
Change-Id: I5dd50a1a7ca5424d9e7afffd17adfb5d0bb9a54c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-01-30 13:28:19 -08:00
Tomasz Kozłowski 09a21c73a0 Add required network libs for VxWorks
It is needed for proper inet socket address working
on this platform.

Pick-to: 6.7
Task-number: QTBUG-115777
Change-Id: Icde7ff7baf257762339f5f72a783c92f6b297a46
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-01-26 18:48:38 +00:00
Lena Biliaieva 15b0bd69ff Network: Use QHttpHeaders in QHttpHeaderParser
QHttpHeaderParser::headers() method is changed to return QHttpHeaders.
QAuthenticatorPrivate::parseHttpResponse() method is changed to work with QHttpHeaders.
QHttpNetworkHeader::header() method is updated to return QHttpHeaders.
Tests are updated.

Task-number: QTBUG-120133
Change-Id: I20a18b509acd7a8b8d93884cff8349519d64293e
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
2024-01-25 00:48:10 +00:00
Axel Spoerl 3c5e37fe0f tst_QHostInfo::reverseLookup(): code cleanup
Remove redundant curly braces.
Use constFirst() instead of first() on a temporary list object.

Task-number: QTBUG-120460
Pick-to: 6.7 6.6 6.5
Change-Id: Id643b20dfa5a541fea56abfdbcf933245a8a3c9d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-01-11 10:59:03 +01:00
Ahmad Samir 0ce51dee0e tst_QDnsLookup: fix typo in CMakeListst.txt
There was an extra `q` before dnslookup.

Found while trying to build tst_qdnslookup, the target wasn't seen by
CMake/Ninja.

Pick-to: 6.6
Change-Id: Id594aab30dc9081fc269541561e0f2db5e615657
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-09-04 14:17:12 -07:00
Ahmad Samir 9b40272562 tst_QDnsLookup: skip a unittest on Windows
See code review 496440 on Gerrit for the details.

Change-Id: Ibd32a44cf7e2e07f36687cc2f0eeaf3008f64e73
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-09-04 22:40:35 +03:00
Ivan Solovev 96a62cd1f5 tst_QDnsLookup: extend test coverage for property bindings
The pre-existing tests were not using the QTestPrivate helpers, so
extend them with the call to QTestPrivate::testReadWritePropertyBasics.

The updated test didn't reveal any problems with binding loops, so no
other action is required for now.

Task-number: QTBUG-116346
Pick-to: 6.6 6.5
Change-Id: I51a17974a7f5bec3c969fcb55b6f28e3e9218eb5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-03 18:20:56 +02:00
Thiago Macieira 2e51fbf89a tst_QNetworkInterface: enable IPv6 detection for Windows
This was disabled in d0d1d74033, I guess
accidentally, by a too-wide conditional. The change the same commit
applied to QtNetworkSettings didn't make the same mistake.

I am also opportunistically updating the conditional to QT_CONFIG (I
missed this in 9d4579c1cd) and adding the
Linux-specific check, as the AF_NETLINK implementation does not rely on
getifaddrs() or if_nametoindex().

Drive-by fix indentation.

Pick-to: 6.6
Change-Id: Ifa1111900d6945ea8e05fffd177ef8fcb11b4e1e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-08-29 07:20:49 -07:00
Thiago Macieira 19673b6cf9 tst_qdnslookup: fix the location of the opcode in the header
We were reading the wrong byte with the wrong shift count.

 4.1.1. Header section format

 The header contains the following fields:

                                    1  1  1  1  1  1
      0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                      ID                       |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |QR|   Opcode  |AA|TC|RD|RA|   Z    |   RCODE   |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    QDCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ANCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    NSCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |                    ARCOUNT                    |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

This diagram is big-endian, so bit 0 is the MSB.

Change-Id: I964c2b1e6b834feb9710fffd177bb72110bb77e7
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-28 20:09:41 -07:00
Ahmad Samir 40f863738b QtNetwork auto tests: compile with QT_NO_FOREACH
Remove all "#undef QT_NO_FOREACH" white-listing from source files.
Previous commits have removed all remaining Q_FOREACH/foreach uses in
this sub-tree.

Also remove one source file from NO_PCH_SOURCES in CMakeLists.txt.

Task-number: QTBUG-115839
Change-Id: I02cf994eda720c028e613407342fbd6658fa62b1
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-08-22 21:50:38 +03:00
Ahmad Samir dccaedc626 QtNetwork auto tests: port Q_FOREACH to ranged-for [4]
Straightforward ports where the container could be made const.

Use C arrays instead of QList if the data is known at compile time.

Drive-by, where appropriate make the for-loop variable a const& (e.g.
QString) instead of copying it for no reason.

Task-number: QTBUG-115839
Change-Id: I273a386e414e5923e750072f0407226efcd4531e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-08-22 21:48:20 +03:00
Ahmad Samir 1a98293200 QtNetwork auto tests: port Q_FOREACH to ranged-for [1]
The loops were iterating over a temporary, so use a local const auto
variable to hold it, and use ranged-for.

Drive-by, make the for-loop variable const& instead of copying it,
for any object that has a d-pointer (QNetworkAddressEntry, QHostAddress,
QNetworkInterface).

Task-number: QTBUG-115839
Change-Id: If96c0b2a6142fe2fa2ed45ed7e2435cc1f80e005
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-08-22 21:47:16 +03:00
Marc Mutz 11d6932560 Mark all of Qt as free of Q_FOREACH, except where it isn't
The density of Q_FOREACH uses in this and some other modules is still
extremely high, too high for anyone to tackle in a short amount of
time. Even if they're not concentrated in just a few TUs, we need to
make progress on a global QT_NO_FOREACH default, so grab the nettle
and stick to our strategy:

Mark the whole of Qt with QT_NO_FOREACH, to prevent new uses from
creeping in, and whitelist the affected TUs by #undef'ing
QT_NO_FOREACH locally, at the top of each file. For TUs that are part
of a larger executable, this requires these files to be compiled
separately, so add them to NO_PCH_SOURCES (which implies
NO_UNITY_BUILD_SOURCES, too).

In tst_qglobal.cpp and tst_qcollections.cpp change the comment on the
#undef QT_NO_FOREACH to indicate that these actually test the macro.

Task-number: QTBUG-115839
Change-Id: Iecc444eb7d43d7e4d037f6e155abe0e14a00a5d6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-08-19 05:19:42 +00:00
Marc Mutz f2f8820073 tests: port assorted trivial uses of Q_FOREACH to ranged for loops
All of these fall into the trivial category: loops over (readily made)
const local containers. As such, they cannot possibly depend on the
safety copy that Q_FOREACH performs, so are safe to port as-is to
ranged for loops.

There may be more where these came from, but these were the ones that
stood out as immediately obvious when scanning the 100s of uses in
qtbase, so I preferred to directly fix them over white-listing their
files with QT_NO_FOREACH (which still may be necessary for some files,
as this patch may not port all uses in that file).

Pick-to: 6.6 6.5
Task-nubmber: QTBUG-115839
Change-Id: I7b7893bec8254f902660dac24167113aca855029
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-08-14 23:11:54 +03:00
Marc Mutz 69d767bec2 tst_QHostInfo: fix mem-leaks in threadSafetyAsynchronousAPI()
Allocate participating threads and objects on the stack, not the heap.

As a drive-by, port from QList to C arrays (never use a
dynamically-sized container for statically-sized data™).

Code predates the public history, all active branches are affected.

Pick-to: 6.6 6.5 6.2 5.15
Change-Id: If8def658c1c7b505074938d637e78ad2d1f9fd57
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-07-19 04:52:28 +00:00
Alexandru Croitor 463d232457 CMake: Make network tests standalone projects
Add the boilerplate standalone test prelude to each test, so that they
can be opened with an IDE without the qt-cmake-standalone-test script,
but directly with qt-cmake or cmake.

Boilerplate was added using the following scripts:
https://git.qt.io/alcroito/cmake_refactor

Manual adjustments were made where the code was inserted in the wrong
location.

Task-number: QTBUG-93020
Change-Id: I000cd3b0809b6417c3b1ab520e4de746afee71fc
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2023-07-05 15:09:32 +02:00
Amir Masoud Abdol 1dfa922606 Remove the manual undef of the min/max macros, or def NOMINMAX
We now add NOMINMAX to PlatformCommonInternal target which will be
linked to everything else, so min/max will not be defined upon the
inclusion of `windows.h`, or other headers.

Pick-to: 6.5 6.6
Change-Id: I10016720dac7ce015e929885b7368ee86d8b6918
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-06-08 01:18:04 +02:00
Thiago Macieira 8b6bd8ed99 QDnsLookup: allow looking up the root domain
[ChangeLog][QtNetwork][QDnsLookup] It is now possible to look up the
root DNS domain, by setting the name property to an empty string. This
query is usually done while setting the query type to NS.

Change-Id: I5f7f427ded124479baa6fffd175f688395941610
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-06-03 19:28:13 -07:00
Thiago Macieira 26dd7fe4ed CMake: remove "res_ninit" feature and collapse to just "libresolv"
Testing for "res_ninit" when WrapResolv.cmake has already checked for
far more complex functions was pointless. Instead, just accept the
library that was found by find_package() as good enough and rename the
feature as "libresolv".

Amends 4a46ba1209 and
68b625901f.

Change-Id: Ib5ce7a497e034ebabb2cfffd1762c0afa2fac6e0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-27 12:57:16 -07:00
Thiago Macieira 432d67b43f QDnsLookup: add TimeoutError for timeouts
We were getting InvalidReplyError because it was simply unknown, which
is not very useful. Previously, the Unix code used res_nquery(), which
does not return timeouts as a condition. It returns -1 if a timeout did
happen, but the content in errno could be a left-over from a previous
timeout (see the "Not a typewriter"[1] problem).

With the rewrite to using res_nmkquery() and res_nsend() from the
previous commits, we can rely on errno being set properly by
res_nsend().

$ $objdir/tests/manual/qdnslookup/qdnslookup @0.0.0.1
; <<>> QDnsLookup 6.6.0 <<>> qdnslookup @0.0.0.1
;; status: TimeoutError (Request timed out)
;; QUESTION:
;qt-project.org                 IN A

;; Query time: 10008 ms
;; SERVER: 0.0.0.1#53

Tested on FreeBSD, Linux, macOS, and Windows.

[1] https://en.wikipedia.org/wiki/Not_a_typewriter

Change-Id: I3e3bfef633af4130a03afffd175e31958247f9b1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-26 06:46:33 -07:00
Thiago Macieira 282b078fca tst_QDnsLookup: add a test for setNameserver
I had to write a sample query test to ensure that those servers can be
reached. They can't from the my corporate network, for example:

QDEBUG : tst_QDnsLookup::setNameserver(normal) QHostAddress("8.8.8.8") discarded: "Network operation timed out"
QDEBUG : tst_QDnsLookup::setNameserver(normal) QHostAddress("2001:4860:4860::8888") discarded: "Network unreachable"
QDEBUG : tst_QDnsLookup::setNameserver(normal) QHostAddress("1.1.1.1") discarded: "Connection refused"
QDEBUG : tst_QDnsLookup::setNameserver(normal) QHostAddress("2606:4700:4700::1111") discarded: "Network unreachable"

This will also take care of ignoring the IPv6 servers on systems without
it (as above).

Change-Id: I3e3bfef633af4130a03afffd175de18af24add70
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-23 21:23:43 -07:00
Thiago Macieira bce7009f55 QDnsLookup: add support for setting the port number of the server
I couldn't make my Windows 10 or 11 query a non-standard port. It kept
complaining about "The parameter is incorrect.", so as a result the unit
test doesn't actually test the new feature there. I can't find a single
example of this on the Internet; my speculation is that the backend API
that DnsQueryEx uses does not support setting port numbers
(DnsQuery_{A,W} didn't offer that option).

[ChangeLog][QtNetwork][QDnsLookup] Added setNameserverPort().

Change-Id: I3e3bfef633af4130a03afffd175d60a581cc0a9c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-23 21:23:42 -07:00
Thiago Macieira af9fa21a70 tst_QDnsLookup: don't fail if the server refused to answer
This happens often for me for ANY queries via Dnsmasq (home router) or
via whatever the corporate DNS servers are in the office.

Pick-to: 6.5
Change-Id: I3e3bfef633af4130a03afffd175e2656ae5e2c3e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-11 17:05:26 -07:00
Thiago Macieira 9f7b341aae tst_QDnsLookup: create a dedicated test for IDN
Instead of using initTestCase and QFETCH_GLOBAL, which make the rest of
the tests repeat themselves with IDN data, which isn't necessary.

Pick-to: 6.5
Change-Id: I3e3bfef633af4130a03afffd175e2537ba89dc04
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-11 17:05:25 -07:00
Amir Masoud Abdol 68b625901f Network: link directly to libresolv instead of dlopen()ing it
There's little need for us to dynamically load it. The reasons why that
was necessary aren't in the public history (Qt 4.5 already had it[1]). I
remember writing the code in 2007-2008, I just don't remember why.

On modern Linux and FreeBSD, there's no libresolv.so any more and those
symbols have been rolled up into libc.so. It's still necessary on Darwin
systems, so this commit introduces WrapResolv.

It also resolves the unity build issues relating to libresolv symbols.

[1] https://code.qt.io/cgit/qt/qt.git/tree/src/network/kernel/qhostinfo_unix.cpp?h=v4.5.1

Task-number: QTBUG-109394
Change-Id: Ic5799e4d000b6c9395109e008780643bac52122b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-05-11 17:05:25 -07:00
Mårten Nordheim 36e59db1bb Unblacklist tst_QDnsQuery::lookup
It was blacklisted some years ago, the bug was closed as
cannot reproduce, and no one unblacklisted it.

Pick-to: 6.5 6.2
Change-Id: I51f1fe4d819e0f90bf18c19b67fa0dca198914d4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-05-10 17:16:25 +02:00