Merge lp:~mardy/online-accounts-api/fix-initialization into lp:online-accounts-api

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 17
Merged at revision: 15
Proposed branch: lp:~mardy/online-accounts-api/fix-initialization
Merge into: lp:online-accounts-api
Diff against target: 210 lines (+121/-2)
5 files modified
src/lib/OnlineAccountsDaemon/authenticator.cpp (+15/-2)
src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp (+5/-0)
tests/daemon/functional_tests/data/oauth1auth.service (+18/-0)
tests/daemon/functional_tests/functional_tests.cpp (+30/-0)
tests/lib/qml_module/tst_qml_module.cpp (+53/-0)
To merge this branch: bzr merge lp:~mardy/online-accounts-api/fix-initialization
Reviewer Review Type Date Requested Status
Online Accounts Pending
Review via email: mp+276286@code.launchpad.net

Commit message

If the applicationId is not set, force using APP_ID

Because the m_applicationIdChanged variable was not set, we were not
initializing the Manager at all.

Description of the change

If the applicationId is not set, force using APP_ID

Because the m_applicationIdChanged variable was not set, we were not
initializing the Manager at all.

To post a comment you must log in.
16. By Alberto Mardegan

Pass auth data back to the client

17. By Alberto Mardegan

Tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lib/OnlineAccountsDaemon/authenticator.cpp'
2--- src/lib/OnlineAccountsDaemon/authenticator.cpp 2015-09-03 10:41:07 +0000
3+++ src/lib/OnlineAccountsDaemon/authenticator.cpp 2015-11-03 14:45:24 +0000
4@@ -72,6 +72,7 @@
5 SignOn::Identity *m_identity;
6 QVariantMap m_parameters;
7 QVariantMap m_reply;
8+ QVariantMap m_extraReplyData;
9 QString m_errorName;
10 QString m_errorMessage;
11 Authenticator *q_ptr;
12@@ -106,13 +107,25 @@
13
14 QVariantMap allSessionData =
15 mergeMaps(authData.parameters(), mergeMaps(parameters, m_parameters));
16- m_authSession->process(allSessionData, authData.mechanism());
17+ QString mechanism = authData.mechanism();
18+
19+ m_extraReplyData.clear();
20+ if (mechanism == "HMAC-SHA1" || mechanism == "PLAINTEXT") {
21+ /* For OAuth 1.0, let's return also the Consumer key and secret along
22+ * with the reply. */
23+ m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] =
24+ allSessionData.value("ConsumerKey");
25+ m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET] =
26+ allSessionData.value("ConsumerSecret");
27+ }
28+
29+ m_authSession->process(allSessionData, mechanism);
30 }
31
32 void AuthenticatorPrivate::onAuthSessionResponse(const SignOn::SessionData &sessionData)
33 {
34 Q_Q(Authenticator);
35- m_reply = sessionData.toMap();
36+ m_reply = mergeMaps(m_extraReplyData, sessionData.toMap());
37 Q_EMIT q->finished();
38 }
39
40
41=== modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp'
42--- src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2015-09-23 08:23:49 +0000
43+++ src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2015-11-03 14:45:24 +0000
44@@ -134,6 +134,11 @@
45 QStringList parts = QString::fromUtf8(qgetenv("APP_ID")).split('_');
46 if (parts.count() == 3) {
47 m_applicationId = QStringList(parts.mid(0, 2)).join('_');
48+ m_applicationIdChanged = true;
49+ } else {
50+ qWarning() << "Ubuntu.OnlineAccounts: No APP_ID defined "
51+ "and no applicationId given!";
52+ return;
53 }
54 }
55
56
57=== added file 'tests/daemon/functional_tests/data/oauth1auth.service'
58--- tests/daemon/functional_tests/data/oauth1auth.service 1970-01-01 00:00:00 +0000
59+++ tests/daemon/functional_tests/data/oauth1auth.service 2015-11-03 14:45:24 +0000
60@@ -0,0 +1,18 @@
61+<?xml version="1.0" encoding="UTF-8" ?>
62+<service id="oauth1auth">
63+ <type>e-mail</type>
64+ <name>OAuth 1 test</name>
65+ <icon>general_myservice</icon>
66+ <provider>cool</provider>
67+
68+ <template>
69+ <group name="auth">
70+ <setting name="method">oauth2</setting>
71+ <setting name="mechanism">HMAC-SHA1</setting>
72+ <group name="oauth2/HMAC-SHA1">
73+ <setting name="ConsumerKey">c0nsum3rk3y</setting>
74+ <setting name="ConsumerSecret">c0nsum3rs3cr3t</setting>
75+ </group>
76+ </group>
77+ </template>
78+</service>
79
80=== modified file 'tests/daemon/functional_tests/functional_tests.cpp'
81--- tests/daemon/functional_tests/functional_tests.cpp 2015-09-23 12:40:40 +0000
82+++ tests/daemon/functional_tests/functional_tests.cpp 2015-11-03 14:45:24 +0000
83@@ -196,6 +196,7 @@
84 Accounts::Manager *manager = new Accounts::Manager(this);
85 Accounts::Service coolMail = manager->service("coolmail");
86 Accounts::Service coolShare = manager->service("com.ubuntu.tests_coolshare");
87+ Accounts::Service oauth1auth = manager->service("oauth1auth");
88 Accounts::Account *account1 = manager->createAccount("cool");
89 QVERIFY(account1 != 0);
90 account1->setEnabled(true);
91@@ -226,6 +227,8 @@
92 account3->setCredentialsId(m_account3CredentialsId);
93 account3->selectService(coolMail);
94 account3->setEnabled(true);
95+ account3->selectService(oauth1auth);
96+ account3->setEnabled(true);
97 account3->syncAndBlock();
98
99 delete manager;
100@@ -344,6 +347,33 @@
101 authParams <<
102 credentials <<
103 QString();
104+
105+ authParams.clear();
106+ credentials.clear();
107+ credentials["UiPolicy"] = 0;
108+ credentials["ConsumerKey"] = "c0nsum3rk3y";
109+ credentials["ConsumerSecret"] = "c0nsum3rs3cr3t";
110+ QTest::newRow("OAuth1 client data") <<
111+ 3 <<
112+ "oauth1auth" <<
113+ true << false <<
114+ authParams <<
115+ credentials <<
116+ QString();
117+
118+ authParams.clear();
119+ authParams["ConsumerKey"] = "overridden";
120+ credentials.clear();
121+ credentials["UiPolicy"] = 0;
122+ credentials["ConsumerKey"] = "overridden";
123+ credentials["ConsumerSecret"] = "c0nsum3rs3cr3t";
124+ QTest::newRow("OAuth1 client data, overridden") <<
125+ 3 <<
126+ "oauth1auth" <<
127+ true << false <<
128+ authParams <<
129+ credentials <<
130+ QString();
131 }
132
133 void FunctionalTests::testAuthenticate()
134
135=== modified file 'tests/lib/qml_module/tst_qml_module.cpp'
136--- tests/lib/qml_module/tst_qml_module.cpp 2015-08-28 14:25:23 +0000
137+++ tests/lib/qml_module/tst_qml_module.cpp 2015-11-03 14:45:24 +0000
138@@ -26,6 +26,7 @@
139 #include <QObject>
140 #include <QQmlComponent>
141 #include <QQmlEngine>
142+#include <QRegularExpression>
143 #include <QSignalSpy>
144 #include <QTest>
145 #include <libqtdbusmock/DBusMock.h>
146@@ -98,6 +99,8 @@
147 void testModelRequestAccess();
148 void testAccountAuthentication_data();
149 void testAccountAuthentication();
150+ void testInitialization_data();
151+ void testInitialization();
152
153 private:
154 QtDBusTest::DBusTestRunner m_dbus;
155@@ -561,5 +564,55 @@
156 delete object;
157 }
158
159+void ModuleTest::testInitialization_data()
160+{
161+ QTest::addColumn<QString>("appId");
162+ QTest::addColumn<bool>("errorExpected");
163+
164+ QTest::newRow("empty APP_ID") <<
165+ "" <<
166+ true;
167+
168+ QTest::newRow("invalid APP_ID") <<
169+ "" <<
170+ true;
171+
172+ QTest::newRow("valid APP_ID") <<
173+ "my.package_app_0.2" <<
174+ false;
175+}
176+
177+void ModuleTest::testInitialization()
178+{
179+ QFETCH(QString, appId);
180+ QFETCH(bool, errorExpected);
181+
182+ qputenv("APP_ID", appId.toUtf8());
183+
184+ if (errorExpected) {
185+ QTest::ignoreMessage(QtWarningMsg,
186+ QRegularExpression("Ubuntu.OnlineAccounts:.*"));
187+ }
188+
189+ QQmlEngine engine;
190+ QQmlComponent component(&engine);
191+ component.setData("import Ubuntu.OnlineAccounts 2.0\n"
192+ "AccountModel {}",
193+ QUrl());
194+ QObject *object = component.create();
195+ QVERIFY(object != 0);
196+
197+ if (!errorExpected) {
198+ /* We just want to check that invoking this method won't cause a crash */
199+ QString serviceId = "bar";
200+ QVariantMap params;
201+ bool ok = QMetaObject::invokeMethod(object, "requestAccess",
202+ Q_ARG(QString, serviceId),
203+ Q_ARG(QVariantMap, params));
204+ QVERIFY(ok);
205+ }
206+ delete object;
207+}
208+
209 QTEST_MAIN(ModuleTest)
210 #include "tst_qml_module.moc"

Subscribers

People subscribed via source and target branches