summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-04-05 12:08:32 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-04-05 12:08:32 +0200
commit32912fdcf35bc9f9e14a65d9e8019798fb7bb316 (patch)
tree4229755e052c74b2bbd7b1613d88c700a2c770c2
parent6b8ac5e36f5f0eaabb2fdc6720394a77b6264954 (diff)
parent88e0b0fc7e828533fa387f7a367e94b81674e3b1 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
-rw-r--r--src/oauth/qabstractoauth.cpp8
-rw-r--r--src/oauth/qoauth1signature.cpp3
-rw-r--r--src/oauth/qoauth2authorizationcodeflow.cpp3
-rw-r--r--tests/auto/oauth2/tst_oauth2.cpp75
-rw-r--r--tests/auto/shared/webserver.h1
5 files changed, 80 insertions, 10 deletions
diff --git a/src/oauth/qabstractoauth.cpp b/src/oauth/qabstractoauth.cpp
index 58579ec..5326292 100644
--- a/src/oauth/qabstractoauth.cpp
+++ b/src/oauth/qabstractoauth.cpp
@@ -520,10 +520,10 @@ QAbstractOAuth::ModifyParametersFunction QAbstractOAuth::modifyParametersFunctio
}
/*!
- Sets the parameter-modification function. This function is used
- to customize the parameters sent to the server during a specified
- authorization stage. The number of calls to this function
- depends on the flow used during the authentication.
+ Sets the parameter-modification function \a modifyParametersFunction.
+ This function is used to customize the parameters sent to the server
+ during a specified authorization stage. The number of calls to this
+ function depends on the flow used during the authentication.
\sa modifyParametersFunction(), ModifyParametersFunction, Stage
*/
void QAbstractOAuth::setModifyParametersFunction(
diff --git a/src/oauth/qoauth1signature.cpp b/src/oauth/qoauth1signature.cpp
index 6ad38b2..54d97c6 100644
--- a/src/oauth/qoauth1signature.cpp
+++ b/src/oauth/qoauth1signature.cpp
@@ -408,9 +408,6 @@ void QOAuth1Signature::swap(QOAuth1Signature &other)
qSwap(d, other.d);
}
-/*!
- Copy-assignment operator.
-*/
QOAuth1Signature &QOAuth1Signature::operator=(const QOAuth1Signature &other)
{
if (d != other.d) {
diff --git a/src/oauth/qoauth2authorizationcodeflow.cpp b/src/oauth/qoauth2authorizationcodeflow.cpp
index 3bc94e6..4c23c97 100644
--- a/src/oauth/qoauth2authorizationcodeflow.cpp
+++ b/src/oauth/qoauth2authorizationcodeflow.cpp
@@ -332,6 +332,9 @@ void QOAuth2AuthorizationCodeFlow::refreshAccessToken()
connect(reply, &QNetworkReply::finished,
[handler, reply]() { handler->networkReplyFinished(reply); });
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
+ QObjectPrivate::connect(d->replyHandler.data(), &QAbstractOAuthReplyHandler::tokensReceived, d,
+ &QOAuth2AuthorizationCodeFlowPrivate::_q_accessTokenRequestFinished,
+ Qt::UniqueConnection);
QObjectPrivate::connect(d->networkAccessManager(),
&QNetworkAccessManager::authenticationRequired,
d, &QOAuth2AuthorizationCodeFlowPrivate::_q_authenticate,
diff --git a/tests/auto/oauth2/tst_oauth2.cpp b/tests/auto/oauth2/tst_oauth2.cpp
index 826be06..f3a30a9 100644
--- a/tests/auto/oauth2/tst_oauth2.cpp
+++ b/tests/auto/oauth2/tst_oauth2.cpp
@@ -39,6 +39,8 @@ class tst_OAuth2 : public QObject
private Q_SLOTS:
void getToken();
+ void refreshToken();
+ void getAndRefreshToken();
};
struct ReplyHandler : QAbstractOAuthReplyHandler
@@ -80,11 +82,11 @@ void tst_OAuth2::getToken()
QOAuth2AuthorizationCodeFlow oauth2;
oauth2.setAuthorizationUrl(webServer.url(QLatin1String("authorization")));
oauth2.setAccessTokenUrl(webServer.url(QLatin1String("accessToken")));
- auto replyHandler = new ReplyHandler;
- oauth2.setReplyHandler(replyHandler);
+ ReplyHandler replyHandler;
+ oauth2.setReplyHandler(&replyHandler);
connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [&](const QUrl &url) {
const QUrlQuery query(url.query());
- replyHandler->emitCallbackReceived(QVariantMap {
+ replyHandler.emitCallbackReceived(QVariantMap {
{ QLatin1String("code"), QLatin1String("test") },
{ QLatin1String("state"),
query.queryItemValue(QLatin1String("state")) }
@@ -96,5 +98,72 @@ void tst_OAuth2::getToken()
QCOMPARE(oauth2.token(), QLatin1String("token"));
}
+void tst_OAuth2::refreshToken()
+{
+ WebServer webServer([](const WebServer::HttpRequest &request, QTcpSocket *socket) {
+ if (request.url.path() == QLatin1String("/accessToken")) {
+ const QString text = "access_token=token&token_type=bearer";
+ const QByteArray replyMessage {
+ "HTTP/1.0 200 OK\r\n"
+ "Content-Type: application/x-www-form-urlencoded; charset=\"utf-8\"\r\n"
+ "Content-Length: " + QByteArray::number(text.size()) + "\r\n\r\n"
+ + text.toUtf8()
+ };
+ socket->write(replyMessage);
+ }
+ });
+ QOAuth2AuthorizationCodeFlow oauth2;
+ oauth2.setAccessTokenUrl(webServer.url(QLatin1String("accessToken")));
+ ReplyHandler replyHandler;
+ oauth2.setReplyHandler(&replyHandler);
+ oauth2.setRefreshToken(QLatin1String("refresh_token"));
+ QSignalSpy grantedSpy(&oauth2, &QOAuth2AuthorizationCodeFlow::granted);
+ oauth2.refreshAccessToken();
+ QTRY_COMPARE(grantedSpy.count(), 1);
+ QCOMPARE(oauth2.token(), QLatin1String("token"));
+}
+
+void tst_OAuth2::getAndRefreshToken()
+{
+ // In this test we use the grant_type as a token to be able to
+ // identify the token request from the token refresh.
+ WebServer webServer([](const WebServer::HttpRequest &request, QTcpSocket *socket) {
+ if (request.url.path() == QLatin1String("/accessToken")) {
+ const QUrlQuery query(request.body);
+ const QString format = QStringLiteral("access_token=%1&token_type=bearer&expires_in=1&"
+ "refresh_token=refresh_token");
+ const auto text = format.arg(query.queryItemValue(QLatin1String("grant_type")));
+ const QByteArray replyMessage {
+ "HTTP/1.0 200 OK\r\n"
+ "Content-Type: application/x-www-form-urlencoded; charset=\"utf-8\"\r\n"
+ "Content-Length: " + QByteArray::number(text.size()) + "\r\n\r\n"
+ + text.toUtf8()
+ };
+ socket->write(replyMessage);
+ }
+ });
+ QOAuth2AuthorizationCodeFlow oauth2;
+ oauth2.setAuthorizationUrl(webServer.url(QLatin1String("authorization")));
+ oauth2.setAccessTokenUrl(webServer.url(QLatin1String("accessToken")));
+ ReplyHandler replyHandler;
+ oauth2.setReplyHandler(&replyHandler);
+ connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [&](const QUrl &url) {
+ const QUrlQuery query(url.query());
+ replyHandler.emitCallbackReceived(QVariantMap {
+ { QLatin1String("code"), QLatin1String("test") },
+ { QLatin1String("state"),
+ query.queryItemValue(QLatin1String("state")) }
+ });
+ });
+ QSignalSpy grantedSpy(&oauth2, &QOAuth2AuthorizationCodeFlow::granted);
+ oauth2.grant();
+ QTRY_COMPARE(grantedSpy.count(), 1);
+ QCOMPARE(oauth2.token(), QLatin1String("authorization_code"));
+ grantedSpy.clear();
+ oauth2.refreshAccessToken();
+ QTRY_COMPARE(grantedSpy.count(), 1);
+ QCOMPARE(oauth2.token(), QLatin1String("refresh_token"));
+}
+
QTEST_MAIN(tst_OAuth2)
#include "tst_oauth2.moc"
diff --git a/tests/auto/shared/webserver.h b/tests/auto/shared/webserver.h
index b28a0e5..63ba001 100644
--- a/tests/auto/shared/webserver.h
+++ b/tests/auto/shared/webserver.h
@@ -34,6 +34,7 @@
#include <cctype>
#include <QtCore/qcoreapplication.h>
#include <QtNetwork/qtcpserver.h>
+#include <QTcpSocket>
class WebServer : public QTcpServer
{