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
=== modified file 'src/lib/OnlineAccountsDaemon/authenticator.cpp'
--- src/lib/OnlineAccountsDaemon/authenticator.cpp 2015-09-03 10:41:07 +0000
+++ src/lib/OnlineAccountsDaemon/authenticator.cpp 2015-11-03 14:45:24 +0000
@@ -72,6 +72,7 @@
72 SignOn::Identity *m_identity;72 SignOn::Identity *m_identity;
73 QVariantMap m_parameters;73 QVariantMap m_parameters;
74 QVariantMap m_reply;74 QVariantMap m_reply;
75 QVariantMap m_extraReplyData;
75 QString m_errorName;76 QString m_errorName;
76 QString m_errorMessage;77 QString m_errorMessage;
77 Authenticator *q_ptr;78 Authenticator *q_ptr;
@@ -106,13 +107,25 @@
106107
107 QVariantMap allSessionData =108 QVariantMap allSessionData =
108 mergeMaps(authData.parameters(), mergeMaps(parameters, m_parameters));109 mergeMaps(authData.parameters(), mergeMaps(parameters, m_parameters));
109 m_authSession->process(allSessionData, authData.mechanism());110 QString mechanism = authData.mechanism();
111
112 m_extraReplyData.clear();
113 if (mechanism == "HMAC-SHA1" || mechanism == "PLAINTEXT") {
114 /* For OAuth 1.0, let's return also the Consumer key and secret along
115 * with the reply. */
116 m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] =
117 allSessionData.value("ConsumerKey");
118 m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_SECRET] =
119 allSessionData.value("ConsumerSecret");
120 }
121
122 m_authSession->process(allSessionData, mechanism);
110}123}
111124
112void AuthenticatorPrivate::onAuthSessionResponse(const SignOn::SessionData &sessionData)125void AuthenticatorPrivate::onAuthSessionResponse(const SignOn::SessionData &sessionData)
113{126{
114 Q_Q(Authenticator);127 Q_Q(Authenticator);
115 m_reply = sessionData.toMap();128 m_reply = mergeMaps(m_extraReplyData, sessionData.toMap());
116 Q_EMIT q->finished();129 Q_EMIT q->finished();
117}130}
118131
119132
=== modified file 'src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp'
--- src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2015-09-23 08:23:49 +0000
+++ src/lib/Ubuntu/OnlineAccounts.2/account_model.cpp 2015-11-03 14:45:24 +0000
@@ -134,6 +134,11 @@
134 QStringList parts = QString::fromUtf8(qgetenv("APP_ID")).split('_');134 QStringList parts = QString::fromUtf8(qgetenv("APP_ID")).split('_');
135 if (parts.count() == 3) {135 if (parts.count() == 3) {
136 m_applicationId = QStringList(parts.mid(0, 2)).join('_');136 m_applicationId = QStringList(parts.mid(0, 2)).join('_');
137 m_applicationIdChanged = true;
138 } else {
139 qWarning() << "Ubuntu.OnlineAccounts: No APP_ID defined "
140 "and no applicationId given!";
141 return;
137 }142 }
138 }143 }
139144
140145
=== added file 'tests/daemon/functional_tests/data/oauth1auth.service'
--- tests/daemon/functional_tests/data/oauth1auth.service 1970-01-01 00:00:00 +0000
+++ tests/daemon/functional_tests/data/oauth1auth.service 2015-11-03 14:45:24 +0000
@@ -0,0 +1,18 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2<service id="oauth1auth">
3 <type>e-mail</type>
4 <name>OAuth 1 test</name>
5 <icon>general_myservice</icon>
6 <provider>cool</provider>
7
8 <template>
9 <group name="auth">
10 <setting name="method">oauth2</setting>
11 <setting name="mechanism">HMAC-SHA1</setting>
12 <group name="oauth2/HMAC-SHA1">
13 <setting name="ConsumerKey">c0nsum3rk3y</setting>
14 <setting name="ConsumerSecret">c0nsum3rs3cr3t</setting>
15 </group>
16 </group>
17 </template>
18</service>
019
=== modified file 'tests/daemon/functional_tests/functional_tests.cpp'
--- tests/daemon/functional_tests/functional_tests.cpp 2015-09-23 12:40:40 +0000
+++ tests/daemon/functional_tests/functional_tests.cpp 2015-11-03 14:45:24 +0000
@@ -196,6 +196,7 @@
196 Accounts::Manager *manager = new Accounts::Manager(this);196 Accounts::Manager *manager = new Accounts::Manager(this);
197 Accounts::Service coolMail = manager->service("coolmail");197 Accounts::Service coolMail = manager->service("coolmail");
198 Accounts::Service coolShare = manager->service("com.ubuntu.tests_coolshare");198 Accounts::Service coolShare = manager->service("com.ubuntu.tests_coolshare");
199 Accounts::Service oauth1auth = manager->service("oauth1auth");
199 Accounts::Account *account1 = manager->createAccount("cool");200 Accounts::Account *account1 = manager->createAccount("cool");
200 QVERIFY(account1 != 0);201 QVERIFY(account1 != 0);
201 account1->setEnabled(true);202 account1->setEnabled(true);
@@ -226,6 +227,8 @@
226 account3->setCredentialsId(m_account3CredentialsId);227 account3->setCredentialsId(m_account3CredentialsId);
227 account3->selectService(coolMail);228 account3->selectService(coolMail);
228 account3->setEnabled(true);229 account3->setEnabled(true);
230 account3->selectService(oauth1auth);
231 account3->setEnabled(true);
229 account3->syncAndBlock();232 account3->syncAndBlock();
230233
231 delete manager;234 delete manager;
@@ -344,6 +347,33 @@
344 authParams <<347 authParams <<
345 credentials <<348 credentials <<
346 QString();349 QString();
350
351 authParams.clear();
352 credentials.clear();
353 credentials["UiPolicy"] = 0;
354 credentials["ConsumerKey"] = "c0nsum3rk3y";
355 credentials["ConsumerSecret"] = "c0nsum3rs3cr3t";
356 QTest::newRow("OAuth1 client data") <<
357 3 <<
358 "oauth1auth" <<
359 true << false <<
360 authParams <<
361 credentials <<
362 QString();
363
364 authParams.clear();
365 authParams["ConsumerKey"] = "overridden";
366 credentials.clear();
367 credentials["UiPolicy"] = 0;
368 credentials["ConsumerKey"] = "overridden";
369 credentials["ConsumerSecret"] = "c0nsum3rs3cr3t";
370 QTest::newRow("OAuth1 client data, overridden") <<
371 3 <<
372 "oauth1auth" <<
373 true << false <<
374 authParams <<
375 credentials <<
376 QString();
347}377}
348378
349void FunctionalTests::testAuthenticate()379void FunctionalTests::testAuthenticate()
350380
=== modified file 'tests/lib/qml_module/tst_qml_module.cpp'
--- tests/lib/qml_module/tst_qml_module.cpp 2015-08-28 14:25:23 +0000
+++ tests/lib/qml_module/tst_qml_module.cpp 2015-11-03 14:45:24 +0000
@@ -26,6 +26,7 @@
26#include <QObject>26#include <QObject>
27#include <QQmlComponent>27#include <QQmlComponent>
28#include <QQmlEngine>28#include <QQmlEngine>
29#include <QRegularExpression>
29#include <QSignalSpy>30#include <QSignalSpy>
30#include <QTest>31#include <QTest>
31#include <libqtdbusmock/DBusMock.h>32#include <libqtdbusmock/DBusMock.h>
@@ -98,6 +99,8 @@
98 void testModelRequestAccess();99 void testModelRequestAccess();
99 void testAccountAuthentication_data();100 void testAccountAuthentication_data();
100 void testAccountAuthentication();101 void testAccountAuthentication();
102 void testInitialization_data();
103 void testInitialization();
101104
102private:105private:
103 QtDBusTest::DBusTestRunner m_dbus;106 QtDBusTest::DBusTestRunner m_dbus;
@@ -561,5 +564,55 @@
561 delete object;564 delete object;
562}565}
563566
567void ModuleTest::testInitialization_data()
568{
569 QTest::addColumn<QString>("appId");
570 QTest::addColumn<bool>("errorExpected");
571
572 QTest::newRow("empty APP_ID") <<
573 "" <<
574 true;
575
576 QTest::newRow("invalid APP_ID") <<
577 "" <<
578 true;
579
580 QTest::newRow("valid APP_ID") <<
581 "my.package_app_0.2" <<
582 false;
583}
584
585void ModuleTest::testInitialization()
586{
587 QFETCH(QString, appId);
588 QFETCH(bool, errorExpected);
589
590 qputenv("APP_ID", appId.toUtf8());
591
592 if (errorExpected) {
593 QTest::ignoreMessage(QtWarningMsg,
594 QRegularExpression("Ubuntu.OnlineAccounts:.*"));
595 }
596
597 QQmlEngine engine;
598 QQmlComponent component(&engine);
599 component.setData("import Ubuntu.OnlineAccounts 2.0\n"
600 "AccountModel {}",
601 QUrl());
602 QObject *object = component.create();
603 QVERIFY(object != 0);
604
605 if (!errorExpected) {
606 /* We just want to check that invoking this method won't cause a crash */
607 QString serviceId = "bar";
608 QVariantMap params;
609 bool ok = QMetaObject::invokeMethod(object, "requestAccess",
610 Q_ARG(QString, serviceId),
611 Q_ARG(QVariantMap, params));
612 QVERIFY(ok);
613 }
614 delete object;
615}
616
564QTEST_MAIN(ModuleTest)617QTEST_MAIN(ModuleTest)
565#include "tst_qml_module.moc"618#include "tst_qml_module.moc"

Subscribers

People subscribed via source and target branches