Merge lp:~mardy/ubuntu-system-settings-online-accounts/lp1420847 into lp:~online-accounts/ubuntu-system-settings-online-accounts/master

Proposed by Alberto Mardegan
Status: Merged
Merged at revision: 231
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/lp1420847
Merge into: lp:~online-accounts/ubuntu-system-settings-online-accounts/master
Diff against target: 165 lines (+59/-17)
5 files modified
online-accounts-service/mir-helper-stub.cpp (+9/-0)
online-accounts-service/mir-helper.h (+2/-0)
online-accounts-service/ui-proxy.cpp (+8/-17)
tests/online-accounts-service/tst_ui_proxy.cpp (+39/-0)
tests/online-accounts-service/tst_ui_proxy.pro (+1/-0)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/lp1420847
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
Review via email: mp+249842@code.launchpad.net

Commit message

Fail initialization if trust session cannot be setup.

Description of the change

Fail initialization if trust session cannot be setup.

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Needs Information
Revision history for this message
Alberto Mardegan (mardy) :
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'online-accounts-service/mir-helper-stub.cpp'
--- online-accounts-service/mir-helper-stub.cpp 2014-11-25 13:34:16 +0000
+++ online-accounts-service/mir-helper-stub.cpp 2015-02-16 15:47:16 +0000
@@ -40,7 +40,11 @@
4040
41QString PromptSession::requestSocket()41QString PromptSession::requestSocket()
42{42{
43#ifdef BUILDING_TESTS
44 return QString::fromUtf8(qgetenv("TEST_MIR_HELPER_SOCKET"));
45#else
43 return QString();46 return QString();
47#endif
44}48}
4549
46MirHelper::MirHelper(QObject *parent):50MirHelper::MirHelper(QObject *parent):
@@ -65,5 +69,10 @@
65PromptSessionP MirHelper::createPromptSession(pid_t initiatorPid)69PromptSessionP MirHelper::createPromptSession(pid_t initiatorPid)
66{70{
67 Q_UNUSED(initiatorPid);71 Q_UNUSED(initiatorPid);
72#ifdef BUILDING_TESTS
73 return qgetenv("TEST_MIR_HELPER_FAIL_CREATE").isEmpty() ?
74 PromptSessionP(new PromptSession(0)) : PromptSessionP();
75#else
68 return PromptSessionP();76 return PromptSessionP();
77#endif
69}78}
7079
=== modified file 'online-accounts-service/mir-helper.h'
--- online-accounts-service/mir-helper.h 2014-11-21 13:50:15 +0000
+++ online-accounts-service/mir-helper.h 2015-02-16 15:47:16 +0000
@@ -27,6 +27,7 @@
27namespace OnlineAccountsUi {27namespace OnlineAccountsUi {
2828
29class PromptSessionPrivate;29class PromptSessionPrivate;
30class MirHelper;
30class MirHelperPrivate;31class MirHelperPrivate;
3132
32class PromptSession: public QObject33class PromptSession: public QObject
@@ -45,6 +46,7 @@
45 explicit PromptSession(PromptSessionPrivate *priv);46 explicit PromptSession(PromptSessionPrivate *priv);
4647
47private:48private:
49 friend class MirHelper;
48 friend class MirHelperPrivate;50 friend class MirHelperPrivate;
49 PromptSessionPrivate *d_ptr;51 PromptSessionPrivate *d_ptr;
50 Q_DECLARE_PRIVATE(PromptSession)52 Q_DECLARE_PRIVATE(PromptSession)
5153
=== modified file 'online-accounts-service/ui-proxy.cpp'
--- online-accounts-service/ui-proxy.cpp 2015-02-03 10:21:46 +0000
+++ online-accounts-service/ui-proxy.cpp 2015-02-16 15:47:16 +0000
@@ -225,6 +225,8 @@
225{225{
226 Q_Q(UiProxy);226 Q_Q(UiProxy);
227227
228 if (!m_clientPid) return false;
229
228 PromptSessionP session =230 PromptSessionP session =
229 MirHelper::instance()->createPromptSession(m_clientPid);231 MirHelper::instance()->createPromptSession(m_clientPid);
230 if (!session) return false;232 if (!session) return false;
@@ -246,14 +248,12 @@
246248
247bool UiProxyPrivate::init()249bool UiProxyPrivate::init()
248{250{
249 m_arguments.clear();251 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
250 if (!m_promptSession) {252 if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
251 /* the first argument is required to be the desktop file */253 if (!setupPromptSession()) {
252 m_arguments.append("--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop");254 qWarning() << "Couldn't setup prompt session";
253 }255 return false;
254256 }
255 if (m_clientPid) {
256 setupPromptSession();
257 }257 }
258258
259 return true;259 return true;
@@ -313,15 +313,6 @@
313 m_arguments.prepend(accountsUi);313 m_arguments.prepend(accountsUi);
314 }314 }
315315
316 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
317 if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
318 if (!setupPromptSession()) {
319 qWarning() << "Couldn't setup prompt session";
320 setStatus(UiProxy::Error);
321 return;
322 }
323 }
324
325 setStatus(UiProxy::Loading);316 setStatus(UiProxy::Loading);
326 m_process.start(processName, m_arguments);317 m_process.start(processName, m_arguments);
327 if (Q_UNLIKELY(!m_process.waitForStarted())) {318 if (Q_UNLIKELY(!m_process.waitForStarted())) {
328319
=== modified file 'tests/online-accounts-service/tst_ui_proxy.cpp'
--- tests/online-accounts-service/tst_ui_proxy.cpp 2014-12-03 13:42:09 +0000
+++ tests/online-accounts-service/tst_ui_proxy.cpp 2015-02-16 15:47:16 +0000
@@ -204,6 +204,8 @@
204 void testRequestDelay();204 void testRequestDelay();
205 void testHandler();205 void testHandler();
206 void testWrapper();206 void testWrapper();
207 void testTrustSessionError_data();
208 void testTrustSessionError();
207209
208private:210private:
209 QDBusConnection m_connection;211 QDBusConnection m_connection;
@@ -477,6 +479,43 @@
477 delete proxy;479 delete proxy;
478}480}
479481
482void UiProxyTest::testTrustSessionError_data()
483{
484 QTest::addColumn<int>("clientPid");
485 QTest::addColumn<QString>("envVar");
486 QTest::addColumn<bool>("expectSuccess");
487
488 QTest::newRow("PID 0") << 0 << "" << false;
489
490 QTest::newRow("fail creation") << 4 <<
491 "TEST_MIR_HELPER_FAIL_CREATE=1" << false;
492
493 QTest::newRow("return empty socket") << 4 <<
494 "" << false;
495
496 QTest::newRow("success") << 4 <<
497 "TEST_MIR_HELPER_SOCKET=something" << true;
498}
499
500void UiProxyTest::testTrustSessionError()
501{
502 QFETCH(int, clientPid);
503 QFETCH(QString, envVar);
504 QFETCH(bool, expectSuccess);
505
506 qputenv("QT_QPA_PLATFORM", "ubuntu-something");
507
508 QStringList envVarSplit = envVar.split('=');
509 QByteArray envVarKey = envVarSplit.value(0, "").toUtf8();
510 QByteArray envVarValue = envVarSplit.value(1, "").toUtf8();
511 qputenv(envVarKey.constData(), envVarValue);
512 UiProxy *proxy = new UiProxy(clientPid, this);
513 QCOMPARE(proxy->init(), expectSuccess);
514 delete proxy;
515
516 qunsetenv(envVarKey.constData());
517}
518
480QTEST_MAIN(UiProxyTest);519QTEST_MAIN(UiProxyTest);
481520
482#include "tst_ui_proxy.moc"521#include "tst_ui_proxy.moc"
483522
=== modified file 'tests/online-accounts-service/tst_ui_proxy.pro'
--- tests/online-accounts-service/tst_ui_proxy.pro 2014-12-08 16:22:39 +0000
+++ tests/online-accounts-service/tst_ui_proxy.pro 2015-02-16 15:47:16 +0000
@@ -13,6 +13,7 @@
13 testlib13 testlib
1414
15DEFINES += \15DEFINES += \
16 BUILDING_TESTS \
16 INSTALL_BIN_DIR=\\\"$${INSTALL_PREFIX}/bin\\\"17 INSTALL_BIN_DIR=\\\"$${INSTALL_PREFIX}/bin\\\"
1718
18PKGCONFIG += \19PKGCONFIG += \

Subscribers

People subscribed via source and target branches