diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2022-11-15 14:12:34 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2022-11-24 09:39:00 +0000 |
commit | 69e2b30057003c0ed17c3478d60fea249546a168 (patch) | |
tree | 34f8b7bdc7d23e55bfa5a6ddda1b6ff781e599be /tests | |
parent | 0fbd3decd0dd694063edd06a174f137ec30d3741 (diff) |
QWebSocket: honor subprotocols specified with setRawHeader
We would error out with a ConnectionRejected if the server accepted
one of the protocols specified directly in the header since we
did not consider those at all.
Fixes: QTBUG-108276
Pick-to: 6.4
Change-Id: Ifbb316c9d4871fd764e03c74caefa10f5b757155
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 118a5c2..c0ba30c 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -356,20 +356,28 @@ void tst_QWebSocketServer::tst_connectivity() void tst_QWebSocketServer::tst_protocols_data() { QTest::addColumn<QStringList>("clientProtocols"); + QTest::addColumn<QStringList>("headerProtocols"); QTest::addColumn<QString>("expectedProtocol"); - QTest::addRow("none") << QStringList {} << QString {}; + + QTest::addRow("none") << QStringList{} << QStringList{} << QString{}; QTest::addRow("same order as server") - << QStringList { "chat", "superchat" } << QStringLiteral("chat"); + << QStringList{ "chat", "superchat" } << QStringList{} << QStringLiteral("chat"); QTest::addRow("different order from server") - << QStringList { "superchat", "chat" } << QStringLiteral("superchat"); - QTest::addRow("unsupported protocol") << QStringList { "foo" } << QString {}; + << QStringList{ "superchat", "chat" } << QStringList{} << QStringLiteral("superchat"); + QTest::addRow("unsupported protocol") << QStringList{ "foo" } << QStringList{} << QString{}; QTest::addRow("mixed supported/unsupported protocol") - << QStringList { "foo", "chat" } << QStringLiteral("chat"); + << QStringList{ "foo", "chat" } << QStringList{} << QStringLiteral("chat"); + + QTest::addRow("same order as server, in header") + << QStringList{} << QStringList{ "chat", "superchat" } << QStringLiteral("chat"); + QTest::addRow("specified in options and in header") + << QStringList{ "superchat" } << QStringList{ "chat" } << QStringLiteral("superchat"); } void tst_QWebSocketServer::tst_protocols() { QFETCH(QStringList, clientProtocols); + QFETCH(QStringList, headerProtocols); QFETCH(QString, expectedProtocol); QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode); @@ -380,9 +388,15 @@ void tst_QWebSocketServer::tst_protocols() QVERIFY(server.listen()); QWebSocketHandshakeOptions opt; + QNetworkRequest request(server.serverUrl()); + if (!headerProtocols.isEmpty()) { + QString protocols = headerProtocols.join(u','); + request.setRawHeader("Sec-WebSocket-Protocol", protocols.toUtf8()); + } opt.setSubprotocols(clientProtocols); + QWebSocket client; - client.open(server.serverUrl(), opt); + client.open(request, opt); QTRY_COMPARE(client.state(), QAbstractSocket::ConnectedState); QTRY_COMPARE(newConnectionSpy.size(), 1); @@ -392,7 +406,7 @@ void tst_QWebSocketServer::tst_protocols() QCOMPARE(client.subprotocol(), expectedProtocol); QCOMPARE(serverSocket->subprotocol(), expectedProtocol); - QCOMPARE(serverSocket->handshakeOptions().subprotocols(), clientProtocols); + QCOMPARE(serverSocket->handshakeOptions().subprotocols(), clientProtocols + headerProtocols); } void tst_QWebSocketServer::tst_preSharedKey() |