diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-03-09 15:01:04 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-09 16:15:35 (GMT) |
commit | 810e844984e4dd757156a9069ce9db4a1dc3ae5d (patch) | |
tree | 1a5c580573b7fb403399ab064520876d3ba42edf /tests | |
parent | fd60a3796ec4d4976965c81b7e14a538343050c4 (diff) | |
download | Qt-810e844984e4dd757156a9069ce9db4a1dc3ae5d.zip Qt-810e844984e4dd757156a9069ce9db4a1dc3ae5d.tar.gz Qt-810e844984e4dd757156a9069ce9db4a1dc3ae5d.tar.bz2 |
Rework QNetworkProxyFactory::systemProxyForQuery autotest
Rather than requiring specific hardcoded proxies in the system,
it now checks the proxies returned by the system have the required
capabilities for the request.
Note the test will pass if no proxy is configured (as
QNetworkProxy::NoProxy has all required capabilities)
The test prints the returned proxy lists and elapsed time
diagnostic for manual comparison and debugging.
Change-Id: I621ef4d1d7264a98c3e8bd485c30bc1166fcbdf0
Task-number: QTBUG-19454
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 3c529933612ff022d139975d661e37c77b1b2e99)
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp | 141 |
1 files changed, 120 insertions, 21 deletions
diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index e2052b0..490f5df 100644 --- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -79,6 +79,7 @@ public: private slots: void systemProxyForQueryCalledFromThread(); + void systemProxyForQuery_data(); void systemProxyForQuery() const; #ifndef QT_NO_BEARERMANAGEMENT void fromConfigurations(); @@ -108,34 +109,132 @@ QString tst_QNetworkProxyFactory::formatProxyName(const QNetworkProxy & proxy) c return proxyName; } -void tst_QNetworkProxyFactory::systemProxyForQuery() const +void tst_QNetworkProxyFactory::systemProxyForQuery_data() { - QNetworkProxyQuery query(QUrl(QString("http://www.abc.com")), QNetworkProxyQuery::UrlRequest); - QList<QNetworkProxy> systemProxyList = QNetworkProxyFactory::systemProxyForQuery(query); - bool pass = true; - QNetworkProxy proxy; + QTest::addColumn<int>("type"); + QTest::addColumn<QUrl>("url"); + QTest::addColumn<QString>("tag"); + QTest::addColumn<QString>("hostName"); + QTest::addColumn<int>("port"); + QTest::addColumn<int>("requiredCapabilities"); + + //URLs + QTest::newRow("http") << (int)QNetworkProxyQuery::UrlRequest << QUrl("http://qt-project.org") << QString() << QString() << 0 << 0; + //windows: "intranet" should be bypassed if "bypass proxy server for local addresses" is ticked + QTest::newRow("intranet") << (int)QNetworkProxyQuery::UrlRequest << QUrl("http://qt-test-server") << QString() << QString() << 0 << 0; + //windows: "intranet2" should be bypassed if "*.local" is in the exceptions list (advanced settings) + QTest::newRow("intranet2") << (int)QNetworkProxyQuery::UrlRequest << QUrl("http://qt-test-server.local") << QString() << QString() << 0 << 0; + QTest::newRow("https") << (int)QNetworkProxyQuery::UrlRequest << QUrl("https://qt-project.org") << QString() << QString() << 0 << (int)QNetworkProxy::TunnelingCapability; + QTest::newRow("ftp") << (int)QNetworkProxyQuery::UrlRequest << QUrl("ftp://qt-project.org") << QString() << QString() << 0 << 0; + + //TCP + QTest::newRow("imap") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString() << QString("qt-project.org") << 0 << (int)QNetworkProxy::TunnelingCapability; + QTest::newRow("autobind-server") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString() << QString() << 0 << (int)QNetworkProxy::ListeningCapability; + QTest::newRow("web-server") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString() << QString() << 80 << (int)QNetworkProxy::ListeningCapability; + + //UDP + QTest::newRow("udp") << (int)QNetworkProxyQuery::UdpSocket << QUrl() << QString() << QString() << 0 << (int)QNetworkProxy::UdpTunnelingCapability; + + //Protocol tags + QTest::newRow("http-tag") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString("http") << QString("qt-project.org") << 80 << (int)QNetworkProxy::TunnelingCapability; + QTest::newRow("ftp-tag") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString("ftp") << QString("qt-project.org") << 21 << (int)QNetworkProxy::TunnelingCapability; + QTest::newRow("https-tag") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString("https") << QString("qt-project.org") << 443 << (int)QNetworkProxy::TunnelingCapability; +#ifdef Q_OS_WIN + //in Qt 4.8, "socks" would get the socks proxy, but we dont want to enforce that for all platforms + QTest::newRow("socks-tag") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString("socks") << QString("qt-project.org") << 21 << (int)(QNetworkProxy::TunnelingCapability | QNetworkProxy::ListeningCapability); +#endif + //windows: ssh is not a tag provided by the os, but any tunneling proxy is acceptable + QTest::newRow("ssh-tag") << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString("ssh") << QString("qt-project.org") << 22 << (int)QNetworkProxy::TunnelingCapability; - QList<QNetworkProxy> nativeProxyList; - nativeProxyList << QNetworkProxy(QNetworkProxy::HttpProxy, QString("test.proxy.com"), 8080) << QNetworkProxy::NoProxy; + //Server protocol tags (ftp/http proxies are no good, we need socks or nothing) + QTest::newRow("http-server-tag") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString("http") << QString() << 80 << (int)QNetworkProxy::ListeningCapability; + QTest::newRow("ftp-server-tag") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString("ftp") << QString() << 21 << (int)QNetworkProxy::ListeningCapability; + QTest::newRow("imap-server-tag") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString("imap") << QString() << 143 << (int)QNetworkProxy::ListeningCapability; - foreach (proxy, systemProxyList) { - if (!nativeProxyList.contains(proxy)) { - qWarning() << "System proxy not found in native proxy list: " << - formatProxyName(proxy); - pass = false; - } + //UDP protocol tag + QTest::newRow("sip-udp-tag") << (int)QNetworkProxyQuery::UdpSocket << QUrl() << QString("sip") << QString("qt-project.org") << 5061 << (int)QNetworkProxy::UdpTunnelingCapability; +} + +//This function is added to QtNetwork in 5.0, but new exports aren't allowed in patch releases +QDebug operator<<(QDebug debug, const QNetworkProxy &proxy) +{ + QNetworkProxy::ProxyType type = proxy.type(); + switch (type) { + case QNetworkProxy::NoProxy: + debug << "NoProxy "; + break; + case QNetworkProxy::DefaultProxy: + debug << "DefaultProxy "; + break; + case QNetworkProxy::Socks5Proxy: + debug << "Socks5Proxy "; + break; + case QNetworkProxy::HttpProxy: + debug << "HttpProxy "; + break; + case QNetworkProxy::HttpCachingProxy: + debug << "HttpCachingProxy "; + break; + case QNetworkProxy::FtpCachingProxy: + debug << "FtpCachingProxy "; + break; + default: + debug << "Unknown proxy " << int(type); + break; } + debug << "\"" << proxy.hostName() << ":" << proxy.port() << "\" "; + QNetworkProxy::Capabilities caps = proxy.capabilities(); + QStringList scaps; + if (caps & QNetworkProxy::TunnelingCapability) + scaps << QLatin1String("Tunnel"); + if (caps & QNetworkProxy::ListeningCapability) + scaps << QLatin1String("Listen"); + if (caps & QNetworkProxy::UdpTunnelingCapability) + scaps << QLatin1String("UDP"); + if (caps & QNetworkProxy::CachingCapability) + scaps << QLatin1String("Caching"); + if (caps & QNetworkProxy::HostNameLookupCapability) + scaps << QLatin1String("NameLookup"); + debug << "[" << scaps.join(QLatin1String(" ")) << "]"; + return debug; +} - foreach (proxy, nativeProxyList) { - if (!systemProxyList.contains(proxy)) { - qWarning() << "Native proxy not found in system proxy list: " << - formatProxyName(proxy); - pass = false; - } +void tst_QNetworkProxyFactory::systemProxyForQuery() const +{ + QFETCH(int, type); + QFETCH(QUrl, url); + QFETCH(QString, tag); + QFETCH(QString, hostName); + QFETCH(int, port); + QFETCH(int, requiredCapabilities); + + QNetworkProxyQuery query; + + switch (type) { + case QNetworkProxyQuery::UrlRequest: + query = QNetworkProxyQuery(url); + break; + case QNetworkProxyQuery::TcpSocket: + case QNetworkProxyQuery::UdpSocket: + query = QNetworkProxyQuery(hostName, port, tag, QNetworkProxyQuery::QueryType(type)); + break; + case QNetworkProxyQuery::TcpServer: + query = QNetworkProxyQuery(quint16(port), tag); + break; } - if (!pass) - QFAIL("One or more system proxy lookup failures occurred."); + QElapsedTimer sw; + sw.start(); + QList<QNetworkProxy> systemProxyList = QNetworkProxyFactory::systemProxyForQuery(query); + qDebug() << sw.elapsed() << "ms"; + QVERIFY(!systemProxyList.isEmpty()); + + // for manual comparison with system + qDebug() << systemProxyList; + + foreach (const QNetworkProxy &proxy, systemProxyList) { + QVERIFY((requiredCapabilities == 0) || (proxy.capabilities() & requiredCapabilities)); + } } #ifndef QT_NO_BEARERMANAGEMENT |