summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-01-05 12:30:38 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2023-03-28 14:52:33 +0100
commit143e125e18dc9565d55c4548bf4c4dfba9500f6f (patch)
treef1ed09655c2b7df9266117f1261e1184aab3038a
parent99fdf11b808ab9b38239b04399a3fff21fa6ed35 (diff)
downloadqtwebsockets-143e125e18dc9565d55c4548bf4c4dfba9500f6f.tar.gz
Address issues with test introduced with 401 support
The testing with Connection: Close wasn't necessarily testing it since it was relying on not having a Content-Length, but this did not work out as intended. And fix excluded code (#if 0), relies on an update in qtbase. On macOS the ST backend was having trouble with how we handled shutdown of socket and re-use. Amends da30f70fea239f723f1d36b076bb3f5860f50ed9 Change-Id: I8a19387b911eec522690d597d863c5bc0786e8c8 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
index ae8e8d1..6881afb 100644
--- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp
@@ -1014,8 +1014,7 @@ public:
{
QByteArray payload = "HTTP/1.1 401 UNAUTHORIZED\r\n"
"WWW-Authenticate: Basic realm=shadow\r\n";
- const bool connectionClose = withBody && !withContentLength;
- if (connectionClose)
+ if (withConnectionClose)
payload.append("Connection: Close\r\n");
else if (withContentLength)
payload.append("Content-Length: " % QByteArray::number(body.size()) % "\r\n");
@@ -1025,7 +1024,7 @@ public:
payload.append(body);
socket->write(payload);
- if (connectionClose)
+ if (withConnectionClose)
socket->disconnectFromHost();
}
@@ -1057,6 +1056,7 @@ public:
bool withBody = false;
bool withContentLength = true;
+ bool withConnectionClose = false;
bool withEncryption = false;
#if QT_CONFIG(ssl)
QSslConfiguration configuration;
@@ -1071,6 +1071,7 @@ struct ServerScenario {
QByteArrayView label;
bool withContentLength = false;
bool withBody = false;
+ bool withConnectionClose = false;
bool withEncryption = false;
};
struct Credentials { QString username, password; };
@@ -1090,18 +1091,17 @@ void tst_QWebSocket::authenticationRequired_data()
QTest::addColumn<ClientScenario>("clientScenario");
// Need to test multiple server scenarios:
- // (note: Connection: Close is modelled as 'no Content-Length, with body')
// 1. Normal server (connection: keep-alive, Content-Length)
// 2. Older server (connection: close, Content-Length)
// 3. Even older server (connection: close, no Content-Length)
// 4. Strange server (connection: close, no Content-Length, no body)
// 5. Quiet server (connection: keep-alive, no Content-Length, no body)
ServerScenario serverScenarios[] = {
- { "normal-server", true, true, false },
- { "connection-close", true, true, false },
- { "connection-close-no-content-length", false, true, false },
- { "connection-close-no-content-length-no-body", false, false, false },
- { "keep-alive-no-content-length-no-body", false, false, false },
+ { "normal-server", true, true, false, false },
+ { "connection-close", true, true, true, false },
+ { "connection-close-no-content-length", false, true, true, false },
+ { "connection-close-no-content-length-no-body", false, false, true, false },
+ { "keep-alive-no-content-length-no-body", false, false, false, false },
};
// And some client scenarios
@@ -1126,8 +1126,11 @@ void tst_QWebSocket::authenticationRequired_data()
<< server << client;
}
}
-#if 0 //QT_CONFIG(ssl)
- // FIXME: Consider TLS-shutdown different from Schannel.
+#if QT_CONFIG(ssl)
+ if (!QSslSocket::supportsSsl()) {
+ qDebug("Skipping the SslServer part of this test because proper TLS is not supported.");
+ return;
+ }
// And double that, but now with TLS
for (auto &server : serverScenarios) {
server.withEncryption = true;
@@ -1168,6 +1171,7 @@ void tst_QWebSocket::authenticationRequired()
AuthServer server;
server.withBody = serverScenario.withBody;
server.withContentLength = serverScenario.withContentLength;
+ server.withConnectionClose = serverScenario.withConnectionClose;
server.withEncryption = serverScenario.withEncryption;
#if QT_CONFIG(ssl)
if (serverScenario.withEncryption) {