aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-10-03 14:00:46 +0300
committerJuha Vuolle <juha.vuolle@insta.fi>2022-10-05 13:08:38 +0300
commit17b96b31585e338afe5f5c71706a12cc3d2cd740 (patch)
treee97b0cb7281ac11e63ec2792ed5c24c731835b61 /tests
parentb8d114fc4b48ff1875b18cce4262e2d630c0f738 (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp24
1 files changed, 24 insertions, 0 deletions
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()