summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2025-04-15 16:12:52 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2025-04-15 16:12:52 +0300
commitf8553ff68bb4de66fea95b494cd0afaae45bff54 (patch)
tree5915bcdc9c921a178c7a845803d747ec0bc25ee2
parentac5ec123560bd8279e62091b55d129f0621f2481 (diff)
parentbad60add7091d5e48d03ee1f484800b5e3153896 (diff)
Merge tag 'v6.2.13-lts' into tqtc/lts-6.2-opensourcev6.2.13-lts-lgpl6.2
Qt 6.2.13-lts release Conflicts solved: dependencies.yaml Change-Id: Ib34a3d84f76abc0999456ff31c4e0a1e01cf8712
-rw-r--r--.cmake.conf2
-rw-r--r--.qmake.conf2
-rw-r--r--examples/oauth/redditclient/conanfile.txt2
-rw-r--r--examples/oauth/twittertimeline/conanfile.txt2
-rw-r--r--src/oauth/qabstractoauth.cpp15
-rw-r--r--src/oauth/qoauthhttpserverreplyhandler.cpp21
-rw-r--r--src/oauth/qoauthhttpserverreplyhandler_p.h3
-rw-r--r--tests/auto/oauthhttpserverreplyhandler/tst_oauthhttpserverreplyhandler.cpp27
8 files changed, 60 insertions, 14 deletions
diff --git a/.cmake.conf b/.cmake.conf
index 7733def..0fcb9b1 100644
--- a/.cmake.conf
+++ b/.cmake.conf
@@ -1,2 +1,2 @@
-set(QT_REPO_MODULE_VERSION "6.2.12")
+set(QT_REPO_MODULE_VERSION "6.2.13")
set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "")
diff --git a/.qmake.conf b/.qmake.conf
index d3a38c9..ae99e66 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -3,5 +3,5 @@ CONFIG += warning_clean
DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS
-MODULE_VERSION = 6.2.12
+MODULE_VERSION = 6.2.13
diff --git a/examples/oauth/redditclient/conanfile.txt b/examples/oauth/redditclient/conanfile.txt
index 2eb3a87..6db795e 100644
--- a/examples/oauth/redditclient/conanfile.txt
+++ b/examples/oauth/redditclient/conanfile.txt
@@ -1,5 +1,5 @@
[requires]
-qtnetworkauth/6.2.12@qt/everywhere
+qtnetworkauth/6.2.13@qt/everywhere
[generators]
virtualenv
diff --git a/examples/oauth/twittertimeline/conanfile.txt b/examples/oauth/twittertimeline/conanfile.txt
index 2eb3a87..6db795e 100644
--- a/examples/oauth/twittertimeline/conanfile.txt
+++ b/examples/oauth/twittertimeline/conanfile.txt
@@ -1,5 +1,5 @@
[requires]
-qtnetworkauth/6.2.12@qt/everywhere
+qtnetworkauth/6.2.13@qt/everywhere
[generators]
virtualenv
diff --git a/src/oauth/qabstractoauth.cpp b/src/oauth/qabstractoauth.cpp
index 172edc0..7819915 100644
--- a/src/oauth/qabstractoauth.cpp
+++ b/src/oauth/qabstractoauth.cpp
@@ -37,7 +37,6 @@
#include <QtCore/qurl.h>
#include <QtCore/qpair.h>
#include <QtCore/qstring.h>
-#include <QtCore/qdatetime.h>
#include <QtCore/qurlquery.h>
#include <QtCore/qjsondocument.h>
#include <QtCore/qmessageauthenticationcode.h>
@@ -46,6 +45,9 @@
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtNetwork/qnetworkreply.h>
+#include <QtCore/qrandom.h>
+#include <QtCore/private/qlocking_p.h>
+
#include <random>
Q_DECLARE_METATYPE(QAbstractOAuth::Error)
@@ -290,15 +292,19 @@ void QAbstractOAuthPrivate::setStatus(QAbstractOAuth::Status newStatus)
}
}
+static QBasicMutex prngMutex;
+Q_GLOBAL_STATIC_WITH_ARGS(std::mt19937, prng, (*QRandomGenerator::system()))
+
QByteArray QAbstractOAuthPrivate::generateRandomString(quint8 length)
{
- const char characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- static std::mt19937 randomEngine(QDateTime::currentDateTime().toMSecsSinceEpoch());
+ constexpr char characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
std::uniform_int_distribution<int> distribution(0, sizeof(characters) - 2);
QByteArray data;
data.reserve(length);
+ auto lock = qt_unique_lock(prngMutex);
for (quint8 i = 0; i < length; ++i)
- data.append(characters[distribution(randomEngine)]);
+ data.append(characters[distribution(*prng)]);
+ lock.unlock();
return data;
}
@@ -608,6 +614,7 @@ void QAbstractOAuth::resourceOwnerAuthorization(const QUrl &url, const QMultiMap
}
/*!
+ \threadsafe
Generates a random string which could be used as state or nonce.
The parameter \a length determines the size of the generated
string.
diff --git a/src/oauth/qoauthhttpserverreplyhandler.cpp b/src/oauth/qoauthhttpserverreplyhandler.cpp
index f1a555a..38256ce 100644
--- a/src/oauth/qoauthhttpserverreplyhandler.cpp
+++ b/src/oauth/qoauthhttpserverreplyhandler.cpp
@@ -65,6 +65,13 @@ QOAuthHttpServerReplyHandlerPrivate::~QOAuthHttpServerReplyHandlerPrivate()
httpServer.close();
}
+QString QOAuthHttpServerReplyHandlerPrivate::callback() const
+{
+ const QUrl url(QString::fromLatin1("http://127.0.0.1:%1/%2")
+ .arg(callbackPort).arg(path));
+ return url.toString(QUrl::EncodeDelimiters);
+}
+
void QOAuthHttpServerReplyHandlerPrivate::_q_clientConnected()
{
QTcpSocket *socket = httpServer.nextPendingConnection();
@@ -277,11 +284,7 @@ QOAuthHttpServerReplyHandler::~QOAuthHttpServerReplyHandler()
QString QOAuthHttpServerReplyHandler::callback() const
{
Q_D(const QOAuthHttpServerReplyHandler);
-
- Q_ASSERT(d->httpServer.isListening());
- const QUrl url(QString::fromLatin1("http://127.0.0.1:%1/%2")
- .arg(d->httpServer.serverPort()).arg(d->path));
- return url.toString(QUrl::EncodeDelimiters);
+ return d->callback();
}
QString QOAuthHttpServerReplyHandler::callbackPath() const
@@ -322,7 +325,13 @@ quint16 QOAuthHttpServerReplyHandler::port() const
bool QOAuthHttpServerReplyHandler::listen(const QHostAddress &address, quint16 port)
{
Q_D(QOAuthHttpServerReplyHandler);
- return d->httpServer.listen(address, port);
+ const bool success = d->httpServer.listen(address, port);
+
+ if (success) {
+ // Callback ('redirect_uri') value may be needed after this handler is closed
+ d->callbackPort = d->httpServer.serverPort();
+ }
+ return success;
}
void QOAuthHttpServerReplyHandler::close()
diff --git a/src/oauth/qoauthhttpserverreplyhandler_p.h b/src/oauth/qoauthhttpserverreplyhandler_p.h
index 5b78933..625d727 100644
--- a/src/oauth/qoauthhttpserverreplyhandler_p.h
+++ b/src/oauth/qoauthhttpserverreplyhandler_p.h
@@ -60,10 +60,13 @@ public:
explicit QOAuthHttpServerReplyHandlerPrivate(QOAuthHttpServerReplyHandler *p);
~QOAuthHttpServerReplyHandlerPrivate();
+ QString callback() const;
+
QTcpServer httpServer;
QString text;
QHostAddress listenAddress = QHostAddress::LocalHost;
QString path;
+ quint16 callbackPort = 0;
private:
void _q_clientConnected();
diff --git a/tests/auto/oauthhttpserverreplyhandler/tst_oauthhttpserverreplyhandler.cpp b/tests/auto/oauthhttpserverreplyhandler/tst_oauthhttpserverreplyhandler.cpp
index 2a762e9..5ea8084 100644
--- a/tests/auto/oauthhttpserverreplyhandler/tst_oauthhttpserverreplyhandler.cpp
+++ b/tests/auto/oauthhttpserverreplyhandler/tst_oauthhttpserverreplyhandler.cpp
@@ -40,6 +40,7 @@ class tst_QOAuthHttpServerReplyHandler : public QObject
private Q_SLOTS:
void callback();
+ void callbackCaching();
};
void tst_QOAuthHttpServerReplyHandler::callback()
@@ -71,5 +72,31 @@ void tst_QOAuthHttpServerReplyHandler::callback()
QCOMPARE(count, query.queryItems().count());
}
+void tst_QOAuthHttpServerReplyHandler::callbackCaching()
+{
+ QOAuthHttpServerReplyHandler replyHandler;
+ const auto callbackPath = QStringLiteral("/foo");
+ const auto callbackHost = QStringLiteral("127.0.0.1");
+
+ QVERIFY(replyHandler.isListening());
+ replyHandler.setCallbackPath(callbackPath);
+ QUrl callback = replyHandler.callback();
+ QCOMPARE(callback.path(), callbackPath);
+ QCOMPARE(callback.host(), callbackHost);
+
+ replyHandler.close();
+ QVERIFY(!replyHandler.isListening());
+ callback = replyHandler.callback();
+ // Should remain after close
+ QCOMPARE(callback.path(), callbackPath);
+ QCOMPARE(callback.host(), callbackHost);
+
+ replyHandler.listen();
+ QVERIFY(replyHandler.isListening());
+ callback = replyHandler.callback();
+ QCOMPARE(callback.path(), callbackPath);
+ QCOMPARE(callback.host(), callbackHost);
+}
+
QTEST_MAIN(tst_QOAuthHttpServerReplyHandler)
#include "tst_oauthhttpserverreplyhandler.moc"