From 203da360c4bcd64bdd17639d495f1857b622e92d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= <aklitzing@gmail.com>
Date: Thu, 19 Oct 2017 16:05:17 +0200
Subject: [PATCH] Fix empty sslConfiguration in sslErrors slot

If QWebSocket fires signal sslErrors the
QSslConfiguration of QWebSocket is not updated.
So client application cannot check it in
implemented slot.

Fix this by calling the update method like
for encrypted signal.

Sibling of QTBUG-40401.

Change-Id: I18b39f6b6a0791ae67fc2bff5cf2c04a22b0ab85
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
---
 src/websockets/qwebsocket_p.cpp                        |  3 +++
 .../qwebsocketserver/tst_qwebsocketserver.cpp          | 10 +++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 7863567a..bee2afab 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -596,6 +596,9 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket)
             QObject::connect(sslSocket, &QSslSocket::encryptedBytesWritten, q,
                              &QWebSocket::bytesWritten);
             typedef void (QSslSocket:: *sslErrorSignalType)(const QList<QSslError> &);
+            QObjectPrivate::connect(sslSocket,
+                                    static_cast<sslErrorSignalType>(&QSslSocket::sslErrors),
+                                    this, &QWebSocketPrivate::_q_updateSslConfiguration);
             QObject::connect(sslSocket,
                              static_cast<sslErrorSignalType>(&QSslSocket::sslErrors),
                              q, &QWebSocket::sslErrors);
diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
index 82a873d4..b7734a4f 100644
--- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
+++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
@@ -31,9 +31,9 @@
 #include <QTcpServer>
 #ifndef QT_NO_OPENSSL
 #include <QtNetwork/qsslpresharedkeyauthenticator.h>
-#include <QtNetwork/qsslcipher.h>
 #endif
 #ifndef QT_NO_SSL
+#include <QtNetwork/qsslcipher.h>
 #include <QtNetwork/qsslkey.h>
 #endif
 #include <QtWebSockets/QWebSocketServer>
@@ -539,10 +539,13 @@ void tst_QWebSocketServer::tst_scheme()
 
     QVERIFY(secureServer.listen());
 
+    QSslCipher sessionCipher;
     QWebSocket secureSocket;
-    typedef void (QWebSocket::* ignoreSslErrorsSlot)();
     connect(&secureSocket, &QWebSocket::sslErrors,
-            &secureSocket, static_cast<ignoreSslErrorsSlot>(&QWebSocket::ignoreSslErrors));
+            &secureSocket, [&] {
+                secureSocket.ignoreSslErrors();
+                sessionCipher = secureSocket.sslConfiguration().sessionCipher();
+            });
     secureSocket.open(secureServer.serverUrl().toString());
 
     QTRY_COMPARE(secureServerConnectionSpy.count(), 1);
@@ -550,6 +553,7 @@ void tst_QWebSocketServer::tst_scheme()
     QVERIFY(!secureServerSocket.isNull());
     QCOMPARE(secureServerSocket->requestUrl().scheme(), QStringLiteral("wss"));
     secureServer.close();
+    QVERIFY(!sessionCipher.isNull());
 #endif
 }
 
-- 
GitLab