diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-10-03 14:00:46 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-10-06 05:09:59 +0000 |
commit | 1d8fed1d61ca36de9bd4ebd2b9ce1dcabafa815e (patch) | |
tree | ed238ca2c9e2b39a9eef854eab0a01e3edf755a5 | |
parent | 07e8c9cad45f39a5735e5636e1d2081768b51db6 (diff) | |
download | qtwebsockets-1d8fed1d61ca36de9bd4ebd2b9ce1dcabafa815e.tar.gz |
Fix uninitialized QWebSocket::errorString()
Amends: bbd9f2f4f5e0fda85029fa320f793973ea607c2b
Fixes: QTBUG-106937
Change-Id: Ia805df3e3dd8ba61e53592ebfb0a8bfae9184042
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 17b96b31585e338afe5f5c71706a12cc3d2cd740)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/websockets/qwebsocket_p.cpp | 2 | ||||
-rw-r--r-- | src/websockets/qwebsocket_p.h | 5 | ||||
-rw-r--r-- | tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp | 24 |
3 files changed, 25 insertions, 6 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index e43a701..15217ce 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -1060,7 +1060,7 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket) } else { errorDescription = QWebSocket::tr("QWebSocketPrivate::processHandshake: Unhandled http status code: %1 (%2).") - .arg(m_httpStatusCode).arg(m_httpStatusMessage); + .arg(parser.getStatusCode()).arg(parser.getReasonPhrase()); } if (ok) { diff --git a/src/websockets/qwebsocket_p.h b/src/websockets/qwebsocket_p.h index 0579b3d..167535c 100644 --- a/src/websockets/qwebsocket_p.h +++ b/src/websockets/qwebsocket_p.h @@ -220,11 +220,6 @@ private: QDefaultMaskGenerator m_defaultMaskGenerator; QByteArray m_statusLine; - int m_httpStatusCode; - int m_httpMajorVersion, m_httpMinorVersion; - QString m_httpStatusMessage; - QMultiMap<QString, QString> m_headers; - quint64 m_outgoingFrameSize; friend class QWebSocketServerPrivate; diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp index 4b6e5ba..09310a3 100644 --- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp @@ -5,6 +5,7 @@ #include <QtTest> #include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocketHandshakeOptions> +#include <QtWebSockets/QWebSocketCorsAuthenticator> #include <QtWebSockets/QWebSocketServer> #include <QtWebSockets/qwebsocketprotocol.h> @@ -29,6 +30,7 @@ public: Q_SIGNALS: void newConnection(QUrl requestUrl); void newConnection(QNetworkRequest request); + void originAuthenticationRequired(QWebSocketCorsAuthenticator* pAuthenticator); private Q_SLOTS: void onNewConnection(); @@ -56,6 +58,8 @@ EchoServer::EchoServer(QObject *parent, quint64 maxAllowedIncomingMessageSize, q if (m_pWebSocketServer->listen(QHostAddress(QStringLiteral("127.0.0.1")))) { connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection())); + connect(m_pWebSocketServer, &QWebSocketServer::originAuthenticationRequired, + this, &EchoServer::originAuthenticationRequired); } } @@ -613,6 +617,26 @@ void tst_QWebSocket::tst_errorString() qvariant_cast<QAbstractSocket::SocketError>(arguments.at(0)); QCOMPARE(socketError, QAbstractSocket::HostNotFoundError); QCOMPARE(socket.errorString(), QStringLiteral("Host not found")); + + // Check that handshake status code is parsed. The error is triggered by + // refusing the origin authentication + EchoServer echoServer; + errorSpy.clear(); + QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy serverConnectedSpy(&echoServer, SIGNAL(newConnection(QUrl))); + connect(&echoServer, &EchoServer::originAuthenticationRequired, + &socket, [](QWebSocketCorsAuthenticator* pAuthenticator){ + pAuthenticator->setAllowed(false); + }); + + socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + + QStringLiteral(":") + QString::number(echoServer.port()))); + QTRY_VERIFY(errorSpy.size() > 0); + QCOMPARE(serverConnectedSpy.size(), 0); + QCOMPARE(socketConnectedSpy.size(), 0); + QCOMPARE(socket.errorString(), + QStringLiteral("QWebSocketPrivate::processHandshake: Unhandled http status code: 403" + " (Access Forbidden).")); } void tst_QWebSocket::tst_openRequest_data() |