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

Proposed by Alberto Mardegan on 2015-02-16
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) 2015-02-16 Approve on 2015-02-17
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.
review: Needs Information
Alberto Mardegan (mardy) :
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/mir-helper-stub.cpp'
2--- online-accounts-service/mir-helper-stub.cpp 2014-11-25 13:34:16 +0000
3+++ online-accounts-service/mir-helper-stub.cpp 2015-02-16 15:47:16 +0000
4@@ -40,7 +40,11 @@
5
6 QString PromptSession::requestSocket()
7 {
8+#ifdef BUILDING_TESTS
9+ return QString::fromUtf8(qgetenv("TEST_MIR_HELPER_SOCKET"));
10+#else
11 return QString();
12+#endif
13 }
14
15 MirHelper::MirHelper(QObject *parent):
16@@ -65,5 +69,10 @@
17 PromptSessionP MirHelper::createPromptSession(pid_t initiatorPid)
18 {
19 Q_UNUSED(initiatorPid);
20+#ifdef BUILDING_TESTS
21+ return qgetenv("TEST_MIR_HELPER_FAIL_CREATE").isEmpty() ?
22+ PromptSessionP(new PromptSession(0)) : PromptSessionP();
23+#else
24 return PromptSessionP();
25+#endif
26 }
27
28=== modified file 'online-accounts-service/mir-helper.h'
29--- online-accounts-service/mir-helper.h 2014-11-21 13:50:15 +0000
30+++ online-accounts-service/mir-helper.h 2015-02-16 15:47:16 +0000
31@@ -27,6 +27,7 @@
32 namespace OnlineAccountsUi {
33
34 class PromptSessionPrivate;
35+class MirHelper;
36 class MirHelperPrivate;
37
38 class PromptSession: public QObject
39@@ -45,6 +46,7 @@
40 explicit PromptSession(PromptSessionPrivate *priv);
41
42 private:
43+ friend class MirHelper;
44 friend class MirHelperPrivate;
45 PromptSessionPrivate *d_ptr;
46 Q_DECLARE_PRIVATE(PromptSession)
47
48=== modified file 'online-accounts-service/ui-proxy.cpp'
49--- online-accounts-service/ui-proxy.cpp 2015-02-03 10:21:46 +0000
50+++ online-accounts-service/ui-proxy.cpp 2015-02-16 15:47:16 +0000
51@@ -225,6 +225,8 @@
52 {
53 Q_Q(UiProxy);
54
55+ if (!m_clientPid) return false;
56+
57 PromptSessionP session =
58 MirHelper::instance()->createPromptSession(m_clientPid);
59 if (!session) return false;
60@@ -246,14 +248,12 @@
61
62 bool UiProxyPrivate::init()
63 {
64- m_arguments.clear();
65- if (!m_promptSession) {
66- /* the first argument is required to be the desktop file */
67- m_arguments.append("--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop");
68- }
69-
70- if (m_clientPid) {
71- setupPromptSession();
72+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
73+ if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
74+ if (!setupPromptSession()) {
75+ qWarning() << "Couldn't setup prompt session";
76+ return false;
77+ }
78 }
79
80 return true;
81@@ -313,15 +313,6 @@
82 m_arguments.prepend(accountsUi);
83 }
84
85- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
86- if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
87- if (!setupPromptSession()) {
88- qWarning() << "Couldn't setup prompt session";
89- setStatus(UiProxy::Error);
90- return;
91- }
92- }
93-
94 setStatus(UiProxy::Loading);
95 m_process.start(processName, m_arguments);
96 if (Q_UNLIKELY(!m_process.waitForStarted())) {
97
98=== modified file 'tests/online-accounts-service/tst_ui_proxy.cpp'
99--- tests/online-accounts-service/tst_ui_proxy.cpp 2014-12-03 13:42:09 +0000
100+++ tests/online-accounts-service/tst_ui_proxy.cpp 2015-02-16 15:47:16 +0000
101@@ -204,6 +204,8 @@
102 void testRequestDelay();
103 void testHandler();
104 void testWrapper();
105+ void testTrustSessionError_data();
106+ void testTrustSessionError();
107
108 private:
109 QDBusConnection m_connection;
110@@ -477,6 +479,43 @@
111 delete proxy;
112 }
113
114+void UiProxyTest::testTrustSessionError_data()
115+{
116+ QTest::addColumn<int>("clientPid");
117+ QTest::addColumn<QString>("envVar");
118+ QTest::addColumn<bool>("expectSuccess");
119+
120+ QTest::newRow("PID 0") << 0 << "" << false;
121+
122+ QTest::newRow("fail creation") << 4 <<
123+ "TEST_MIR_HELPER_FAIL_CREATE=1" << false;
124+
125+ QTest::newRow("return empty socket") << 4 <<
126+ "" << false;
127+
128+ QTest::newRow("success") << 4 <<
129+ "TEST_MIR_HELPER_SOCKET=something" << true;
130+}
131+
132+void UiProxyTest::testTrustSessionError()
133+{
134+ QFETCH(int, clientPid);
135+ QFETCH(QString, envVar);
136+ QFETCH(bool, expectSuccess);
137+
138+ qputenv("QT_QPA_PLATFORM", "ubuntu-something");
139+
140+ QStringList envVarSplit = envVar.split('=');
141+ QByteArray envVarKey = envVarSplit.value(0, "").toUtf8();
142+ QByteArray envVarValue = envVarSplit.value(1, "").toUtf8();
143+ qputenv(envVarKey.constData(), envVarValue);
144+ UiProxy *proxy = new UiProxy(clientPid, this);
145+ QCOMPARE(proxy->init(), expectSuccess);
146+ delete proxy;
147+
148+ qunsetenv(envVarKey.constData());
149+}
150+
151 QTEST_MAIN(UiProxyTest);
152
153 #include "tst_ui_proxy.moc"
154
155=== modified file 'tests/online-accounts-service/tst_ui_proxy.pro'
156--- tests/online-accounts-service/tst_ui_proxy.pro 2014-12-08 16:22:39 +0000
157+++ tests/online-accounts-service/tst_ui_proxy.pro 2015-02-16 15:47:16 +0000
158@@ -13,6 +13,7 @@
159 testlib
160
161 DEFINES += \
162+ BUILDING_TESTS \
163 INSTALL_BIN_DIR=\\\"$${INSTALL_PREFIX}/bin\\\"
164
165 PKGCONFIG += \

Subscribers

People subscribed via source and target branches