diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2018-08-02 16:54:49 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2018-08-06 10:34:38 +0000 |
commit | cf41cd16a1f156d68f9cb4a84dd77230f29d739f (patch) | |
tree | de92f94f7e59c51f59bc8d205f633e23be39d8f2 /tests | |
parent | b2478bfb1f9cb48e077aeefd7a52be5d74de6437 (diff) | |
download | qtwebsockets-cf41cd16a1f156d68f9cb4a84dd77230f29d739f.tar.gz |
Limit Close frame to 125 bytes
All control frames should be limited to 125 frames.
https://tools.ietf.org/html/rfc6455#section-5.5
Task-number: QTBUG-62949
Change-Id: Id9b5a431faab6ff6edf7dc2e5c3525e999bc04ea
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp index ac54270..211ea25 100644 --- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp @@ -143,6 +143,7 @@ private Q_SLOTS: #ifndef QT_NO_NETWORKPROXY void tst_setProxy(); #endif + void overlongCloseReason(); }; tst_QWebSocket::tst_QWebSocket() @@ -724,6 +725,34 @@ void tst_QWebSocket::tst_setProxy() socket.setProxy(proxy); QCOMPARE(socket.proxy(), proxy); } + +void tst_QWebSocket::overlongCloseReason() +{ + EchoServer echoServer; + + QWebSocket socket; + + //should return 0 because socket is not open yet + QCOMPARE(socket.sendTextMessage(QStringLiteral("1234")), 0); + + QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy socketDisconnectedSpy(&socket, SIGNAL(disconnected())); + QSignalSpy serverConnectedSpy(&echoServer, SIGNAL(newConnection(QUrl))); + + QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + + QStringLiteral(":") + QString::number(echoServer.port())); + socket.open(url); + QTRY_COMPARE(socketConnectedSpy.count(), 1); + QTRY_COMPARE(serverConnectedSpy.count(), 1); + + const QString reason(200, QChar::fromLatin1('a')); + socket.close(QWebSocketProtocol::CloseCodeGoingAway, reason); + QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeGoingAway); + // Max length of a control frame is 125, but 2 bytes are used for the close code: + QCOMPARE(socket.closeReason().length(), 123); + QCOMPARE(socket.closeReason(), reason.leftRef(123)); + QTRY_COMPARE(socketDisconnectedSpy.count(), 1); +} #endif // QT_NO_NETWORKPROXY QTEST_MAIN(tst_QWebSocket) |