Merge lp:~online-accounts/signon-plugin-oauth2/packaging into lp:signon-plugin-oauth2

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: no longer in the source branch.
Merged at revision: 74
Proposed branch: lp:~online-accounts/signon-plugin-oauth2/packaging
Merge into: lp:signon-plugin-oauth2
Diff against target: 342 lines (+170/-24)
7 files modified
debian/changelog (+9/-0)
src/base-plugin.cpp (+41/-21)
src/base-plugin.h (+6/-1)
src/oauth2plugin.cpp (+12/-1)
src/oauth2plugin.h (+2/-0)
tests/oauth2plugintest.cpp (+98/-1)
tests/oauth2plugintest.h (+2/-0)
To merge this branch: bzr merge lp:~online-accounts/signon-plugin-oauth2/packaging
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Online Accounts Pending
Review via email: mp+249846@code.launchpad.net

Commit message

Merge from upstream

  - Proceed with the normal authentication if an error occurs when using the
    RefreshToken (LP: #1420934)
  - Remove the unused "type" query parameters which breaks DropBox

Description of the change

Merge from upstream

  - Proceed with the normal authentication if an error occurs when using the
    RefreshToken (LP: #1420934)
  - Remove the unused "type" query parameters which breaks DropBox

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
72. By Alberto Mardegan

Remove dependency on signon-ui. Fixes: #1362640
Approved by: PS Jenkins bot, David Barth

73. By CI Train Bot Account

Releasing 0.21+15.04.20150319-0ubuntu1

74. By Alberto Mardegan

Merge from upstream

  - Proceed with the normal authentication if an error occurs when using the
    RefreshToken (LP: #1420934)
  - Remove the unused "type" query parameters which breaks DropBox
 Fixes: #1420934
Approved by: PS Jenkins bot

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-01-28 17:16:29 +0000
3+++ debian/changelog 2015-02-16 15:55:13 +0000
4@@ -1,3 +1,12 @@
5+signon-plugin-oauth2 (0.21+15.04.20150128-0ubuntu2) UNRELEASED; urgency=medium
6+
7+ * Merge from upstream
8+ - Proceed with the normal authentication if an error occurs when using the
9+ RefreshToken (LP: #1420934)
10+ - Remove the unused "type" query parameters which breaks DropBox
11+
12+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Mon, 16 Feb 2015 17:51:01 +0200
13+
14 signon-plugin-oauth2 (0.21+15.04.20150128-0ubuntu1) vivid; urgency=medium
15
16 [ Alberto Mardegan ]
17
18=== modified file 'src/base-plugin.cpp'
19--- src/base-plugin.cpp 2012-11-21 13:34:54 +0000
20+++ src/base-plugin.cpp 2015-02-16 15:55:13 +0000
21@@ -40,25 +40,39 @@
22
23 class BasePluginPrivate
24 {
25+ Q_DECLARE_PUBLIC(BasePlugin)
26+
27 public:
28- BasePluginPrivate();
29+ BasePluginPrivate(BasePlugin *q);
30 ~BasePluginPrivate();
31
32+ void disposeReply();
33+
34 QNetworkAccessManager *m_networkAccessManager;
35 QNetworkReply *m_reply;
36+ mutable BasePlugin *q_ptr;
37 }; //Private
38
39 } //namespace OAuth2PluginNS
40
41-BasePluginPrivate::BasePluginPrivate():
42+BasePluginPrivate::BasePluginPrivate(BasePlugin *q):
43 m_networkAccessManager(0),
44- m_reply(0)
45+ m_reply(0),
46+ q_ptr(q)
47 {
48 }
49
50 BasePluginPrivate::~BasePluginPrivate()
51 {
52+ disposeReply();
53+}
54+
55+void BasePluginPrivate::disposeReply()
56+{
57+ Q_Q(BasePlugin);
58+
59 if (m_reply != 0) {
60+ QObject::disconnect(m_reply, 0, q, 0);
61 m_reply->deleteLater();
62 m_reply = 0;
63 }
64@@ -66,7 +80,7 @@
65
66 BasePlugin::BasePlugin(QObject *parent):
67 QObject(parent),
68- d_ptr(new BasePluginPrivate())
69+ d_ptr(new BasePluginPrivate(this))
70 {
71 }
72
73@@ -113,7 +127,7 @@
74 connect(d->m_reply, SIGNAL(finished()),
75 this, SLOT(onPostFinished()));
76 connect(d->m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
77- this, SLOT(handleNetworkError(QNetworkReply::NetworkError)));
78+ this, SLOT(onNetworkError(QNetworkReply::NetworkError)));
79 connect(d->m_reply, SIGNAL(sslErrors(QList<QSslError>)),
80 this, SLOT(handleSslErrors(QList<QSslError>)));
81 }
82@@ -131,24 +145,34 @@
83 QNetworkReply *reply = (QNetworkReply*)sender();
84
85 TRACE() << "Finished signal received";
86+
87+ d->disposeReply();
88+
89 if (reply->error() != QNetworkReply::NoError) {
90- if (handleNetworkError(reply->error()))
91+ if (handleNetworkError(reply, reply->error()))
92 return;
93 }
94
95- if (d->m_reply) {
96- d->m_reply->deleteLater();
97- d->m_reply = 0;
98- }
99-
100 serverReply(reply);
101 }
102
103-bool BasePlugin::handleNetworkError(QNetworkReply::NetworkError err)
104-{
105- Q_D(BasePlugin);
106-
107- TRACE() << "error signal received:" << err;
108+void BasePlugin::onNetworkError(QNetworkReply::NetworkError err)
109+{
110+ Q_D(BasePlugin);
111+
112+ QNetworkReply *reply = (QNetworkReply*)sender();
113+
114+ TRACE() << "Network error:" << err;
115+
116+ handleNetworkError(reply, err);
117+ d->disposeReply();
118+}
119+
120+bool BasePlugin::handleNetworkError(QNetworkReply *reply,
121+ QNetworkReply::NetworkError err)
122+{
123+ Q_D(BasePlugin);
124+
125 /* Has been handled by handleSslErrors already */
126 if (err == QNetworkReply::SslHandshakeFailedError) {
127 return true;
128@@ -162,11 +186,7 @@
129 if (err <= QNetworkReply::UnknownNetworkError)
130 type = Error::NoConnection;
131 QString errorString = "";
132- if (d->m_reply) {
133- errorString = d->m_reply->errorString();
134- d->m_reply->deleteLater();
135- d->m_reply = 0;
136- }
137+ errorString = reply->errorString();
138 emit error(Error(type, errorString));
139 return true;
140 }
141
142=== modified file 'src/base-plugin.h'
143--- src/base-plugin.h 2012-07-20 06:29:22 +0000
144+++ src/base-plugin.h 2015-02-16 15:55:13 +0000
145@@ -64,10 +64,15 @@
146 const QByteArray &data);
147
148 virtual void serverReply(QNetworkReply *reply);
149+ /*!
150+ * Returns true if processing of the reply must stop.
151+ */
152+ virtual bool handleNetworkError(QNetworkReply *reply,
153+ QNetworkReply::NetworkError err);
154
155 protected Q_SLOTS:
156 void onPostFinished();
157- virtual bool handleNetworkError(QNetworkReply::NetworkError err);
158+ void onNetworkError(QNetworkReply::NetworkError err);
159 virtual void handleSslErrors(QList<QSslError> errorList);
160
161 Q_SIGNALS:
162
163=== modified file 'src/oauth2plugin.cpp'
164--- src/oauth2plugin.cpp 2015-01-28 10:14:40 +0000
165+++ src/oauth2plugin.cpp 2015-02-16 15:55:13 +0000
166@@ -140,7 +140,6 @@
167 if (!d->m_oauth2Data.Display().isEmpty()) {
168 url.addQueryItem(DISPLAY, d->m_oauth2Data.Display());
169 }
170- url.addQueryItem(QString("type"), d->m_mechanism);
171 if (!d->m_oauth2Data.Scope().empty()) {
172 QString separator = QLatin1String(" ");
173
174@@ -520,6 +519,18 @@
175 }
176 }
177
178+bool OAuth2Plugin::handleNetworkError(QNetworkReply *reply,
179+ QNetworkReply::NetworkError err)
180+{
181+ if (err >= QNetworkReply::ContentAccessDenied) {
182+ QByteArray replyContent = reply->readAll();
183+ TRACE() << replyContent;
184+ handleOAuth2Error(replyContent);
185+ return true;
186+ }
187+ return BasePlugin::handleNetworkError(reply, err);
188+}
189+
190 void OAuth2Plugin::handleOAuth2Error(const QByteArray &reply)
191 {
192 Q_D(OAuth2Plugin);
193
194=== modified file 'src/oauth2plugin.h'
195--- src/oauth2plugin.h 2015-01-28 10:14:40 +0000
196+++ src/oauth2plugin.h 2015-02-16 15:55:13 +0000
197@@ -65,6 +65,8 @@
198
199 protected:
200 void serverReply(QNetworkReply *);
201+ bool handleNetworkError(QNetworkReply *reply,
202+ QNetworkReply::NetworkError err);
203
204 private:
205 void sendOAuth2AuthRequest();
206
207=== modified file 'tests/oauth2plugintest.cpp'
208--- tests/oauth2plugintest.cpp 2015-01-28 10:14:40 +0000
209+++ tests/oauth2plugintest.cpp 2015-02-16 15:55:13 +0000
210@@ -95,8 +95,12 @@
211 m_offset(0)
212 {}
213
214- void setError(NetworkError errorCode, const QString &errorString) {
215+ void setError(NetworkError errorCode, const QString &errorString,
216+ int delay = -1) {
217 QNetworkReply::setError(errorCode, errorString);
218+ if (delay > 0) {
219+ QTimer::singleShot(delay, this, SLOT(fail()));
220+ }
221 }
222
223 void setRawHeader(const QByteArray &headerName, const QByteArray &value) {
224@@ -124,6 +128,7 @@
225
226 public Q_SLOTS:
227 void finish() { setFinished(true); Q_EMIT finished(); }
228+ void fail() { Q_EMIT error(error()); }
229
230 protected:
231 void abort() Q_DECL_OVERRIDE {}
232@@ -1358,6 +1363,98 @@
233 delete nam;
234 }
235
236+void OAuth2PluginTest::testRefreshTokenError_data()
237+{
238+ QTest::addColumn<int>("replyErrorCode");
239+ QTest::addColumn<int>("replyStatusCode");
240+ QTest::addColumn<QString>("replyContents");
241+ QTest::addColumn<int>("expectedError");
242+
243+ QTest::newRow("invalid grant, 400") <<
244+ int(QNetworkReply::ProtocolInvalidOperationError) <<
245+ int(400) <<
246+ "{ \"error\":\"invalid_grant\" }" <<
247+ int(-1);
248+
249+ QTest::newRow("invalid grant, 401") <<
250+ int(QNetworkReply::ContentAccessDenied) <<
251+ int(401) <<
252+ "{ \"error\":\"invalid_grant\" }" <<
253+ int(-1);
254+
255+ QTest::newRow("invalid grant, 401, no error signal") <<
256+ int(-1) <<
257+ int(401) <<
258+ "{ \"error\":\"invalid_grant\" }" <<
259+ int(-1);
260+
261+ QTest::newRow("temporary network failure") <<
262+ int(QNetworkReply::TemporaryNetworkFailureError) <<
263+ int(-1) <<
264+ "" <<
265+ int(Error::NoConnection);
266+}
267+
268+void OAuth2PluginTest::testRefreshTokenError()
269+{
270+ QFETCH(int, replyErrorCode);
271+ QFETCH(int, replyStatusCode);
272+ QFETCH(QString, replyContents);
273+ QFETCH(int, expectedError);
274+
275+ OAuth2PluginData data;
276+ data.setHost("localhost");
277+ data.setAuthPath("authorize");
278+ data.setTokenPath("access_token");
279+ data.setClientId("104660106251471");
280+ data.setClientSecret("fa28f40b5a1f8c1d5628963d880636fbkjkjkj");
281+ data.setRedirectUri("http://localhost/resp.html");
282+
283+ QVariantMap tokens;
284+ QVariantMap token;
285+ token.insert("Token", QLatin1String("tokenfromtest"));
286+ token.insert("timestamp", QDateTime::currentDateTime().toTime_t() - 10000);
287+ token.insert("Expiry", 1000);
288+ token.insert("refresh_token", QString("r3fr3sh"));
289+ tokens.insert(data.ClientId(), QVariant::fromValue(token));
290+ data.m_data.insert("Tokens", tokens);
291+
292+ SignOn::UiSessionData info;
293+
294+ QObject::connect(m_testPlugin, SIGNAL(result(const SignOn::SessionData&)),
295+ this, SLOT(result(const SignOn::SessionData&)),
296+ Qt::QueuedConnection);
297+ QObject::connect(m_testPlugin, SIGNAL(error(const SignOn::Error & )),
298+ this, SLOT(pluginError(const SignOn::Error &)),
299+ Qt::QueuedConnection);
300+ QObject::connect(m_testPlugin, SIGNAL(userActionRequired(const SignOn::UiSessionData&)),
301+ this, SLOT(uiRequest(const SignOn::UiSessionData&)),
302+ Qt::QueuedConnection);
303+ QTimer::singleShot(10*1000, &m_loop, SLOT(quit()));
304+
305+ TestNetworkAccessManager *nam = new TestNetworkAccessManager;
306+ m_testPlugin->m_networkAccessManager = nam;
307+ TestNetworkReply *reply = new TestNetworkReply(this);
308+ if (replyErrorCode >= 0) {
309+ reply->setError(QNetworkReply::NetworkError(replyErrorCode),
310+ "Dummy error", 5);
311+ }
312+ reply->setStatusCode(replyStatusCode);
313+ reply->setContentType("application/json");
314+ reply->setContent(replyContents.toUtf8());
315+ nam->setNextReply(reply);
316+
317+ m_testPlugin->process(data, QString("web_server"));
318+ m_loop.exec();
319+
320+ QCOMPARE(m_error.type(), expectedError);
321+ if (expectedError < 0) {
322+ QCOMPARE(m_uiResponse.UrlResponse(), QString("UI request received"));
323+ }
324+
325+ delete nam;
326+}
327+
328 void OAuth2PluginTest::testClientAuthentication_data()
329 {
330 QTest::addColumn<QString>("clientSecret");
331
332=== modified file 'tests/oauth2plugintest.h'
333--- tests/oauth2plugintest.h 2014-10-31 08:09:57 +0000
334+++ tests/oauth2plugintest.h 2015-02-16 15:55:13 +0000
335@@ -66,6 +66,8 @@
336 void testOAuth2Errors();
337 void testRefreshToken_data();
338 void testRefreshToken();
339+ void testRefreshTokenError_data();
340+ void testRefreshTokenError();
341 void testClientAuthentication_data();
342 void testClientAuthentication();
343

Subscribers

No one subscribed via source and target branches