diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2022-10-03 14:00:46 +0300 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@insta.fi> | 2022-10-05 13:08:38 +0300 |
commit | 17b96b31585e338afe5f5c71706a12cc3d2cd740 (patch) | |
tree | e97b0cb7281ac11e63ec2792ed5c24c731835b61 | |
parent | b8d114fc4b48ff1875b18cce4262e2d630c0f738 (diff) | |
download | qtwebsockets-17b96b31585e338afe5f5c71706a12cc3d2cd740.tar.gz |
Fix uninitialized QWebSocket::errorString()
Amends: bbd9f2f4f5e0fda85029fa320f793973ea607c2b
Fixes: QTBUG-106937
Pick-to: 6.3 6.4
Change-Id: Ia805df3e3dd8ba61e53592ebfb0a8bfae9184042
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-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 b806229..c13d831 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -1058,7 +1058,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 48f7fb3..f30dfff 100644 --- a/src/websockets/qwebsocket_p.h +++ b/src/websockets/qwebsocket_p.h @@ -221,11 +221,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() |