diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-07-27 10:31:14 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-07-27 10:31:14 +0200 |
| commit | 7614137a3f3706d6b2fdf1bdacae9569c683b0b0 (patch) | |
| tree | e94a852ded822afc785d67f27d5e7ac8ee7e073a /tests | |
| parent | 7c645e1dd1b8f19fe64a78f5620449ef9f216f5c (diff) | |
| download | qxmpp-7614137a3f3706d6b2fdf1bdacae9569c683b0b0.tar.gz | |
add some tests for invalid SOCKS5 handshake from client
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qxmppsocks/tst_qxmppsocks.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/qxmppsocks/tst_qxmppsocks.cpp b/tests/qxmppsocks/tst_qxmppsocks.cpp index 5958f0be..299417ae 100644 --- a/tests/qxmppsocks/tst_qxmppsocks.cpp +++ b/tests/qxmppsocks/tst_qxmppsocks.cpp @@ -35,6 +35,8 @@ private slots: void testClientAndServer(); void testServer(); + void testServerBadHandshake_data(); + void testServerBadHandshake(); private: QTcpSocket *m_connectionSocket; @@ -107,6 +109,9 @@ void tst_QXmppSocks::testServer() loop.exec(); QCOMPARE(client.readAll(), QByteArray::fromHex("050000030e7777772e676f6f676c652e636f6d0050")); + // check client + QCOMPARE(client.state(), QAbstractSocket::ConnectedState); + // check server QVERIFY(m_connectionSocket); QCOMPARE(m_connectionSocket->state(), QAbstractSocket::ConnectedState); @@ -117,5 +122,45 @@ void tst_QXmppSocks::testServer() client.disconnectFromHost(); } +void tst_QXmppSocks::testServerBadHandshake_data() +{ + QTest::addColumn<QByteArray>("clientHandshake"); + + QTest::newRow("bad SOCKS version") << QByteArray::fromHex("060100"); + QTest::newRow("no methods") << QByteArray::fromHex("0500"); +} + +void tst_QXmppSocks::testServerBadHandshake() +{ + QFETCH(QByteArray, clientHandshake); + + QXmppSocksServer server; + QVERIFY(server.listen()); + QVERIFY(server.serverPort() != 0); + connect(&server, SIGNAL(newConnection(QTcpSocket*,QString,quint16)), + this, SLOT(newConnectionSlot(QTcpSocket*,QString,quint16))); + + QTcpSocket client; + client.connectToHost(QHostAddress::LocalHost, server.serverPort()); + QVERIFY2(client.waitForConnected(), qPrintable(client.errorString())); + + QEventLoop loop; + connect(&client, SIGNAL(disconnected()), &loop, SLOT(quit())); + + client.write(clientHandshake); + loop.exec(); + + // check client + QCOMPARE(client.state(), QAbstractSocket::UnconnectedState); + + // check server + QVERIFY(!m_connectionSocket); + QVERIFY(m_connectionHostName.isNull()); + QCOMPARE(m_connectionPort, quint16(0)); + + // disconnect + client.disconnectFromHost(); +} + QTEST_MAIN(tst_QXmppSocks) #include "tst_qxmppsocks.moc" |
