Merge lp:~mardy/ubuntu-system-settings-online-accounts/remove-snap-decision into lp:~online-accounts/ubuntu-system-settings-online-accounts/master

Proposed by Alberto Mardegan
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 221
Merged at revision: 221
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/remove-snap-decision
Merge into: lp:~online-accounts/ubuntu-system-settings-online-accounts/master
Diff against target: 522 lines (+23/-325)
7 files modified
online-accounts-service/request-manager.cpp (+5/-3)
online-accounts-service/ui-proxy.cpp (+9/-9)
online-accounts-ui/globals.h (+2/-0)
online-accounts-ui/online-accounts-ui.pro (+0/-2)
online-accounts-ui/signonui-request.cpp (+7/-140)
tests/online-accounts-ui/tst_signonui_request.cpp (+0/-168)
tests/online-accounts-ui/tst_signonui_request.pro (+0/-3)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/remove-snap-decision
Reviewer Review Type Date Requested Status
David Barth (community) Approve
Review via email: mp+245568@code.launchpad.net

Commit message

Remove snap decision fallback

Description of the change

Remove snap decision fallback

To post a comment you must log in.
Revision history for this message
David Barth (dbarth) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'online-accounts-service/request-manager.cpp'
2--- online-accounts-service/request-manager.cpp 2014-10-13 10:48:54 +0000
3+++ online-accounts-service/request-manager.cpp 2015-01-05 14:26:48 +0000
4@@ -117,14 +117,16 @@
5 return; // Nothing to do
6 }
7
8+ QObject::connect(request, SIGNAL(completed()),
9+ this, SLOT(onRequestCompleted()));
10+
11 UiProxy *proxy = new UiProxy(request->clientPid(), this);
12 if (Q_UNLIKELY(!proxy->init())) {
13 qWarning() << "UiProxy initialization failed!";
14- runQueue(queue);
15+ request->fail(OAU_ERROR_PROMPT_SESSION,
16+ "Could not create a prompt session");
17 return;
18 }
19- QObject::connect(request, SIGNAL(completed()),
20- this, SLOT(onRequestCompleted()));
21 QObject::connect(proxy, SIGNAL(finished()),
22 this, SLOT(onProxyFinished()));
23 m_proxies.append(proxy);
24
25=== modified file 'online-accounts-service/ui-proxy.cpp'
26--- online-accounts-service/ui-proxy.cpp 2014-11-21 13:50:15 +0000
27+++ online-accounts-service/ui-proxy.cpp 2015-01-05 14:26:48 +0000
28@@ -53,7 +53,7 @@
29 bool init();
30 void sendOperation(const QVariantMap &data);
31 void sendRequest(int requestId, Request *request);
32- void setupPromptSession();
33+ bool setupPromptSession();
34
35 private Q_SLOTS:
36 void onNewConnection();
37@@ -190,28 +190,27 @@
38 return m_server.listen(socketDir.filePath(uniqueName));
39 }
40
41-void UiProxyPrivate::setupPromptSession()
42+bool UiProxyPrivate::setupPromptSession()
43 {
44 Q_Q(UiProxy);
45
46- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
47- if (!env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) return;
48-
49 PromptSessionP session =
50 MirHelper::instance()->createPromptSession(m_clientPid);
51- if (!session) return;
52+ if (!session) return false;
53
54 QString mirSocket = session->requestSocket();
55 if (mirSocket.isEmpty()) {
56- return;
57+ return false;
58 }
59
60 m_promptSession = session;
61 QObject::connect(m_promptSession.data(), SIGNAL(finished()),
62 q, SIGNAL(finished()));
63
64+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
65 env.insert("MIR_SOCKET", mirSocket);
66 m_process.setProcessEnvironment(env);
67+ return true;
68 }
69
70 bool UiProxyPrivate::init()
71@@ -235,8 +234,9 @@
72 arguments.append("--socket");
73 arguments.append(m_server.fullServerName());
74
75- if (m_clientPid) {
76- setupPromptSession();
77+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
78+ if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
79+ if (!setupPromptSession()) return false;
80 }
81
82 m_process.start(processName, arguments);
83
84=== modified file 'online-accounts-ui/globals.h'
85--- online-accounts-ui/globals.h 2014-09-15 12:16:50 +0000
86+++ online-accounts-ui/globals.h 2015-01-05 14:26:48 +0000
87@@ -40,6 +40,8 @@
88 QStringLiteral(OAU_ERROR_PREFIX "InvalidParameters")
89 #define OAU_ERROR_INVALID_APPLICATION \
90 QStringLiteral(OAU_ERROR_PREFIX "InvalidApplication")
91+#define OAU_ERROR_PROMPT_SESSION \
92+ QStringLiteral(OAU_ERROR_PREFIX "NoPromptSession")
93
94 /* SignOnUi service */
95 #define SIGNONUI_SERVICE_NAME QStringLiteral("com.nokia.singlesignonui")
96
97=== modified file 'online-accounts-ui/online-accounts-ui.pro'
98--- online-accounts-ui/online-accounts-ui.pro 2014-10-31 12:05:37 +0000
99+++ online-accounts-ui/online-accounts-ui.pro 2015-01-05 14:26:48 +0000
100@@ -52,7 +52,6 @@
101 i18n.cpp \
102 ipc.cpp \
103 main.cpp \
104- notification.cpp \
105 panel-request.cpp \
106 provider-request.cpp \
107 request.cpp \
108@@ -67,7 +66,6 @@
109 dialog-request.h \
110 i18n.h \
111 ipc.h \
112- notification.h \
113 panel-request.h \
114 provider-request.h \
115 request.h \
116
117=== modified file 'online-accounts-ui/signonui-request.cpp'
118--- online-accounts-ui/signonui-request.cpp 2014-10-14 09:05:52 +0000
119+++ online-accounts-ui/signonui-request.cpp 2015-01-05 14:26:48 +0000
120@@ -24,13 +24,7 @@
121 #include "debug.h"
122 #include "dialog-request.h"
123 #include "globals.h"
124-#include "notification.h"
125
126-#include <Accounts/Account>
127-#include <Accounts/Application>
128-#include <Accounts/Provider>
129-#include <OnlineAccountsPlugin/account-manager.h>
130-#include <OnlineAccountsPlugin/application-manager.h>
131 #include <OnlineAccountsPlugin/request-handler.h>
132 #include <QDBusArgument>
133 #include <QPointer>
134@@ -52,19 +46,9 @@
135 ~RequestPrivate();
136
137 private:
138- void setWindow(QWindow *window);
139- Accounts::Account *findAccount();
140-
141-private Q_SLOTS:
142- void onActionInvoked(const QString &action);
143- void onNotificationClosed();
144-
145-private:
146 mutable Request *q_ptr;
147 QVariantMap m_clientData;
148 QPointer<RequestHandler> m_handler;
149- OnlineAccountsUi::Notification *m_notification;
150- QWindow *m_window;
151 };
152
153 } // namespace
154@@ -72,9 +56,7 @@
155 RequestPrivate::RequestPrivate(Request *request):
156 QObject(request),
157 q_ptr(request),
158- m_handler(0),
159- m_notification(0),
160- m_window(0)
161+ m_handler(0)
162 {
163 const QVariantMap &parameters = request->parameters();
164 if (parameters.contains(SSOUI_KEY_CLIENT_DATA)) {
165@@ -87,112 +69,6 @@
166
167 RequestPrivate::~RequestPrivate()
168 {
169- delete m_notification;
170- m_notification = 0;
171-}
172-
173-void RequestPrivate::setWindow(QWindow *window)
174-{
175- Q_Q(Request);
176-
177- /* Don't show the window yet: the user must be presented with a
178- * snap-decision, and we'll show the window only if he decides to
179- * authenticate. */
180- Accounts::Account *account = findAccount();
181- if (Q_UNLIKELY(!account)) {
182- QVariantMap result;
183- result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
184- q->setResult(result);
185- return;
186- }
187-
188- OnlineAccountsUi::ApplicationManager *appManager =
189- OnlineAccountsUi::ApplicationManager::instance();
190- Accounts::Application application =
191- appManager->applicationFromProfile(q->clientApparmorProfile());
192-
193- OnlineAccountsUi::AccountManager *accountManager =
194- OnlineAccountsUi::AccountManager::instance();
195- Accounts::Provider provider =
196- accountManager->provider(account->providerName());
197-
198- QString summary =
199- QString("Please authorize %1 to access your %2 account %3").
200- arg(application.isValid() ? application.displayName() : "Ubuntu").
201- arg(provider.displayName()).
202- arg(account->displayName());
203- m_notification =
204- new OnlineAccountsUi::Notification("Authentication request", summary);
205- m_notification->addAction("cancel", "Cancel");
206- m_notification->addAction("continue", "Authorize...");
207- m_notification->setSnapDecision(true);
208- QObject::connect(m_notification, SIGNAL(actionInvoked(const QString &)),
209- this, SLOT(onActionInvoked(const QString &)));
210- QObject::connect(m_notification, SIGNAL(closed()),
211- this, SLOT(onNotificationClosed()));
212- m_notification->show();
213- m_window = window;
214-}
215-
216-Accounts::Account *RequestPrivate::findAccount()
217-{
218- Q_Q(Request);
219-
220- uint identity = q->identity();
221- if (identity == 0)
222- return 0;
223-
224- /* Find the account using this identity.
225- * FIXME: there might be more than one!
226- */
227- OnlineAccountsUi::AccountManager *manager =
228- OnlineAccountsUi::AccountManager::instance();
229- Q_FOREACH(Accounts::AccountId accountId, manager->accountList()) {
230- Accounts::Account *account = manager->account(accountId);
231- if (account == 0) continue;
232-
233- QVariant value(QVariant::UInt);
234- if (account->value("CredentialsId", value) != Accounts::NONE &&
235- value.toUInt() == identity) {
236- return account;
237- }
238- }
239-
240- // Not found
241- return 0;
242-}
243-
244-void RequestPrivate::onActionInvoked(const QString &action)
245-{
246- Q_Q(Request);
247-
248- DEBUG() << action;
249-
250- QObject::disconnect(m_notification, 0, this, 0);
251- m_notification->deleteLater();
252- m_notification = 0;
253-
254- if (action == QStringLiteral("continue")) {
255- q->setWindow(m_window);
256- } else {
257- q->cancel();
258- }
259-}
260-
261-void RequestPrivate::onNotificationClosed()
262-{
263- Q_Q(Request);
264-
265- DEBUG();
266-
267- /* setResult() should have been called by onActionInvoked(), but calling it
268- * twice won't harm because only the first invocation counts. */
269- QVariantMap result;
270- result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
271- q->setResult(result);
272-
273- m_notification->deleteLater();
274- m_notification = 0;
275 }
276
277 #ifndef NO_REQUEST_FACTORY
278@@ -266,22 +142,13 @@
279 {
280 Q_D(Request);
281
282- /* While a notification is shown, ignore any further calls to
283- * setWindow(). */
284- if (d->m_notification) return;
285-
286- /* The first time that this method is called, we handle it by presenting a
287- * snap decision to the user.
288- * Then, if this is called again with the same QWindow, it means that the
289- * snap decision was accepted, and we show the window.
290- */
291- if (window == d->m_window ||
292- /* If we are part of a prompt session, just show the window */
293- !qgetenv("MIR_SOCKET").isEmpty()) {
294+ /* Show the window only if we are in a prompt session */
295+ if (qgetenv("MIR_SOCKET").isEmpty()) {
296+ QVariantMap result;
297+ result[SSOUI_KEY_ERROR] = SignOn::QUERY_ERROR_FORBIDDEN;
298+ setResult(result);
299+ } else {
300 OnlineAccountsUi::Request::setWindow(window);
301- d->m_window = 0;
302- } else {
303- d->setWindow(window);
304 }
305 }
306
307
308=== modified file 'tests/online-accounts-ui/tst_signonui_request.cpp'
309--- tests/online-accounts-ui/tst_signonui_request.cpp 2014-10-09 12:24:45 +0000
310+++ tests/online-accounts-ui/tst_signonui_request.cpp 2015-01-05 14:26:48 +0000
311@@ -20,7 +20,6 @@
312
313 #include "globals.h"
314 #include "signonui-request.h"
315-#include "mock/notification-mock.h"
316 #include "mock/request-mock.h"
317 #include "mock/ui-server-mock.h"
318
319@@ -68,8 +67,6 @@
320 void testParameters_data();
321 void testParameters();
322 void testHandler();
323- void testSnapDecision_data();
324- void testSnapDecision();
325
326 private:
327 bool mustCreateAccount(uint credentialsId) { return credentialsId > 10; }
328@@ -167,171 +164,6 @@
329 delete handler;
330 }
331
332-void SignonuiRequestTest::testSnapDecision_data()
333-{
334- QTest::addColumn<uint>("credentialsId");
335- QTest::addColumn<QString>("accountName");
336- QTest::addColumn<QString>("clientProfile");
337- QTest::addColumn<QString>("applicationName");
338- QTest::addColumn<bool>("mustAccept");
339- QTest::addColumn<QVariantMap>("result");
340-
341- QVariantMap acceptedResult;
342- acceptedResult.insert("some key", QString("some value"));
343-
344- QVariantMap declinedResult;
345- declinedResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_CANCELED);
346-
347- QVariantMap errorResult;
348- errorResult.insert(SSOUI_KEY_ERROR, SignOn::QUERY_ERROR_FORBIDDEN);
349-
350- QTest::newRow("no account") <<
351- uint(0) <<
352- "tom@example.com" <<
353- "com.ubuntu.tests_application_0.3" <<
354- QString() <<
355- false <<
356- errorResult;
357-
358- QTest::newRow("invalid account") <<
359- uint(1) <<
360- "tom@example.com" <<
361- "com.ubuntu.tests_application_0.3" <<
362- QString() <<
363- false <<
364- errorResult;
365-
366- QTest::newRow("valid application, accepted") <<
367- uint(14231) <<
368- "tom@example.com" <<
369- "com.ubuntu.tests_application_0.3" <<
370- "Easy Mailer" <<
371- true <<
372- acceptedResult;
373-
374- QTest::newRow("valid application, declined") <<
375- uint(14231) <<
376- "tom@example.com" <<
377- "com.ubuntu.tests_application_0.3" <<
378- "Easy Mailer" <<
379- false <<
380- declinedResult;
381-
382- QTest::newRow("unconfined application, accepted") <<
383- uint(14235) <<
384- "tom@example.com" <<
385- "unconfined" <<
386- "Ubuntu" <<
387- true <<
388- acceptedResult;
389-
390- QTest::newRow("unconfined application, declined") <<
391- uint(14235) <<
392- "tom@example.com" <<
393- "unconfined" <<
394- "Ubuntu" <<
395- false <<
396- declinedResult;
397-}
398-
399-void SignonuiRequestTest::testSnapDecision()
400-{
401- QString providerId("cool");
402- QFETCH(uint, credentialsId);
403- QFETCH(QString, accountName);
404- QFETCH(QString, clientProfile);
405- QFETCH(QString, applicationName);
406- QFETCH(bool, mustAccept);
407- QFETCH(QVariantMap, result);
408-
409- // First, create an account
410- Accounts::Manager *manager = new Accounts::Manager(this);
411- Accounts::Provider provider = manager->provider(providerId);
412- QVERIFY(provider.isValid());
413- if (mustCreateAccount(credentialsId)) {
414- Accounts::Account *account = manager->createAccount(providerId);
415- QVERIFY(account != 0);
416- account->setEnabled(true);
417- account->setDisplayName(accountName);
418- account->setCredentialsId(credentialsId);
419- account->syncAndBlock();
420- }
421-
422- /* Then, create a request referring to the same credentials ID of the
423- * created account. */
424- QVariantMap parameters;
425- parameters.insert(SSOUI_KEY_IDENTITY, credentialsId);
426- parameters.insert(SSOUI_KEY_METHOD, "funnyMethod");
427- parameters.insert(SSOUI_KEY_MECHANISM, "funnyMechanism");
428- TestRequest request(clientProfile, parameters);
429- OnlineAccountsUi::RequestPrivate *mockRequest =
430- OnlineAccountsUi::RequestPrivate::mocked(&request);
431- QSignalSpy failCalled(mockRequest,
432- SIGNAL(failCalled(const QString&, const QString&)));
433- QSignalSpy setResultCalled(mockRequest,
434- SIGNAL(setResultCalled(const QVariantMap &)));
435- request.start();
436-
437- /* Request to show a window; a snap decision should appear instead */
438- QWindow *window = new QWindow;
439- QSignalSpy setWindowCalled(mockRequest,
440- SIGNAL(setWindowCalled(QWindow*)));
441- request.setWindow(window);
442- QCOMPARE(setWindowCalled.count(), 0);
443- if (mustCreateAccount(credentialsId)) {
444- QCOMPARE(NotificationPrivate::allNotifications.count(), 1);
445- } else {
446- /* If the account is not found, no notification should appear, and an
447- * error returned to the app */
448- QCOMPARE(NotificationPrivate::allNotifications.count(), 0);
449- QCOMPARE(setResultCalled.count(), 1);
450- QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
451- return;
452- }
453-
454- /* Inspect the snap decision contents */
455- Notification *notification =
456- NotificationPrivate::allNotifications.first();
457- NotificationPrivate *mockNotification =
458- NotificationPrivate::mocked(notification);
459- QCOMPARE(mockNotification->m_summary, QString("Authentication request"));
460- QCOMPARE(mockNotification->m_body,
461- QString("Please authorize %1 to access your %2 account %3").
462- arg(applicationName).arg(provider.displayName()).arg(accountName));
463- QVERIFY(mockNotification->m_isSnapDecision);
464-
465- /* Invoke the action on the snap decision */
466- QString action = mustAccept ? "continue" : "cancel";
467- QSignalSpy actionInvoked(notification,
468- SIGNAL(actionInvoked(const QString &)));
469- mockNotification->invokeAction(action);
470- QCOMPARE(actionInvoked.count(), 1);
471- QCOMPARE(actionInvoked.at(0).at(0).toString(), action);
472-
473- /* Here we iterate the main loop because the notification object is
474- * destroyed with deleteLater() */
475- QTest::qWait(5);
476-
477- if (mustAccept) {
478- QCOMPARE(setWindowCalled.count(), 1);
479- QCOMPARE(setWindowCalled.at(0).at(0), QVariant::fromValue(window));
480- QCOMPARE(failCalled.count(), 0);
481- QCOMPARE(setResultCalled.count(), 0);
482-
483- /* deliver the result */
484- request.sendResult(result);
485- QCOMPARE(setResultCalled.count(), 1);
486- QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
487- } else {
488- QCOMPARE(setWindowCalled.count(), 0);
489- QCOMPARE(failCalled.count(), 0);
490- QCOMPARE(setResultCalled.count(), 1);
491- QCOMPARE(setResultCalled.at(0).at(0).toMap(), result);
492- }
493- delete window;
494- delete manager;
495-}
496-
497 QTEST_MAIN(SignonuiRequestTest);
498
499 #include "tst_signonui_request.moc"
500
501=== modified file 'tests/online-accounts-ui/tst_signonui_request.pro'
502--- tests/online-accounts-ui/tst_signonui_request.pro 2014-10-14 11:19:19 +0000
503+++ tests/online-accounts-ui/tst_signonui_request.pro 2015-01-05 14:26:48 +0000
504@@ -27,18 +27,15 @@
505 SOURCES += \
506 $${ONLINE_ACCOUNTS_UI_DIR}/debug.cpp \
507 $${ONLINE_ACCOUNTS_UI_DIR}/signonui-request.cpp \
508- mock/notification-mock.cpp \
509 mock/request-mock.cpp \
510 mock/qwindow.cpp \
511 mock/ui-server-mock.cpp \
512 tst_signonui_request.cpp
513
514 HEADERS += \
515- $${ONLINE_ACCOUNTS_UI_DIR}/notification.h \
516 $${ONLINE_ACCOUNTS_UI_DIR}/request.h \
517 $${ONLINE_ACCOUNTS_UI_DIR}/signonui-request.h \
518 $${ONLINE_ACCOUNTS_UI_DIR}/ui-server.h \
519- mock/notification-mock.h \
520 mock/request-mock.h \
521 mock/ui-server-mock.h \
522 window-watcher.h

Subscribers

People subscribed via source and target branches