summaryrefslogtreecommitdiffstats
path: root/tests/auto/network
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network')
-rw-r--r--tests/auto/network/access/qftp/tst_qftp.cpp209
-rw-r--r--tests/auto/network/socket/qudpsocket/BLACKLIST3
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp19
3 files changed, 226 insertions, 5 deletions
diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp
index e00459557a..d42702e1de 100644
--- a/tests/auto/network/access/qftp/tst_qftp.cpp
+++ b/tests/auto/network/access/qftp/tst_qftp.cpp
@@ -41,6 +41,8 @@
#include <qnetworkconfigmanager.h>
#include <QNetworkSession>
#include <QtNetwork/private/qnetworksession_p.h>
+#include <QTcpServer>
+#include <QHostInfo>
#include "../../../network-settings.h"
@@ -108,6 +110,9 @@ private slots:
void qtbug7359Crash();
+ void loginURL_data();
+ void loginURL();
+
protected slots:
void stateChanged( int );
void listInfo( const QUrlInfo & );
@@ -397,11 +402,11 @@ void tst_QFtp::login_data()
QTest::addColumn<int>("success");
QTest::newRow( "ok01" ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString() << 1;
- QTest::newRow( "ok02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString() << 1;
+ QTest::newRow( "ok02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("") << 1;
QTest::newRow( "ok03" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftp") << QString("foo") << 1;
QTest::newRow( "ok04" ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password") << 1;
- QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString() << 0;
+ QTest::newRow( "error01" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString("") << 0;
QTest::newRow( "error02" ) << QtNetworkSettings::serverName() << (uint)21 << QString("foo") << QString("bar") << 0;
}
@@ -2152,6 +2157,206 @@ void tst_QFtp::qtbug7359Crash()
QCoreApplication::processEvents(QEventLoop::AllEvents, 2000 - elapsed);
}
+class FtpLocalServer : public QTcpServer
+{
+ Q_OBJECT
+
+public:
+ explicit FtpLocalServer(QObject *parent = 0) : QTcpServer(parent) {}
+ virtual ~FtpLocalServer() { delete mSocket; }
+ void startServer(qint16 port = 0);
+ void stopServer();
+
+ enum class ReplyCodes {
+ ServiceReady = 220,
+ ServiceClose = 221,
+ NeedPassword = 331,
+ LoginFailed = 530,
+ RequestDeny = 550
+ };
+
+ void sendResponse(ReplyCodes code);
+
+ inline QString getRawUser() { return rawUser; }
+ inline QString getRawPassword() { return rawPass; }
+
+signals:
+ void onStarted();
+ void onStopped();
+
+public slots:
+ void socketReadyRead();
+ void socketDisconnected();
+
+protected:
+ virtual void incomingConnection(qintptr handle);
+
+private:
+ QTcpSocket *mSocket = nullptr;
+ QString rawUser;
+ QString rawPass;
+};
+
+void FtpLocalServer::startServer(qint16 port)
+{
+ if (listen(QHostAddress::Any, port))
+ emit onStarted(); // Notify connected objects
+ else
+ qDebug("Could not start FTP server");
+}
+
+void FtpLocalServer::stopServer()
+{
+ close();
+ emit onStopped(); // Notify connected objects
+}
+
+void FtpLocalServer::sendResponse(ReplyCodes code)
+{
+ if (mSocket)
+ {
+ QString response;
+ switch (code) {
+ case ReplyCodes::ServiceReady:
+ response = QString("220 Service ready for new user.\r\n");
+ break;
+ case ReplyCodes::ServiceClose:
+ response = QString("221 Service closing control connection.\r\n");
+ break;
+ case ReplyCodes::NeedPassword:
+ response = QString("331 User name okay, need password.\r\n");
+ break;
+ case ReplyCodes::LoginFailed:
+ response = QString("530 Not logged in.\r\n");
+ break;
+ case ReplyCodes::RequestDeny:
+ response = QString("550 Requested action not taken.\r\n");
+ break;
+ default:
+ qDebug("Unimplemented response code: %u", static_cast<uint>(code));
+ break;
+ }
+
+ if (!response.isEmpty())
+ mSocket->write(response.toLatin1());
+ }
+}
+
+void FtpLocalServer::incomingConnection(qintptr handle)
+{
+ mSocket = new QTcpSocket(this);
+ if (mSocket == nullptr || !mSocket->setSocketDescriptor(handle))
+ {
+ delete mSocket;
+ mSocket = nullptr;
+ qDebug() << handle << " Error binding socket";
+ return;
+ }
+
+ connect(mSocket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
+ connect(mSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+
+ // Accept client connection
+ sendResponse(ReplyCodes::ServiceReady);
+}
+
+void FtpLocalServer::socketReadyRead()
+{
+ QString data;
+ if (mSocket)
+ data.append(mSocket->readAll());
+
+ // RFC959 Upper and lower case alphabetic characters are to be treated identically.
+ if (data.startsWith("USER", Qt::CaseInsensitive)) {
+ rawUser = data;
+ sendResponse(ReplyCodes::NeedPassword);
+ } else if (data.startsWith("PASS", Qt::CaseInsensitive)) {
+ rawPass = data;
+ sendResponse(ReplyCodes::LoginFailed);
+ } else {
+ sendResponse(ReplyCodes::RequestDeny);
+ }
+}
+
+void FtpLocalServer::socketDisconnected()
+{
+ // Cleanup
+ if (mSocket)
+ mSocket->deleteLater();
+ deleteLater();
+}
+
+void tst_QFtp::loginURL_data()
+{
+ QTest::addColumn<QString>("user");
+ QTest::addColumn<QString>("password");
+ QTest::addColumn<QString>("rawUser");
+ QTest::addColumn<QString>("rawPass");
+
+ QTest::newRow("no username, no password")
+ << QString() << QString()
+ << QString("USER anonymous\r\n") << QString("PASS anonymous@\r\n");
+
+ QTest::newRow("username, no password")
+ << QString("someone") << QString()
+ << QString("USER someone\r\n") << QString();
+
+ QTest::newRow("username, empty password")
+ << QString("someone") << QString("")
+ << QString("USER someone\r\n") << QString("PASS \r\n");
+
+ QTest::newRow("username, password")
+ << QString("someone") << QString("nonsense")
+ << QString("USER someone\r\n") << QString("PASS nonsense\r\n");
+
+ QTest::newRow("anonymous, no password")
+ << QString("anonymous") << QString()
+ << QString("USER anonymous\r\n") << QString("PASS anonymous@\r\n");
+
+ QTest::newRow("Anonymous, no password")
+ << QString("Anonymous") << QString()
+ << QString("USER Anonymous\r\n") << QString("PASS anonymous@\r\n");
+
+ QTest::newRow("anonymous, empty password")
+ << QString("anonymous") << QString("")
+ << QString("USER anonymous\r\n") << QString("PASS \r\n");
+
+ QTest::newRow("ANONYMOUS, password")
+ << QString("ANONYMOUS") << QString("nonsense")
+ << QString("USER ANONYMOUS\r\n") << QString("PASS nonsense\r\n");
+}
+
+void tst_QFtp::loginURL()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ QSKIP("This test should be verified on the local machine without proxies");
+
+ QFETCH(QString, user);
+ QFETCH(QString, password);
+ QFETCH(QString, rawUser);
+ QFETCH(QString, rawPass);
+
+ FtpLocalServer server;
+ server.startServer();
+ uint port = server.serverPort();
+
+ ftp = newFtp();
+ addCommand(QFtp::ConnectToHost,
+ ftp->connectToHost(QHostInfo::localHostName(), port));
+ addCommand(QFtp::Login, ftp->login(user, password));
+
+ QTestEventLoop::instance().enterLoop(5);
+ delete ftp;
+ ftp = nullptr;
+ server.stopServer();
+ if (QTestEventLoop::instance().timeout())
+ QFAIL(msgTimedOut(QHostInfo::localHostName(), port));
+
+ QCOMPARE(server.getRawUser(), rawUser);
+ QCOMPARE(server.getRawPassword(), rawPass);
+}
+
QTEST_MAIN(tst_QFtp)
#include "tst_qftp.moc"
diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST
index d58a850a1f..a98c4d5c6b 100644
--- a/tests/auto/network/socket/qudpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qudpsocket/BLACKLIST
@@ -18,12 +18,9 @@ osx
osx
[broadcasting]
osx
-ubuntu-16.04
[zeroLengthDatagram]
osx
[linkLocalIPv6]
redhatenterpriselinuxworkstation-6.6
-[pendingDatagramSize]
-ubuntu-16.04
[readyReadForEmptyDatagram]
ubuntu-16.04
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index bbac03b708..8165ccbc58 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -126,12 +126,14 @@ protected slots:
private:
bool shouldSkipIpv6TestsForBrokenSetsockopt();
+ bool shouldWorkaroundLinuxKernelBug();
#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
bool ipv6SetsockoptionMissing(int level, int optname);
#endif
QNetworkInterface interfaceForGroup(const QHostAddress &multicastGroup);
bool m_skipUnsupportedIPv6Tests;
+ bool m_workaroundLinuxKernelBug;
QList<QHostAddress> allAddresses;
QHostAddress multicastGroup4, multicastGroup6;
QVector<QHostAddress> linklocalMulticastGroups;
@@ -207,6 +209,16 @@ QNetworkInterface tst_QUdpSocket::interfaceForGroup(const QHostAddress &multicas
return ipv6if;
}
+bool tst_QUdpSocket::shouldWorkaroundLinuxKernelBug()
+{
+#ifdef Q_OS_LINUX
+ const QVersionNumber version = QVersionNumber::fromString(QSysInfo::kernelVersion());
+ return version.majorVersion() == 4 && version.minorVersion() >= 6 && version.minorVersion() < 13;
+#else
+ return false;
+#endif
+}
+
static QHostAddress makeNonAny(const QHostAddress &address, QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost)
{
if (address == QHostAddress::Any)
@@ -276,6 +288,7 @@ void tst_QUdpSocket::initTestCase()
qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups;
+ m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug();
if (EmulationDetector::isRunningArmOnX86())
QSKIP("This test is unreliable due to QEMU emulation shortcomings.");
}
@@ -360,6 +373,9 @@ void tst_QUdpSocket::unconnectedServerAndClientTest()
void tst_QUdpSocket::broadcasting()
{
+ if (m_workaroundLinuxKernelBug)
+ QSKIP("This test can fail due to linux kernel bug");
+
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
#ifndef QT_NO_NETWORKPROXY
@@ -805,6 +821,9 @@ void tst_QUdpSocket::bindAndConnectToHost()
void tst_QUdpSocket::pendingDatagramSize()
{
+ if (m_workaroundLinuxKernelBug)
+ QSKIP("This test can fail due to linux kernel bug");
+
QUdpSocket server;
QVERIFY2(server.bind(), server.errorString().toLatin1().constData());