Merge lp:~mardy/online-accounts-api/password-1628473 into lp:online-accounts-api
- password-1628473
- Merge into trunk
Proposed by
Alberto Mardegan
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Alberto Mardegan | ||||
Approved revision: | 28 | ||||
Merged at revision: | 32 | ||||
Proposed branch: | lp:~mardy/online-accounts-api/password-1628473 | ||||
Merge into: | lp:online-accounts-api | ||||
Diff against target: |
435 lines (+131/-42) 7 files modified
src/lib/OnlineAccountsDaemon/authenticator.cpp (+37/-3) src/lib/OnlineAccountsDaemon/authenticator.h (+2/-0) src/lib/OnlineAccountsDaemon/manager.cpp (+2/-21) tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service (+7/-0) tests/daemon/functional_tests/fake_signond.h (+4/-0) tests/daemon/functional_tests/functional_tests.cpp (+69/-16) tests/daemon/functional_tests/signond.py (+10/-2) |
||||
To merge this branch: | bzr merge lp:~mardy/online-accounts-api/password-1628473 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Barth (community) | Approve | ||
Review via email: mp+307026@code.launchpad.net |
Commit message
Fix reply of password-based authentication
The keys for the username and password are different from those used by signond, and need to be translated.
Description of the change
Fix reply of password-based authentication
The keys for the username and password are different from those used by signond, and need to be translated.
To post a comment you must log in.
- 28. By Alberto Mardegan
-
From trunk
* debian/control:
- Depend on qttools5-dev-tools for qdoc (LP: #1608814)
* debian/rules:
- No need to invoke dh_python
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 2016-02-12 07:44:03 +0000 | |||
3 | +++ src/lib/OnlineAccountsDaemon/authenticator.cpp 2016-10-06 06:56:41 +0000 | |||
4 | @@ -71,6 +71,7 @@ | |||
5 | 71 | SignOn::AuthSession *m_authSession; | 71 | SignOn::AuthSession *m_authSession; |
6 | 72 | SignOn::Identity *m_identity; | 72 | SignOn::Identity *m_identity; |
7 | 73 | QVariantMap m_parameters; | 73 | QVariantMap m_parameters; |
8 | 74 | int m_authMethod; | ||
9 | 74 | QVariantMap m_reply; | 75 | QVariantMap m_reply; |
10 | 75 | QVariantMap m_extraReplyData; | 76 | QVariantMap m_extraReplyData; |
11 | 76 | QString m_errorName; | 77 | QString m_errorName; |
12 | @@ -85,6 +86,7 @@ | |||
13 | 85 | QObject(q), | 86 | QObject(q), |
14 | 86 | m_authSession(0), | 87 | m_authSession(0), |
15 | 87 | m_identity(0), | 88 | m_identity(0), |
16 | 89 | m_authMethod(ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN), | ||
17 | 88 | m_invalidateCache(false), | 90 | m_invalidateCache(false), |
18 | 89 | q_ptr(q) | 91 | q_ptr(q) |
19 | 90 | { | 92 | { |
20 | @@ -111,11 +113,14 @@ | |||
21 | 111 | mergeMaps(authData.parameters(), mergeMaps(parameters, m_parameters)); | 113 | mergeMaps(authData.parameters(), mergeMaps(parameters, m_parameters)); |
22 | 112 | QString mechanism = authData.mechanism(); | 114 | QString mechanism = authData.mechanism(); |
23 | 113 | 115 | ||
24 | 116 | m_authMethod = Authenticator::authMethod(authData); | ||
25 | 117 | |||
26 | 114 | if (m_invalidateCache) { | 118 | if (m_invalidateCache) { |
27 | 115 | /* This works for OAuth 1.0 and 2.0; other authentication plugins should | 119 | /* This works for OAuth 1.0 and 2.0; other authentication plugins should |
28 | 116 | * implement a similar flag. */ | 120 | * implement a similar flag. */ |
29 | 117 | allSessionData["ForceTokenRefresh"] = true; | 121 | allSessionData["ForceTokenRefresh"] = true; |
31 | 118 | if (authData.method() == "password" || authData.method() == "sasl") { | 122 | if (m_authMethod == ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD || |
32 | 123 | m_authMethod == ONLINE_ACCOUNTS_AUTH_METHOD_SASL) { | ||
33 | 119 | uint uiPolicy = allSessionData.value("UiPolicy").toUInt(); | 124 | uint uiPolicy = allSessionData.value("UiPolicy").toUInt(); |
34 | 120 | if (uiPolicy != SignOn::NoUserInteractionPolicy) { | 125 | if (uiPolicy != SignOn::NoUserInteractionPolicy) { |
35 | 121 | allSessionData["UiPolicy"] = SignOn::RequestPasswordPolicy; | 126 | allSessionData["UiPolicy"] = SignOn::RequestPasswordPolicy; |
36 | @@ -124,7 +129,7 @@ | |||
37 | 124 | } | 129 | } |
38 | 125 | 130 | ||
39 | 126 | m_extraReplyData.clear(); | 131 | m_extraReplyData.clear(); |
41 | 127 | if (mechanism == "HMAC-SHA1" || mechanism == "PLAINTEXT") { | 132 | if (m_authMethod == ONLINE_ACCOUNTS_AUTH_METHOD_OAUTH1) { |
42 | 128 | /* For OAuth 1.0, let's return also the Consumer key and secret along | 133 | /* For OAuth 1.0, let's return also the Consumer key and secret along |
43 | 129 | * with the reply. */ | 134 | * with the reply. */ |
44 | 130 | m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] = | 135 | m_extraReplyData[ONLINE_ACCOUNTS_AUTH_KEY_CONSUMER_KEY] = |
45 | @@ -139,7 +144,17 @@ | |||
46 | 139 | void AuthenticatorPrivate::onAuthSessionResponse(const SignOn::SessionData &sessionData) | 144 | void AuthenticatorPrivate::onAuthSessionResponse(const SignOn::SessionData &sessionData) |
47 | 140 | { | 145 | { |
48 | 141 | Q_Q(Authenticator); | 146 | Q_Q(Authenticator); |
50 | 142 | m_reply = mergeMaps(m_extraReplyData, sessionData.toMap()); | 147 | QVariantMap signonReply; |
51 | 148 | |||
52 | 149 | /* Perform some method-specific translation of reply keys */ | ||
53 | 150 | if (m_authMethod == ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD) { | ||
54 | 151 | signonReply[ONLINE_ACCOUNTS_AUTH_KEY_USERNAME] = sessionData.UserName(); | ||
55 | 152 | signonReply[ONLINE_ACCOUNTS_AUTH_KEY_PASSWORD] = sessionData.Secret(); | ||
56 | 153 | } else { | ||
57 | 154 | signonReply = sessionData.toMap(); | ||
58 | 155 | } | ||
59 | 156 | |||
60 | 157 | m_reply = mergeMaps(m_extraReplyData, signonReply); | ||
61 | 143 | Q_EMIT q->finished(); | 158 | Q_EMIT q->finished(); |
62 | 144 | } | 159 | } |
63 | 145 | 160 | ||
64 | @@ -231,4 +246,23 @@ | |||
65 | 231 | return d->m_errorMessage; | 246 | return d->m_errorMessage; |
66 | 232 | } | 247 | } |
67 | 233 | 248 | ||
68 | 249 | int Authenticator::authMethod(const Accounts::AuthData &authData) | ||
69 | 250 | { | ||
70 | 251 | QString method = authData.method(); | ||
71 | 252 | QString mechanism = authData.mechanism(); | ||
72 | 253 | if (method == "oauth2") { | ||
73 | 254 | if (mechanism == "web_server" || mechanism == "user_agent") { | ||
74 | 255 | return ONLINE_ACCOUNTS_AUTH_METHOD_OAUTH2; | ||
75 | 256 | } else if (mechanism == "HMAC-SHA1" || mechanism == "PLAINTEXT") { | ||
76 | 257 | return ONLINE_ACCOUNTS_AUTH_METHOD_OAUTH1; | ||
77 | 258 | } | ||
78 | 259 | } else if (method == "sasl") { | ||
79 | 260 | return ONLINE_ACCOUNTS_AUTH_METHOD_SASL; | ||
80 | 261 | } else if (method == "password") { | ||
81 | 262 | return ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD; | ||
82 | 263 | } | ||
83 | 264 | |||
84 | 265 | return ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN; | ||
85 | 266 | } | ||
86 | 267 | |||
87 | 234 | #include "authenticator.moc" | 268 | #include "authenticator.moc" |
88 | 235 | 269 | ||
89 | === modified file 'src/lib/OnlineAccountsDaemon/authenticator.h' | |||
90 | --- src/lib/OnlineAccountsDaemon/authenticator.h 2015-08-28 14:25:23 +0000 | |||
91 | +++ src/lib/OnlineAccountsDaemon/authenticator.h 2016-10-06 06:56:41 +0000 | |||
92 | @@ -51,6 +51,8 @@ | |||
93 | 51 | QString errorName() const; | 51 | QString errorName() const; |
94 | 52 | QString errorMessage() const; | 52 | QString errorMessage() const; |
95 | 53 | 53 | ||
96 | 54 | static int authMethod(const Accounts::AuthData &authData); | ||
97 | 55 | |||
98 | 54 | Q_SIGNALS: | 56 | Q_SIGNALS: |
99 | 55 | void finished(); | 57 | void finished(); |
100 | 56 | 58 | ||
101 | 57 | 59 | ||
102 | === modified file 'src/lib/OnlineAccountsDaemon/manager.cpp' | |||
103 | --- src/lib/OnlineAccountsDaemon/manager.cpp 2016-01-13 14:23:12 +0000 | |||
104 | +++ src/lib/OnlineAccountsDaemon/manager.cpp 2016-10-06 06:56:41 +0000 | |||
105 | @@ -33,6 +33,7 @@ | |||
106 | 33 | #include <QSet> | 33 | #include <QSet> |
107 | 34 | #include "access_request.h" | 34 | #include "access_request.h" |
108 | 35 | #include "authentication_request.h" | 35 | #include "authentication_request.h" |
109 | 36 | #include "authenticator.h" | ||
110 | 36 | #include "client_registry.h" | 37 | #include "client_registry.h" |
111 | 37 | #include "dbus_constants.h" | 38 | #include "dbus_constants.h" |
112 | 38 | #include "manager_adaptor.h" | 39 | #include "manager_adaptor.h" |
113 | @@ -76,7 +77,6 @@ | |||
114 | 76 | const QString &serviceName, | 77 | const QString &serviceName, |
115 | 77 | const QStringList &clients); | 78 | const QStringList &clients); |
116 | 78 | 79 | ||
117 | 79 | int authMethod(const Accounts::AuthData &authData); | ||
118 | 80 | AccountInfo readAccountInfo(const Accounts::AccountService *as); | 80 | AccountInfo readAccountInfo(const Accounts::AccountService *as); |
119 | 81 | QList<AccountInfo> getAccounts(const QVariantMap &filters, | 81 | QList<AccountInfo> getAccounts(const QVariantMap &filters, |
120 | 82 | const CallContext &context); | 82 | const CallContext &context); |
121 | @@ -317,25 +317,6 @@ | |||
122 | 317 | return activeAccount; | 317 | return activeAccount; |
123 | 318 | } | 318 | } |
124 | 319 | 319 | ||
125 | 320 | int ManagerPrivate::authMethod(const Accounts::AuthData &authData) | ||
126 | 321 | { | ||
127 | 322 | QString method = authData.method(); | ||
128 | 323 | QString mechanism = authData.mechanism(); | ||
129 | 324 | if (method == "oauth2") { | ||
130 | 325 | if (mechanism == "web_server" || mechanism == "user_agent") { | ||
131 | 326 | return ONLINE_ACCOUNTS_AUTH_METHOD_OAUTH2; | ||
132 | 327 | } else if (mechanism == "HMAC-SHA1" || mechanism == "PLAINTEXT") { | ||
133 | 328 | return ONLINE_ACCOUNTS_AUTH_METHOD_OAUTH1; | ||
134 | 329 | } | ||
135 | 330 | } else if (method == "sasl") { | ||
136 | 331 | return ONLINE_ACCOUNTS_AUTH_METHOD_SASL; | ||
137 | 332 | } else if (method == "password") { | ||
138 | 333 | return ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD; | ||
139 | 334 | } | ||
140 | 335 | |||
141 | 336 | return ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN; | ||
142 | 337 | } | ||
143 | 338 | |||
144 | 339 | AccountInfo ManagerPrivate::readAccountInfo(const Accounts::AccountService *as) | 320 | AccountInfo ManagerPrivate::readAccountInfo(const Accounts::AccountService *as) |
145 | 340 | { | 321 | { |
146 | 341 | QVariantMap info; | 322 | QVariantMap info; |
147 | @@ -343,7 +324,7 @@ | |||
148 | 343 | info[ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME] = as->account()->displayName(); | 324 | info[ONLINE_ACCOUNTS_INFO_KEY_DISPLAY_NAME] = as->account()->displayName(); |
149 | 344 | info[ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID] = as->service().name(); | 325 | info[ONLINE_ACCOUNTS_INFO_KEY_SERVICE_ID] = as->service().name(); |
150 | 345 | 326 | ||
152 | 346 | info[ONLINE_ACCOUNTS_INFO_KEY_AUTH_METHOD] = authMethod(as->authData()); | 327 | info[ONLINE_ACCOUNTS_INFO_KEY_AUTH_METHOD] = Authenticator::authMethod(as->authData()); |
153 | 347 | QString settingsPrefix(QStringLiteral(ONLINE_ACCOUNTS_INFO_KEY_SETTINGS)); | 328 | QString settingsPrefix(QStringLiteral(ONLINE_ACCOUNTS_INFO_KEY_SETTINGS)); |
154 | 348 | /* First, read the global settings */ | 329 | /* First, read the global settings */ |
155 | 349 | Accounts::Account *a = as->account(); | 330 | Accounts::Account *a = as->account(); |
156 | 350 | 331 | ||
157 | === modified file 'tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service' | |||
158 | --- tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service 2015-07-08 15:09:56 +0000 | |||
159 | +++ tests/daemon/functional_tests/data/com.ubuntu.tests_coolshare.service 2016-10-06 06:56:41 +0000 | |||
160 | @@ -4,4 +4,11 @@ | |||
161 | 4 | <name>Cool Share</name> | 4 | <name>Cool Share</name> |
162 | 5 | <icon>general_otherservice</icon> | 5 | <icon>general_otherservice</icon> |
163 | 6 | <provider>cool</provider> | 6 | <provider>cool</provider> |
164 | 7 | |||
165 | 8 | <template> | ||
166 | 9 | <group name="auth"> | ||
167 | 10 | <setting name="method">password</setting> | ||
168 | 11 | <setting name="mechanism">password</setting> | ||
169 | 12 | </group> | ||
170 | 13 | </template> | ||
171 | 7 | </service> | 14 | </service> |
172 | 8 | 15 | ||
173 | === modified file 'tests/daemon/functional_tests/fake_signond.h' | |||
174 | --- tests/daemon/functional_tests/fake_signond.h 2015-07-06 14:51:30 +0000 | |||
175 | +++ tests/daemon/functional_tests/fake_signond.h 2016-10-06 06:56:41 +0000 | |||
176 | @@ -37,6 +37,10 @@ | |||
177 | 37 | mockedAuthService().call("AddIdentity", id, info); | 37 | mockedAuthService().call("AddIdentity", id, info); |
178 | 38 | } | 38 | } |
179 | 39 | 39 | ||
180 | 40 | void setNextReply(uint identity, const QVariantMap &reply) { | ||
181 | 41 | mockedAuthService().call("SetNextReply", identity, reply); | ||
182 | 42 | } | ||
183 | 43 | |||
184 | 40 | private: | 44 | private: |
185 | 41 | OrgFreedesktopDBusMockInterface &mockedAuthService() { | 45 | OrgFreedesktopDBusMockInterface &mockedAuthService() { |
186 | 42 | return m_mock->mockInterface("com.google.code.AccountsSSO.SingleSignOn", | 46 | return m_mock->mockInterface("com.google.code.AccountsSSO.SingleSignOn", |
187 | 43 | 47 | ||
188 | === modified file 'tests/daemon/functional_tests/functional_tests.cpp' | |||
189 | --- tests/daemon/functional_tests/functional_tests.cpp 2016-07-22 05:08:11 +0000 | |||
190 | +++ tests/daemon/functional_tests/functional_tests.cpp 2016-10-06 06:56:41 +0000 | |||
191 | @@ -186,6 +186,7 @@ | |||
192 | 186 | EnvSetup m_env; | 186 | EnvSetup m_env; |
193 | 187 | DBusService *m_dbus; | 187 | DBusService *m_dbus; |
194 | 188 | int m_firstAccountId; | 188 | int m_firstAccountId; |
195 | 189 | int m_account2CredentialsId; | ||
196 | 189 | int m_account3CredentialsId; | 190 | int m_account3CredentialsId; |
197 | 190 | }; | 191 | }; |
198 | 191 | 192 | ||
199 | @@ -206,6 +207,7 @@ | |||
200 | 206 | FunctionalTests::FunctionalTests(): | 207 | FunctionalTests::FunctionalTests(): |
201 | 207 | QObject(), | 208 | QObject(), |
202 | 208 | m_dbus(0), | 209 | m_dbus(0), |
203 | 210 | m_account2CredentialsId(41), | ||
204 | 209 | m_account3CredentialsId(35) | 211 | m_account3CredentialsId(35) |
205 | 210 | { | 212 | { |
206 | 211 | clearDb(); | 213 | clearDb(); |
207 | @@ -230,6 +232,7 @@ | |||
208 | 230 | QVERIFY(account2 != 0); | 232 | QVERIFY(account2 != 0); |
209 | 231 | account2->setEnabled(true); | 233 | account2->setEnabled(true); |
210 | 232 | account2->setDisplayName("CoolAccount 2"); | 234 | account2->setDisplayName("CoolAccount 2"); |
211 | 235 | account2->setCredentialsId(m_account2CredentialsId); | ||
212 | 233 | account2->selectService(coolMail); | 236 | account2->selectService(coolMail); |
213 | 234 | account2->setEnabled(false); | 237 | account2->setEnabled(false); |
214 | 235 | account2->selectService(coolShare); | 238 | account2->selectService(coolShare); |
215 | @@ -262,6 +265,9 @@ | |||
216 | 262 | { | 265 | { |
217 | 263 | m_dbus = new DBusService(); | 266 | m_dbus = new DBusService(); |
218 | 264 | m_dbus->startServices(); | 267 | m_dbus->startServices(); |
219 | 268 | |||
220 | 269 | /* Uncomment next line to debug DBus calls */ | ||
221 | 270 | // QProcess::startDetached("/usr/bin/dbus-monitor"); | ||
222 | 265 | } | 271 | } |
223 | 266 | 272 | ||
224 | 267 | void FunctionalTests::cleanup() | 273 | void FunctionalTests::cleanup() |
225 | @@ -321,16 +327,19 @@ | |||
226 | 321 | QTest::addColumn<bool>("interactive"); | 327 | QTest::addColumn<bool>("interactive"); |
227 | 322 | QTest::addColumn<bool>("invalidate"); | 328 | QTest::addColumn<bool>("invalidate"); |
228 | 323 | QTest::addColumn<QVariantMap>("authParams"); | 329 | QTest::addColumn<QVariantMap>("authParams"); |
229 | 330 | QTest::addColumn<QVariantMap>("signonReply"); | ||
230 | 324 | QTest::addColumn<QVariantMap>("expectedCredentials"); | 331 | QTest::addColumn<QVariantMap>("expectedCredentials"); |
231 | 325 | QTest::addColumn<QString>("errorName"); | 332 | QTest::addColumn<QString>("errorName"); |
232 | 326 | 333 | ||
233 | 327 | QVariantMap authParams; | 334 | QVariantMap authParams; |
234 | 335 | QVariantMap signonReply; | ||
235 | 328 | QVariantMap credentials; | 336 | QVariantMap credentials; |
236 | 329 | QTest::newRow("invalid account ID") << | 337 | QTest::newRow("invalid account ID") << |
237 | 330 | 12412341 << | 338 | 12412341 << |
238 | 331 | "coolmail" << | 339 | "coolmail" << |
239 | 332 | false << false << | 340 | false << false << |
240 | 333 | authParams << | 341 | authParams << |
241 | 342 | signonReply << | ||
242 | 334 | credentials << | 343 | credentials << |
243 | 335 | ONLINE_ACCOUNTS_ERROR_PERMISSION_DENIED; | 344 | ONLINE_ACCOUNTS_ERROR_PERMISSION_DENIED; |
244 | 336 | 345 | ||
245 | @@ -341,6 +350,7 @@ | |||
246 | 341 | "coolmail" << | 350 | "coolmail" << |
247 | 342 | false << false << | 351 | false << false << |
248 | 343 | authParams << | 352 | authParams << |
249 | 353 | signonReply << | ||
250 | 344 | credentials << | 354 | credentials << |
251 | 345 | "com.ubuntu.OnlineAccounts.Error.Network"; | 355 | "com.ubuntu.OnlineAccounts.Error.Network"; |
252 | 346 | authParams.clear(); | 356 | authParams.clear(); |
253 | @@ -354,6 +364,7 @@ | |||
254 | 354 | "coolmail" << | 364 | "coolmail" << |
255 | 355 | false << false << | 365 | false << false << |
256 | 356 | authParams << | 366 | authParams << |
257 | 367 | signonReply << | ||
258 | 357 | credentials << | 368 | credentials << |
259 | 358 | QString(); | 369 | QString(); |
260 | 359 | 370 | ||
261 | @@ -363,6 +374,7 @@ | |||
262 | 363 | "coolmail" << | 374 | "coolmail" << |
263 | 364 | true << false << | 375 | true << false << |
264 | 365 | authParams << | 376 | authParams << |
265 | 377 | signonReply << | ||
266 | 366 | credentials << | 378 | credentials << |
267 | 367 | QString(); | 379 | QString(); |
268 | 368 | 380 | ||
269 | @@ -372,6 +384,7 @@ | |||
270 | 372 | "coolmail" << | 384 | "coolmail" << |
271 | 373 | true << true << | 385 | true << true << |
272 | 374 | authParams << | 386 | authParams << |
273 | 387 | signonReply << | ||
274 | 375 | credentials << | 388 | credentials << |
275 | 376 | QString(); | 389 | QString(); |
276 | 377 | 390 | ||
277 | @@ -385,6 +398,7 @@ | |||
278 | 385 | "oauth1auth" << | 398 | "oauth1auth" << |
279 | 386 | true << false << | 399 | true << false << |
280 | 387 | authParams << | 400 | authParams << |
281 | 401 | signonReply << | ||
282 | 388 | credentials << | 402 | credentials << |
283 | 389 | QString(); | 403 | QString(); |
284 | 390 | 404 | ||
285 | @@ -399,6 +413,25 @@ | |||
286 | 399 | "oauth1auth" << | 413 | "oauth1auth" << |
287 | 400 | true << false << | 414 | true << false << |
288 | 401 | authParams << | 415 | authParams << |
289 | 416 | signonReply << | ||
290 | 417 | credentials << | ||
291 | 418 | QString(); | ||
292 | 419 | |||
293 | 420 | authParams.clear(); | ||
294 | 421 | credentials = QVariantMap { | ||
295 | 422 | { ONLINE_ACCOUNTS_AUTH_KEY_USERNAME, "my name" }, | ||
296 | 423 | { ONLINE_ACCOUNTS_AUTH_KEY_PASSWORD, "don't tell" }, | ||
297 | 424 | }; | ||
298 | 425 | signonReply = QVariantMap { | ||
299 | 426 | { "UserName", "my name" }, | ||
300 | 427 | { "Secret", "don't tell" }, | ||
301 | 428 | }; | ||
302 | 429 | QTest::newRow("password") << | ||
303 | 430 | 2 << | ||
304 | 431 | "com.ubuntu.tests_coolshare" << | ||
305 | 432 | true << false << | ||
306 | 433 | authParams << | ||
307 | 434 | signonReply << | ||
308 | 402 | credentials << | 435 | credentials << |
309 | 403 | QString(); | 436 | QString(); |
310 | 404 | } | 437 | } |
311 | @@ -410,10 +443,16 @@ | |||
312 | 410 | QFETCH(bool, interactive); | 443 | QFETCH(bool, interactive); |
313 | 411 | QFETCH(bool, invalidate); | 444 | QFETCH(bool, invalidate); |
314 | 412 | QFETCH(QVariantMap, authParams); | 445 | QFETCH(QVariantMap, authParams); |
315 | 446 | QFETCH(QVariantMap, signonReply); | ||
316 | 413 | QFETCH(QVariantMap, expectedCredentials); | 447 | QFETCH(QVariantMap, expectedCredentials); |
317 | 414 | QFETCH(QString, errorName); | 448 | QFETCH(QString, errorName); |
318 | 415 | 449 | ||
319 | 450 | m_dbus->signond().addIdentity(m_account2CredentialsId, QVariantMap()); | ||
320 | 416 | m_dbus->signond().addIdentity(m_account3CredentialsId, QVariantMap()); | 451 | m_dbus->signond().addIdentity(m_account3CredentialsId, QVariantMap()); |
321 | 452 | if (!signonReply.isEmpty()) { | ||
322 | 453 | m_dbus->signond().setNextReply(m_account2CredentialsId, signonReply); | ||
323 | 454 | m_dbus->signond().setNextReply(m_account3CredentialsId, signonReply); | ||
324 | 455 | } | ||
325 | 417 | 456 | ||
326 | 418 | DaemonInterface *daemon = new DaemonInterface(m_dbus->sessionConnection()); | 457 | DaemonInterface *daemon = new DaemonInterface(m_dbus->sessionConnection()); |
327 | 419 | 458 | ||
328 | @@ -425,8 +464,10 @@ | |||
329 | 425 | if (errorName.isEmpty()) { | 464 | if (errorName.isEmpty()) { |
330 | 426 | QVERIFY2(!reply.isError(), reply.error().message().toUtf8().constData()); | 465 | QVERIFY2(!reply.isError(), reply.error().message().toUtf8().constData()); |
331 | 427 | QVariantMap credentials = reply.argumentAt<0>(); | 466 | QVariantMap credentials = reply.argumentAt<0>(); |
334 | 428 | // Add the requestor PID | 467 | if (credentials.contains("requestorPid")) { |
335 | 429 | expectedCredentials["requestorPid"] = getpid(); | 468 | // Add the requestor PID |
336 | 469 | expectedCredentials["requestorPid"] = getpid(); | ||
337 | 470 | } | ||
338 | 430 | QCOMPARE(credentials, expectedCredentials); | 471 | QCOMPARE(credentials, expectedCredentials); |
339 | 431 | } else { | 472 | } else { |
340 | 432 | QVERIFY(reply.isError()); | 473 | QVERIFY(reply.isError()); |
341 | @@ -561,11 +602,14 @@ | |||
342 | 561 | 602 | ||
343 | 562 | QCOMPARE(serviceId, coolShare.name()); | 603 | QCOMPARE(serviceId, coolShare.name()); |
344 | 563 | QCOMPARE(accountInfo.id(), account->id()); | 604 | QCOMPARE(accountInfo.id(), account->id()); |
350 | 564 | QVariantMap expectedAccountInfo; | 605 | QVariantMap expectedAccountInfo { |
351 | 565 | expectedAccountInfo["authMethod"] = ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN; | 606 | { "authMethod", ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD }, |
352 | 566 | expectedAccountInfo["changeType"] = ONLINE_ACCOUNTS_INFO_CHANGE_ENABLED; | 607 | { "changeType", ONLINE_ACCOUNTS_INFO_CHANGE_ENABLED }, |
353 | 567 | expectedAccountInfo["displayName"] = "New account"; | 608 | { "displayName", "New account" }, |
354 | 568 | expectedAccountInfo["serviceId"] = "com.ubuntu.tests_coolshare"; | 609 | { "serviceId", "com.ubuntu.tests_coolshare" }, |
355 | 610 | { "settings/auth/mechanism", "password" }, | ||
356 | 611 | { "settings/auth/method", "password" }, | ||
357 | 612 | }; | ||
358 | 569 | QCOMPARE(accountInfo.data(), expectedAccountInfo); | 613 | QCOMPARE(accountInfo.data(), expectedAccountInfo); |
359 | 570 | 614 | ||
360 | 571 | /* Change a setting */ | 615 | /* Change a setting */ |
361 | @@ -579,11 +623,15 @@ | |||
362 | 579 | 623 | ||
363 | 580 | QCOMPARE(serviceId, coolShare.name()); | 624 | QCOMPARE(serviceId, coolShare.name()); |
364 | 581 | QCOMPARE(accountInfo.id(), account->id()); | 625 | QCOMPARE(accountInfo.id(), account->id()); |
370 | 582 | expectedAccountInfo["authMethod"] = ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN; | 626 | expectedAccountInfo = QVariantMap { |
371 | 583 | expectedAccountInfo["changeType"] = ONLINE_ACCOUNTS_INFO_CHANGE_UPDATED; | 627 | { "authMethod", ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD }, |
372 | 584 | expectedAccountInfo["settings/color"] = "blue"; | 628 | { "changeType", ONLINE_ACCOUNTS_INFO_CHANGE_UPDATED }, |
373 | 585 | expectedAccountInfo["displayName"] = "New account"; | 629 | { "settings/color", "blue" }, |
374 | 586 | expectedAccountInfo["serviceId"] = "com.ubuntu.tests_coolshare"; | 630 | { "displayName", "New account" }, |
375 | 631 | { "serviceId", "com.ubuntu.tests_coolshare" }, | ||
376 | 632 | { "settings/auth/mechanism", "password" }, | ||
377 | 633 | { "settings/auth/method", "password" }, | ||
378 | 634 | }; | ||
379 | 587 | QCOMPARE(accountInfo.data(), expectedAccountInfo); | 635 | QCOMPARE(accountInfo.data(), expectedAccountInfo); |
380 | 588 | 636 | ||
381 | 589 | /* Delete the account */ | 637 | /* Delete the account */ |
382 | @@ -597,10 +645,15 @@ | |||
383 | 597 | 645 | ||
384 | 598 | QCOMPARE(serviceId, coolShare.name()); | 646 | QCOMPARE(serviceId, coolShare.name()); |
385 | 599 | QCOMPARE(accountInfo.id(), account->id()); | 647 | QCOMPARE(accountInfo.id(), account->id()); |
390 | 600 | expectedAccountInfo["authMethod"] = ONLINE_ACCOUNTS_AUTH_METHOD_UNKNOWN; | 648 | expectedAccountInfo = QVariantMap { |
391 | 601 | expectedAccountInfo["changeType"] = ONLINE_ACCOUNTS_INFO_CHANGE_DISABLED; | 649 | { "authMethod", ONLINE_ACCOUNTS_AUTH_METHOD_PASSWORD }, |
392 | 602 | expectedAccountInfo["displayName"] = "New account"; | 650 | { "changeType", ONLINE_ACCOUNTS_INFO_CHANGE_DISABLED }, |
393 | 603 | expectedAccountInfo["serviceId"] = "com.ubuntu.tests_coolshare"; | 651 | { "displayName", "New account" }, |
394 | 652 | { "serviceId", "com.ubuntu.tests_coolshare" }, | ||
395 | 653 | { "settings/color", "blue" }, | ||
396 | 654 | { "settings/auth/mechanism", "password" }, | ||
397 | 655 | { "settings/auth/method", "password" }, | ||
398 | 656 | }; | ||
399 | 604 | QCOMPARE(accountInfo.data(), expectedAccountInfo); | 657 | QCOMPARE(accountInfo.data(), expectedAccountInfo); |
400 | 605 | 658 | ||
401 | 606 | delete manager; | 659 | delete manager; |
402 | 607 | 660 | ||
403 | === modified file 'tests/daemon/functional_tests/signond.py' | |||
404 | --- tests/daemon/functional_tests/signond.py 2015-07-23 13:57:48 +0000 | |||
405 | +++ tests/daemon/functional_tests/signond.py 2016-10-06 06:56:41 +0000 | |||
406 | @@ -48,7 +48,11 @@ | |||
407 | 48 | return (path, self.identities[identity]) | 48 | return (path, self.identities[identity]) |
408 | 49 | 49 | ||
409 | 50 | 50 | ||
411 | 51 | def auth_session_process(identity, params, method): | 51 | def auth_session_process(self, params, method): |
412 | 52 | auth_service = dbusmock.get_object(MAIN_OBJ) | ||
413 | 53 | if self.identity in auth_service.auth_replies: | ||
414 | 54 | return auth_service.auth_replies[self.identity] | ||
415 | 55 | |||
416 | 52 | if 'errorName' in params: | 56 | if 'errorName' in params: |
417 | 53 | raise dbus.exceptions.DBusException('Authentication error', | 57 | raise dbus.exceptions.DBusException('Authentication error', |
418 | 54 | name=params['errorName']) | 58 | name=params['errorName']) |
419 | @@ -63,7 +67,7 @@ | |||
420 | 63 | path = '/AuthSession%s' % self.sessions_counter | 67 | path = '/AuthSession%s' % self.sessions_counter |
421 | 64 | self.sessions_counter += 1 | 68 | self.sessions_counter += 1 |
422 | 65 | self.AddObject(path, AUTH_SESSION_IFACE, {}, [ | 69 | self.AddObject(path, AUTH_SESSION_IFACE, {}, [ |
424 | 66 | ('process', 'a{sv}s', 'a{sv}', 'ret = self.auth_session_process(self.identity, args[0], args[1])'), | 70 | ('process', 'a{sv}s', 'a{sv}', 'ret = self.auth_session_process(self, args[0], args[1])'), |
425 | 67 | ]) | 71 | ]) |
426 | 68 | 72 | ||
427 | 69 | auth_session = dbusmock.get_object(path) | 73 | auth_session = dbusmock.get_object(path) |
428 | @@ -91,3 +95,7 @@ | |||
429 | 91 | def AddIdentity(self, identity, data): | 95 | def AddIdentity(self, identity, data): |
430 | 92 | self.identities[identity] = data | 96 | self.identities[identity] = data |
431 | 93 | 97 | ||
432 | 98 | @dbus.service.method(MOCK_IFACE, in_signature='ua{sv}', out_signature='') | ||
433 | 99 | def SetNextReply(self, identity, reply): | ||
434 | 100 | self.auth_replies[identity] = reply | ||
435 | 101 |
LGTM. Nice code reorg as well.