summaryrefslogtreecommitdiffstats
path: root/tests/auto/networkselftest/tst_networkselftest.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-10-06 18:55:18 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-10-06 18:55:18 (GMT)
commit46d12ba420b7c4870f6bab2c44002dbb48c35629 (patch)
treee02f5af44537d8445ff20251065edf14d4516b4a /tests/auto/networkselftest/tst_networkselftest.cpp
parentffeb69003a9c676064cdf7ec099a02c2fbcf2ad3 (diff)
parentd47b7e6d0adcd675ba9da11818b3fa9acc3caff5 (diff)
downloadQt-46d12ba420b7c4870f6bab2c44002dbb48c35629.zip
Qt-46d12ba420b7c4870f6bab2c44002dbb48c35629.tar.gz
Qt-46d12ba420b7c4870f6bab2c44002dbb48c35629.tar.bz2
Merge branch '4.5' into 4.6
Conflicts: tests/auto/networkselftest/tst_networkselftest.cpp
Diffstat (limited to 'tests/auto/networkselftest/tst_networkselftest.cpp')
-rw-r--r--tests/auto/networkselftest/tst_networkselftest.cpp86
1 files changed, 80 insertions, 6 deletions
diff --git a/tests/auto/networkselftest/tst_networkselftest.cpp b/tests/auto/networkselftest/tst_networkselftest.cpp
index 4e60101..d58402b 100644
--- a/tests/auto/networkselftest/tst_networkselftest.cpp
+++ b/tests/auto/networkselftest/tst_networkselftest.cpp
@@ -54,10 +54,13 @@
class tst_NetworkSelfTest: public QObject
{
Q_OBJECT
+ QHostAddress cachedIpAddress;
public:
tst_NetworkSelfTest();
virtual ~tst_NetworkSelfTest();
+ QHostAddress serverIpAddress();
+
private slots:
void hostTest();
void dnsResolution_data();
@@ -325,6 +328,16 @@ tst_NetworkSelfTest::~tst_NetworkSelfTest()
{
}
+QHostAddress tst_NetworkSelfTest::serverIpAddress()
+{
+ if (cachedIpAddress.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol) {
+ // need resolving
+ QHostInfo resolved = QHostInfo::fromName(QtNetworkSettings::serverName());
+ cachedIpAddress = resolved.addresses().first();
+ }
+ return cachedIpAddress;
+}
+
void tst_NetworkSelfTest::hostTest()
{
// this is a localhost self-test
@@ -353,14 +366,22 @@ void tst_NetworkSelfTest::dnsResolution()
QHostInfo resolved = QHostInfo::fromName(hostName);
QVERIFY2(resolved.error() == QHostInfo::NoError,
QString("Failed to resolve hostname %1: %2").arg(hostName, resolved.errorString()).toLocal8Bit());
+ QVERIFY2(resolved.addresses().size() > 0, "Got 0 addresses for server IP");
+
+ cachedIpAddress = resolved.addresses().first();
}
void tst_NetworkSelfTest::serverReachability()
{
- // check that we get a proper error connecting to port 1
+ // check that we get a proper error connecting to port 12346
QTcpSocket socket;
- socket.connectToHost(QtNetworkSettings::serverName(), 1);
+ socket.connectToHost(QtNetworkSettings::serverName(), 12346);
+
+ QTime timer;
+ timer.start();
socket.waitForConnected(10000);
+ QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong");
+
QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!");
QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError,
QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit());
@@ -516,7 +537,18 @@ void tst_NetworkSelfTest::httpsServer()
void tst_NetworkSelfTest::httpProxy()
{
netChat(3128, QList<Chat>()
- // proxy GET
+ // proxy GET by IP
+ << Chat::send("GET http://" + serverIpAddress().toString().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+
+ // proxy GET by hostname
+ << Chat::Reconnect
<< Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
"Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
"Proxy-connection: close\r\n"
@@ -526,7 +558,17 @@ void tst_NetworkSelfTest::httpProxy()
<< Chat::expect("200 ")
<< Chat::DiscardUntilDisconnect
- // proxy CONNECT
+ // proxy CONNECT by IP
+ << Chat::Reconnect
+ << Chat::send("CONNECT " + serverIpAddress().toString().toLatin1() + ":21 HTTP/1.0\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::discardUntil("\r\n\r\n")
+ << ftpChat()
+
+ // proxy CONNECT by hostname
<< Chat::Reconnect
<< Chat::send("CONNECT " + QtNetworkSettings::serverName().toLatin1() + ":21 HTTP/1.0\r\n"
"\r\n")
@@ -534,7 +576,8 @@ void tst_NetworkSelfTest::httpProxy()
<< Chat::discardUntil(" ")
<< Chat::expect("200 ")
<< Chat::discardUntil("\r\n\r\n")
- << ftpChat());
+ << ftpChat()
+ );
}
void tst_NetworkSelfTest::httpProxyBasicAuth()
@@ -591,11 +634,22 @@ static const char handshakeAuthPassword[] = "\5\1\2\1\12qsockstest\10password";
static const char handshakeOkPasswdAuth[] = "\5\2\1\0";
static const char handshakeAuthNotOk[] = "\5\377";
static const char connect1[] = "\5\1\0\1\177\0\0\1\0\25"; // Connect IPv4 127.0.0.1 port 21
+static const char connect1a[] = "\5\1\0\1"; // just "Connect to IPv4"
+static const char connect1b[] = "\0\25"; // just "port 21"
static const char connect2[] = "\5\1\0\3\11localhost\0\25"; // Connect hostname localhost 21
+static const char connect2a[] = "\5\1\0\3"; // just "Connect to hostname"
static const char connected[] = "\5\0\0";
+#define QBA(x) (QByteArray::fromRawData(x, -1 + sizeof(x)))
+
void tst_NetworkSelfTest::socks5Proxy()
{
+ union {
+ char buf[4];
+ quint32 data;
+ } ip4Address;
+ ip4Address.data = qToBigEndian(serverIpAddress().toIPv4Address());
+
netChat(1080, QList<Chat>()
// IP address connection
<< Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
@@ -606,7 +660,17 @@ void tst_NetworkSelfTest::socks5Proxy()
<< Chat::skipBytes(6) // the server's local address and port
<< ftpChat()
- // hostname connection
+ // connect by IP
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QBA(connect1a) + QByteArray::fromRawData(ip4Address.buf, 4) + QBA(connect1b))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+
+ // connect to "localhost" by hostname
<< Chat::Reconnect
<< Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
<< Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
@@ -615,6 +679,16 @@ void tst_NetworkSelfTest::socks5Proxy()
<< Chat::expect("\1") // IPv4 address following
<< Chat::skipBytes(6) // the server's local address and port
<< ftpChat()
+
+ // connect to server by its official name
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QBA(connect2a) + char(QtNetworkSettings::serverName().size()) + QtNetworkSettings::serverName().toLatin1() + QBA(connect1b))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
);
}