summaryrefslogtreecommitdiff
path: root/tests/auto/websockets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/websockets')
-rw-r--r--tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp40
-rw-r--r--tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp6
-rw-r--r--tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro1
-rw-r--r--tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp57
-rw-r--r--tests/auto/websockets/websockets.pro3
5 files changed, 100 insertions, 7 deletions
diff --git a/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp b/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
index 4a9603f..230b052 100644
--- a/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
+++ b/tests/auto/websockets/handshakerequest/tst_handshakerequest.cpp
@@ -63,6 +63,7 @@ private Q_SLOTS:
void tst_multipleValuesInConnectionHeader();
void tst_multipleVersions();
+ void tst_parsingWhitespaceInHeaders();
void tst_qtbug_39355();
void tst_qtbug_48123_data();
@@ -194,6 +195,17 @@ void tst_HandshakeRequest::tst_invalidStream_data()
QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") +
QStringLiteral("Upgrade: websocket,ftp\r\n") +
QStringLiteral("Connection: Upgrade\r\n\r\n");
+ QTest::newRow("Invalid header - starts with continuation")
+ << QStringLiteral("GET . HTTP/1.1\r\n Host: foo\r\nSec-WebSocket-Version: 13\r\n") +
+ QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") +
+ QStringLiteral("Upgrade: websocket\r\n") +
+ QStringLiteral("Connection: Upgrade\r\n\r\n");
+ QTest::newRow("Invalid header - no colon")
+ << QStringLiteral("GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") +
+ QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") +
+ QStringLiteral("Upgrade: websocket\r\n") +
+ QStringLiteral("X-Custom foo\r\n") +
+ QStringLiteral("Connection: Upgrade\r\n\r\n");
}
void tst_HandshakeRequest::tst_invalidStream()
@@ -259,6 +271,34 @@ void tst_HandshakeRequest::tst_multipleValuesInConnectionHeader()
QCOMPARE(request.versions().at(0), QWebSocketProtocol::Version13);
}
+/*
+ * This is a regression test
+ * Checks for RFC compliant header parsing
+ */
+void tst_HandshakeRequest::tst_parsingWhitespaceInHeaders()
+{
+ //doing extensive QStringLiteral concatenations here, because
+ //MSVC 2010 complains when using concatenation literal strings about
+ //concatenation of wide and narrow strings (error C2308)
+ QString header = QStringLiteral("GET /test HTTP/1.1\r\nHost: ") +
+ QStringLiteral("foo.com\r\nSec-WebSocket-Version:13\r\n") +
+ QStringLiteral("Sec-WebSocket-Key: AVD \r\n\tFBDDFF \r\n") +
+ QStringLiteral("Upgrade:websocket \r\n") +
+ QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n");
+ QByteArray data;
+ QTextStream textStream(&data);
+ QWebSocketHandshakeRequest request(80, false);
+
+ textStream << header;
+ textStream.seek(0);
+ request.readHandshake(textStream, MAX_HEADERLINE_LENGTH, MAX_HEADERS);
+
+ QVERIFY(request.isValid());
+ QCOMPARE(request.key(), QStringLiteral("AVD FBDDFF"));
+ QCOMPARE(request.versions().length(), 1);
+ QCOMPARE(request.versions().at(0), QWebSocketProtocol::Version13);
+}
+
void tst_HandshakeRequest::tst_multipleVersions()
{
QString header = QStringLiteral("GET /test HTTP/1.1\r\nHost: foo.com\r\n") +
diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
index dfa0ce5..ac54270 100644
--- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
@@ -39,7 +39,7 @@ class EchoServer : public QObject
{
Q_OBJECT
public:
- explicit EchoServer(QObject *parent = Q_NULLPTR);
+ explicit EchoServer(QObject *parent = nullptr);
~EchoServer();
QHostAddress hostAddress() const { return m_pWebSocketServer->serverAddress(); }
@@ -659,7 +659,7 @@ void tst_QWebSocket::tst_moveToThread()
EchoServer echoServer;
- QThread* thread = new QThread;
+ QThread* thread = new QThread(this);
thread->start();
WebSocket* socket = new WebSocket;
@@ -696,7 +696,7 @@ void tst_QWebSocket::tst_moveToThread()
socket->deleteLater();
thread->quit();
- thread->deleteLater();
+ thread->wait();
}
void tst_QWebSocket::tst_moveToThreadNoWarning()
diff --git a/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro b/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro
index e166f50..178fd88 100644
--- a/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro
+++ b/tests/auto/websockets/qwebsocketserver/qwebsocketserver.pro
@@ -12,3 +12,4 @@ SOURCES += tst_qwebsocketserver.cpp
RESOURCES += $$PWD/../shared/qwebsocketshared.qrc
+boot2qt: DEFINES += SHOULD_CHECK_SYSCALL_SUPPORT
diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
index b7734a4..8a3760d 100644
--- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
+++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
@@ -112,9 +112,15 @@ private Q_SLOTS:
void tst_serverDestroyedWhileSocketConnected();
void tst_scheme(); // qtbug-55927
void tst_handleConnection();
+
+private:
+ bool m_shouldSkipUnsupportedIpv6Test;
+#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
+ bool ipv6GetsockoptionMissing(int level, int optname);
+#endif
};
-tst_QWebSocketServer::tst_QWebSocketServer()
+tst_QWebSocketServer::tst_QWebSocketServer() : m_shouldSkipUnsupportedIpv6Test(false)
{
}
@@ -132,8 +138,42 @@ void tst_QWebSocketServer::init()
#endif
}
+#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <unistd.h>
+
+bool tst_QWebSocketServer::ipv6GetsockoptionMissing(int level, int optname)
+{
+ int testSocket;
+
+ testSocket = socket(PF_INET6, SOCK_STREAM, 0);
+
+ // If we can't test here, assume it's not missing
+ if (testSocket == -1)
+ return false;
+
+ bool result = false;
+ if (getsockopt(testSocket, level, optname, nullptr, 0) == -1) {
+ if (errno == EOPNOTSUPP) {
+ result = true;
+ }
+ }
+
+ close(testSocket);
+ return result;
+}
+
+#endif //SHOULD_CHECK_SYSCALL_SUPPORT
+
void tst_QWebSocketServer::initTestCase()
{
+#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
+ // Qemu does not have required support for IPV6 socket options.
+ // If this is detected, skip the test
+ m_shouldSkipUnsupportedIpv6Test = ipv6GetsockoptionMissing(SOL_IPV6, IPV6_V6ONLY);
+#endif
}
void tst_QWebSocketServer::cleanupTestCase()
@@ -283,6 +323,9 @@ void tst_QWebSocketServer::tst_listening()
void tst_QWebSocketServer::tst_connectivity()
{
+ if (m_shouldSkipUnsupportedIpv6Test)
+ QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
+
QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode);
QSignalSpy serverConnectionSpy(&server, SIGNAL(newConnection()));
QSignalSpy serverErrorSpy(&server,
@@ -323,6 +366,9 @@ void tst_QWebSocketServer::tst_connectivity()
void tst_QWebSocketServer::tst_preSharedKey()
{
+ if (m_shouldSkipUnsupportedIpv6Test)
+ QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
+
#ifndef QT_NO_OPENSSL
QWebSocketServer server(QString(), QWebSocketServer::SecureMode);
@@ -399,6 +445,9 @@ void tst_QWebSocketServer::tst_preSharedKey()
void tst_QWebSocketServer::tst_maxPendingConnections()
{
+ if (m_shouldSkipUnsupportedIpv6Test)
+ QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
+
//tests if maximum connections are respected
//also checks if there are no side-effects like signals that are unexpectedly thrown
QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode);
@@ -474,6 +523,9 @@ void tst_QWebSocketServer::tst_maxPendingConnections()
void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected()
{
+ if (m_shouldSkipUnsupportedIpv6Test)
+ QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
+
QWebSocketServer * server = new QWebSocketServer(QString(), QWebSocketServer::NonSecureMode);
QSignalSpy serverConnectionSpy(server, SIGNAL(newConnection()));
QSignalSpy corsAuthenticationSpy(server,
@@ -505,6 +557,9 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected()
void tst_QWebSocketServer::tst_scheme()
{
+ if (m_shouldSkipUnsupportedIpv6Test)
+ QSKIP("Syscalls needed for ipv6 sockoptions missing functionality");
+
QWebSocketServer plainServer(QString(), QWebSocketServer::NonSecureMode);
QSignalSpy plainServerConnectionSpy(&plainServer, SIGNAL(newConnection()));
diff --git a/tests/auto/websockets/websockets.pro b/tests/auto/websockets/websockets.pro
index 4b7ee4e..b000229 100644
--- a/tests/auto/websockets/websockets.pro
+++ b/tests/auto/websockets/websockets.pro
@@ -14,6 +14,3 @@ qtConfig(private_tests): SUBDIRS += \
SUBDIRS += \
qwebsocket \
qwebsocketserver
-
-# QTBUG-60268
-boot2qt: SUBDIRS -= qwebsocketserver