From e0cf3fcd8f8680e9c8b0fe1f1f18c1dda89eca80 Mon Sep 17 00:00:00 2001 From: Thomas McGuire Date: Tue, 23 Apr 2013 09:37:29 +0200 Subject: Fix retrieving of the generic system proxy via environment variables ignoreProxyFor() always returned true if the no_proxy was not set, which resulted in the first token being an empty QByteArray, causing the endsWith() check to always evaluate to true. Add a unit test that is enabled for those platforms that use the generic system proxy. Change-Id: I6081ad5e0b8e2c3fee1568835907c32bde5b7772 Reviewed-by: Peter Hartmann --- src/network/kernel/qnetworkproxy_generic.cpp | 6 +++- .../tst_qnetworkproxyfactory.cpp | 41 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp index 9069755da4..c576719076 100644 --- a/src/network/kernel/qnetworkproxy_generic.cpp +++ b/src/network/kernel/qnetworkproxy_generic.cpp @@ -55,7 +55,11 @@ QT_BEGIN_NAMESPACE static bool ignoreProxyFor(const QNetworkProxyQuery &query) { - const QList noProxyTokens = qgetenv("no_proxy").split(','); + const QByteArray noProxy = qgetenv("no_proxy").trimmed(); + if (noProxy.isEmpty()) + return false; + + const QList noProxyTokens = noProxy.split(','); foreach (const QByteArray &rawToken, noProxyTokens) { QByteArray token = rawToken.trimmed(); diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index d57a99a758..e06285dc67 100644 --- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -87,6 +87,8 @@ private slots: void inNetworkAccessManager_data(); void inNetworkAccessManager(); #endif + void genericSystemProxy(); + void genericSystemProxy_data(); private: QString formatProxyName(const QNetworkProxy & proxy) const; @@ -367,6 +369,45 @@ void tst_QNetworkProxyFactory::inNetworkAccessManager() #endif //QT_NO_BEARERMANAGEMENT +Q_DECLARE_METATYPE(QNetworkProxy::ProxyType) + +void tst_QNetworkProxyFactory::genericSystemProxy() +{ + QFETCH(QByteArray, envVar); + QFETCH(QByteArray, url); + QFETCH(QNetworkProxy::ProxyType, proxyType); + QFETCH(QString, hostName); + QFETCH(int, port); + +// The generic system proxy is only available on the following platforms +#if (!defined Q_OS_BLACKBERRY) && (!defined Q_OS_WIN) && ((!defined Q_OS_MAC) || defined Q_OS_IOS) + qputenv(envVar, url); + const QList systemProxy = QNetworkProxyFactory::systemProxyForQuery(); + QCOMPARE(systemProxy.size(), 1); + QCOMPARE(systemProxy.first().type(), proxyType); + QCOMPARE(systemProxy.first().hostName(), hostName); + QCOMPARE(systemProxy.first().port(), static_cast(port)); + qunsetenv(envVar); +#else + QSKIP("Generic system proxy not available on this platform."); +#endif +} + +void tst_QNetworkProxyFactory::genericSystemProxy_data() +{ + QTest::addColumn("envVar"); + QTest::addColumn("url"); + QTest::addColumn("proxyType"); + QTest::addColumn("hostName"); + QTest::addColumn("port"); + + QTest::newRow("no proxy") << QByteArray("http_proxy") << QByteArray() << QNetworkProxy::NoProxy + << QString() << 0; + QTest::newRow("socks5") << QByteArray("http_proxy") << QByteArray("socks5://127.0.0.1:4242") + << QNetworkProxy::Socks5Proxy << QString("127.0.0.1") << 4242; + QTest::newRow("http") << QByteArray("http_proxy") << QByteArray("http://example.com:666") + << QNetworkProxy::HttpProxy << QString("example.com") << 666; +} class QSPFQThread : public QThread { -- cgit v1.2.3