Merge lp:~mandel/ubuntu-download-manager/filter-all-per-app into lp:ubuntu-download-manager
- filter-all-per-app
- Merge into trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Diego Sarmentero | ||||||||
Approved revision: | 261 | ||||||||
Merged at revision: | 291 | ||||||||
Proposed branch: | lp:~mandel/ubuntu-download-manager/filter-all-per-app | ||||||||
Merge into: | lp:ubuntu-download-manager | ||||||||
Prerequisite: | lp:~mandel/ubuntu-download-manager/db-store-owner | ||||||||
Diff against target: |
1563 lines (+1010/-117) 19 files modified
src/common/priv/CMakeLists.txt (+3/-0) src/common/priv/ubuntu/transfers/system/apparmor.cpp (+31/-11) src/common/priv/ubuntu/transfers/system/apparmor.h (+4/-1) src/common/priv/ubuntu/transfers/system/dbus_proxy.h (+26/-20) src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.cpp (+85/-0) src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.h (+62/-0) src/common/priv/ubuntu/transfers/system/pending_reply.h (+74/-0) src/downloads/priv/ubuntu/downloads/manager.cpp (+47/-16) src/downloads/priv/ubuntu/downloads/manager.h (+1/-1) tests/CMakeLists.txt (+5/-0) tests/apparmor.h (+2/-0) tests/dbus_proxy.h (+74/-0) tests/dbus_proxy_factory.h (+46/-0) tests/download.h (+1/-0) tests/pending_reply.h (+49/-0) tests/test_apparmor.cpp (+162/-0) tests/test_apparmor.h (+51/-0) tests/test_download_manager.cpp (+279/-66) tests/test_download_manager.h (+8/-2) |
||||||||
To merge this branch: | bzr merge lp:~mandel/ubuntu-download-manager/filter-all-per-app | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Diego Sarmentero (community) | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Review via email:
|
Commit message
Ensure that the getAllDownloads* methods do filter per app id if the application is confined.
Description of the change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
- 258. By Manuel de la Peña
-
Merged db-store-owner into filter-all-per-app.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:258
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 259. By Manuel de la Peña
-
Merged db-store-owner into filter-all-per-app.
- 260. By Manuel de la Peña
-
Merged db-store-owner into filter-all-per-app.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:260
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 261. By Manuel de la Peña
-
Merged db-store-owner into filter-all-per-app.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:261
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'src/common/priv/CMakeLists.txt' |
2 | --- src/common/priv/CMakeLists.txt 2014-03-30 22:55:37 +0000 |
3 | +++ src/common/priv/CMakeLists.txt 2014-05-08 15:17:33 +0000 |
4 | @@ -11,6 +11,7 @@ |
5 | ubuntu/transfers/system/application.cpp |
6 | ubuntu/transfers/system/cryptographic_hash.cpp |
7 | ubuntu/transfers/system/dbus_proxy.cpp |
8 | + ubuntu/transfers/system/dbus_proxy_factory.cpp |
9 | ubuntu/transfers/system/file_manager.cpp |
10 | ubuntu/transfers/system/filename_mutex.cpp |
11 | ubuntu/transfers/system/network_reply.cpp |
12 | @@ -36,9 +37,11 @@ |
13 | ubuntu/transfers/system/application.h |
14 | ubuntu/transfers/system/cryptographic_hash.h |
15 | ubuntu/transfers/system/dbus_proxy.h |
16 | + ubuntu/transfers/system/dbus_proxy_factory.h |
17 | ubuntu/transfers/system/file_manager.h |
18 | ubuntu/transfers/system/filename_mutex.h |
19 | ubuntu/transfers/system/network_reply.h |
20 | + ubuntu/transfers/system/pending_reply.h |
21 | ubuntu/transfers/system/process.h |
22 | ubuntu/transfers/system/process_factory.h |
23 | ubuntu/transfers/system/request_factory.h |
24 | |
25 | === modified file 'src/common/priv/ubuntu/transfers/system/apparmor.cpp' |
26 | --- src/common/priv/ubuntu/transfers/system/apparmor.cpp 2014-05-08 15:17:33 +0000 |
27 | +++ src/common/priv/ubuntu/transfers/system/apparmor.cpp 2014-05-08 15:17:33 +0000 |
28 | @@ -26,8 +26,10 @@ |
29 | #include <QRegExp> |
30 | #include <QStandardPaths> |
31 | #include <ubuntu/transfers/system/logger.h> |
32 | +#include "apparmor.h" |
33 | +#include "dbus_proxy_factory.h" |
34 | +#include "pending_reply.h" |
35 | #include "uuid_utils.h" |
36 | -#include "apparmor.h" |
37 | |
38 | namespace Ubuntu { |
39 | |
40 | @@ -39,16 +41,14 @@ |
41 | |
42 | AppArmor::AppArmor(QObject* parent) |
43 | : QObject(parent) { |
44 | - _dbus = new DBusProxy("org.freedesktop.DBus", "/", |
45 | - QDBusConnection::sessionBus(), this); |
46 | + _dbus = DBusProxyFactory::instance()->createDBusProxy(this); |
47 | _uuidFactory = new UuidFactory(this); |
48 | } |
49 | |
50 | AppArmor::AppArmor(QSharedPointer<DBusConnection> connection, |
51 | QObject* parent) |
52 | : QObject(parent) { |
53 | - _dbus = new DBusProxy("org.freedesktop.DBus", "/", |
54 | - connection->connection(), this); |
55 | + _dbus = DBusProxyFactory::instance()->createDBusProxy(connection, this); |
56 | _uuidFactory = new UuidFactory(this); |
57 | } |
58 | |
59 | @@ -74,6 +74,26 @@ |
60 | return details; |
61 | } |
62 | |
63 | +QString |
64 | +AppArmor::appId(QString caller) { |
65 | + QScopedPointer<PendingReply<QString> > reply( |
66 | + _dbus->GetConnectionAppArmorSecurityContext(caller)); |
67 | + // blocking but should be ok for now |
68 | + reply->waitForFinished(); |
69 | + if (reply->isError()) { |
70 | + return ""; |
71 | + } |
72 | + return reply->value(); |
73 | +} |
74 | + |
75 | +bool |
76 | +AppArmor::isConfined(QString appId) { |
77 | + if (appId.isEmpty() || appId == UNCONFINED_ID) { |
78 | + return false; |
79 | + } |
80 | + return true; |
81 | +} |
82 | + |
83 | void |
84 | AppArmor::getSecurityDetails(const QString& connName, |
85 | SecurityDetails* details) { |
86 | @@ -84,19 +104,19 @@ |
87 | return; |
88 | } |
89 | |
90 | - QDBusPendingReply<QString> reply = |
91 | - _dbus->GetConnectionAppArmorSecurityContext(connName); |
92 | + QScopedPointer<PendingReply<QString> > reply ( |
93 | + _dbus->GetConnectionAppArmorSecurityContext(connName)); |
94 | // blocking but should be ok for now |
95 | - reply.waitForFinished(); |
96 | - if (reply.isError()) { |
97 | - LOG(ERROR) << reply.error(); |
98 | + reply->waitForFinished(); |
99 | + if (reply->isError()) { |
100 | + LOG(ERROR) << reply->error(); |
101 | details->dbusPath = QString(BASE_ACCOUNT_URL) + "/" + details->id; |
102 | details->localPath = getLocalPath(""); |
103 | details->isConfined = false; |
104 | return; |
105 | } else { |
106 | // use the returned value |
107 | - details->appId = reply.value(); |
108 | + details->appId = reply->value(); |
109 | |
110 | if (details->appId.isEmpty() || details->appId == UNCONFINED_ID) { |
111 | LOG(INFO) << "UNCONFINED APP"; |
112 | |
113 | === modified file 'src/common/priv/ubuntu/transfers/system/apparmor.h' |
114 | --- src/common/priv/ubuntu/transfers/system/apparmor.h 2014-05-08 15:17:33 +0000 |
115 | +++ src/common/priv/ubuntu/transfers/system/apparmor.h 2014-05-08 15:17:33 +0000 |
116 | @@ -58,6 +58,10 @@ |
117 | virtual SecurityDetails* getSecurityDetails(const QString& connName); |
118 | virtual SecurityDetails* getSecurityDetails(const QString& connName, |
119 | const QString& id); |
120 | + virtual QString appId(QString caller); |
121 | + virtual bool isConfined(QString appId); |
122 | + |
123 | + static QString UNCONFINED_ID; |
124 | |
125 | private: |
126 | void getSecurityDetails(const QString& connName, |
127 | @@ -66,7 +70,6 @@ |
128 | |
129 | private: |
130 | const char* BASE_ACCOUNT_URL = "/com/canonical/applications/download"; |
131 | - static QString UNCONFINED_ID; |
132 | |
133 | DBusProxy* _dbus; |
134 | UuidFactory* _uuidFactory; |
135 | |
136 | === modified file 'src/common/priv/ubuntu/transfers/system/dbus_proxy.h' |
137 | --- src/common/priv/ubuntu/transfers/system/dbus_proxy.h 2014-03-07 15:07:43 +0000 |
138 | +++ src/common/priv/ubuntu/transfers/system/dbus_proxy.h 2014-05-08 15:17:33 +0000 |
139 | @@ -19,8 +19,10 @@ |
140 | #include <QtCore/QStringList> |
141 | #include <QtCore/QVariant> |
142 | #include <QtDBus/QtDBus> |
143 | +#include "pending_reply.h" |
144 | |
145 | typedef QMap<QString, QString> StringMap; |
146 | +using namespace Ubuntu::Transfers::System; |
147 | |
148 | /* |
149 | * Proxy class for interface org.freedesktop.DBus |
150 | @@ -38,128 +40,132 @@ |
151 | ~DBusProxy(); |
152 | |
153 | public Q_SLOTS: // METHODS |
154 | - inline QDBusPendingReply<> AddMatch(const QString &in0) |
155 | + virtual QDBusPendingReply<> AddMatch(const QString &in0) |
156 | { |
157 | QList<QVariant> argumentList; |
158 | argumentList << QVariant::fromValue(in0); |
159 | return asyncCallWithArgumentList(QLatin1String("AddMatch"), argumentList); |
160 | } |
161 | |
162 | - inline QDBusPendingReply<QByteArray> GetAdtAuditSessionData(const QString &in0) |
163 | + virtual QDBusPendingReply<QByteArray> GetAdtAuditSessionData(const QString &in0) |
164 | { |
165 | QList<QVariant> argumentList; |
166 | argumentList << QVariant::fromValue(in0); |
167 | return asyncCallWithArgumentList(QLatin1String("GetAdtAuditSessionData"), argumentList); |
168 | } |
169 | |
170 | - inline QDBusPendingReply<QString> GetConnectionAppArmorSecurityContext(const QString &in0) |
171 | + virtual PendingReply<QString>* GetConnectionAppArmorSecurityContext(const QString &in0) |
172 | { |
173 | QList<QVariant> argumentList; |
174 | argumentList << QVariant::fromValue(in0); |
175 | - return asyncCallWithArgumentList(QLatin1String("GetConnectionAppArmorSecurityContext"), argumentList); |
176 | + QDBusPendingReply<QString> reply = asyncCallWithArgumentList( |
177 | + QLatin1String("GetConnectionAppArmorSecurityContext"), |
178 | + argumentList); |
179 | + auto wrapper = new PendingReply<QString>(reply); |
180 | + return wrapper; |
181 | } |
182 | |
183 | - inline QDBusPendingReply<QByteArray> GetConnectionSELinuxSecurityContext(const QString &in0) |
184 | + virtual QDBusPendingReply<QByteArray> GetConnectionSELinuxSecurityContext(const QString &in0) |
185 | { |
186 | QList<QVariant> argumentList; |
187 | argumentList << QVariant::fromValue(in0); |
188 | return asyncCallWithArgumentList(QLatin1String("GetConnectionSELinuxSecurityContext"), argumentList); |
189 | } |
190 | |
191 | - inline QDBusPendingReply<uint> GetConnectionUnixProcessID(const QString &in0) |
192 | + virtual QDBusPendingReply<uint> GetConnectionUnixProcessID(const QString &in0) |
193 | { |
194 | QList<QVariant> argumentList; |
195 | argumentList << QVariant::fromValue(in0); |
196 | return asyncCallWithArgumentList(QLatin1String("GetConnectionUnixProcessID"), argumentList); |
197 | } |
198 | |
199 | - inline QDBusPendingReply<uint> GetConnectionUnixUser(const QString &in0) |
200 | + virtual QDBusPendingReply<uint> GetConnectionUnixUser(const QString &in0) |
201 | { |
202 | QList<QVariant> argumentList; |
203 | argumentList << QVariant::fromValue(in0); |
204 | return asyncCallWithArgumentList(QLatin1String("GetConnectionUnixUser"), argumentList); |
205 | } |
206 | |
207 | - inline QDBusPendingReply<QString> GetId() |
208 | + virtual QDBusPendingReply<QString> GetId() |
209 | { |
210 | QList<QVariant> argumentList; |
211 | return asyncCallWithArgumentList(QLatin1String("GetId"), argumentList); |
212 | } |
213 | |
214 | - inline QDBusPendingReply<QString> GetNameOwner(const QString &in0) |
215 | + virtual QDBusPendingReply<QString> GetNameOwner(const QString &in0) |
216 | { |
217 | QList<QVariant> argumentList; |
218 | argumentList << QVariant::fromValue(in0); |
219 | return asyncCallWithArgumentList(QLatin1String("GetNameOwner"), argumentList); |
220 | } |
221 | |
222 | - inline QDBusPendingReply<QString> Hello() |
223 | + virtual QDBusPendingReply<QString> Hello() |
224 | { |
225 | QList<QVariant> argumentList; |
226 | return asyncCallWithArgumentList(QLatin1String("Hello"), argumentList); |
227 | } |
228 | |
229 | - inline QDBusPendingReply<QStringList> ListActivatableNames() |
230 | + virtual QDBusPendingReply<QStringList> ListActivatableNames() |
231 | { |
232 | QList<QVariant> argumentList; |
233 | return asyncCallWithArgumentList(QLatin1String("ListActivatableNames"), argumentList); |
234 | } |
235 | |
236 | - inline QDBusPendingReply<QStringList> ListNames() |
237 | + virtual QDBusPendingReply<QStringList> ListNames() |
238 | { |
239 | QList<QVariant> argumentList; |
240 | return asyncCallWithArgumentList(QLatin1String("ListNames"), argumentList); |
241 | } |
242 | |
243 | - inline QDBusPendingReply<QStringList> ListQueuedOwners(const QString &in0) |
244 | + virtual QDBusPendingReply<QStringList> ListQueuedOwners(const QString &in0) |
245 | { |
246 | QList<QVariant> argumentList; |
247 | argumentList << QVariant::fromValue(in0); |
248 | return asyncCallWithArgumentList(QLatin1String("ListQueuedOwners"), argumentList); |
249 | } |
250 | |
251 | - inline QDBusPendingReply<bool> NameHasOwner(const QString &in0) |
252 | + virtual QDBusPendingReply<bool> NameHasOwner(const QString &in0) |
253 | { |
254 | QList<QVariant> argumentList; |
255 | argumentList << QVariant::fromValue(in0); |
256 | return asyncCallWithArgumentList(QLatin1String("NameHasOwner"), argumentList); |
257 | } |
258 | |
259 | - inline QDBusPendingReply<uint> ReleaseName(const QString &in0) |
260 | + virtual QDBusPendingReply<uint> ReleaseName(const QString &in0) |
261 | { |
262 | QList<QVariant> argumentList; |
263 | argumentList << QVariant::fromValue(in0); |
264 | return asyncCallWithArgumentList(QLatin1String("ReleaseName"), argumentList); |
265 | } |
266 | |
267 | - inline QDBusPendingReply<> ReloadConfig() |
268 | + virtual QDBusPendingReply<> ReloadConfig() |
269 | { |
270 | QList<QVariant> argumentList; |
271 | return asyncCallWithArgumentList(QLatin1String("ReloadConfig"), argumentList); |
272 | } |
273 | |
274 | - inline QDBusPendingReply<> RemoveMatch(const QString &in0) |
275 | + virtual QDBusPendingReply<> RemoveMatch(const QString &in0) |
276 | { |
277 | QList<QVariant> argumentList; |
278 | argumentList << QVariant::fromValue(in0); |
279 | return asyncCallWithArgumentList(QLatin1String("RemoveMatch"), argumentList); |
280 | } |
281 | |
282 | - inline QDBusPendingReply<uint> RequestName(const QString &in0, uint in1) |
283 | + virtual QDBusPendingReply<uint> RequestName(const QString &in0, uint in1) |
284 | { |
285 | QList<QVariant> argumentList; |
286 | argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1); |
287 | return asyncCallWithArgumentList(QLatin1String("RequestName"), argumentList); |
288 | } |
289 | |
290 | - inline QDBusPendingReply<uint> StartServiceByName(const QString &in0, uint in1) |
291 | + virtual QDBusPendingReply<uint> StartServiceByName(const QString &in0, uint in1) |
292 | { |
293 | QList<QVariant> argumentList; |
294 | argumentList << QVariant::fromValue(in0) << QVariant::fromValue(in1); |
295 | return asyncCallWithArgumentList(QLatin1String("StartServiceByName"), argumentList); |
296 | } |
297 | |
298 | - inline QDBusPendingReply<> UpdateActivationEnvironment(StringMap in0) |
299 | + virtual QDBusPendingReply<> UpdateActivationEnvironment(StringMap in0) |
300 | { |
301 | QList<QVariant> argumentList; |
302 | argumentList << QVariant::fromValue(in0); |
303 | |
304 | === added file 'src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.cpp' |
305 | --- src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.cpp 1970-01-01 00:00:00 +0000 |
306 | +++ src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.cpp 2014-05-08 15:17:33 +0000 |
307 | @@ -0,0 +1,85 @@ |
308 | +/* |
309 | + * Copyright 2014 Canonical Ltd. |
310 | + * |
311 | + * This library is free software; you can redistribute it and/or |
312 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
313 | + * License as published by the Free Software Foundation. |
314 | + * |
315 | + * This program is distributed in the hope that it will be useful, |
316 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
317 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
318 | + * General Public License for more details. |
319 | + * |
320 | + * You should have received a copy of the GNU Lesser General Public |
321 | + * License along with this library; if not, write to the |
322 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
323 | + * Boston, MA 02110-1301, USA. |
324 | + */ |
325 | + |
326 | +#include <QDBusConnection> |
327 | +#include "dbus_proxy_factory.h" |
328 | + |
329 | +namespace { |
330 | + const QString DBUS_SERVICE_PATH = "org.freedesktop.DBus"; |
331 | + const QString DBUS_OBJECT_PATH = "/"; |
332 | +} |
333 | + |
334 | +namespace Ubuntu { |
335 | + |
336 | +namespace Transfers { |
337 | + |
338 | +namespace System { |
339 | + |
340 | +DBusProxyFactory* DBusProxyFactory::_instance = nullptr; |
341 | +QMutex DBusProxyFactory::_mutex; |
342 | + |
343 | +DBusProxyFactory::DBusProxyFactory(QObject* parent) |
344 | + : QObject(parent) { |
345 | +} |
346 | + |
347 | +DBusProxy* |
348 | +DBusProxyFactory::createDBusProxy(QObject* parent) { |
349 | + return new DBusProxy(DBUS_SERVICE_PATH, DBUS_OBJECT_PATH, |
350 | + QDBusConnection::sessionBus(), parent); |
351 | +} |
352 | + |
353 | +DBusProxy* |
354 | +DBusProxyFactory::createDBusProxy(QSharedPointer<DBusConnection> connection, |
355 | + QObject* parent) { |
356 | + return new DBusProxy(DBUS_SERVICE_PATH, DBUS_OBJECT_PATH, |
357 | + connection->connection(), parent); |
358 | +} |
359 | + |
360 | +DBusProxyFactory* |
361 | +DBusProxyFactory::instance() { |
362 | + if(_instance == nullptr) { |
363 | + _mutex.lock(); |
364 | + if(_instance == nullptr) |
365 | + _instance = new DBusProxyFactory(); |
366 | + _mutex.unlock(); |
367 | + } |
368 | + return _instance; |
369 | +} |
370 | + |
371 | +void |
372 | +DBusProxyFactory::setInstance(DBusProxyFactory* instance) { |
373 | + _instance = instance; |
374 | +} |
375 | + |
376 | +void |
377 | +DBusProxyFactory::deleteInstance() { |
378 | + if(_instance != nullptr) { |
379 | + _mutex.lock(); |
380 | + if(_instance != nullptr) { |
381 | + delete _instance; |
382 | + _instance = nullptr; |
383 | + } |
384 | + _mutex.unlock(); |
385 | + } |
386 | +} |
387 | + |
388 | +} // System |
389 | + |
390 | +} // Transfers |
391 | + |
392 | +} // Ubuntu |
393 | |
394 | === added file 'src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.h' |
395 | --- src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.h 1970-01-01 00:00:00 +0000 |
396 | +++ src/common/priv/ubuntu/transfers/system/dbus_proxy_factory.h 2014-05-08 15:17:33 +0000 |
397 | @@ -0,0 +1,62 @@ |
398 | +/* |
399 | + * Copyright 2014 Canonical Ltd. |
400 | + * |
401 | + * This library is free software; you can redistribute it and/or |
402 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
403 | + * License as published by the Free Software Foundation. |
404 | + * |
405 | + * This program is distributed in the hope that it will be useful, |
406 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
407 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
408 | + * General Public License for more details. |
409 | + * |
410 | + * You should have received a copy of the GNU Lesser General Public |
411 | + * License along with this library; if not, write to the |
412 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
413 | + * Boston, MA 02110-1301, USA. |
414 | + */ |
415 | + |
416 | +#ifndef DOWNLOADER_LIB_DBUS_PROXY_FACTORY_H |
417 | +#define DOWNLOADER_LIB_DBUS_PROXY_FACTORY_H |
418 | + |
419 | +#include <QSharedPointer> |
420 | +#include <QObject> |
421 | +#include <ubuntu/transfers/system/dbus_connection.h> |
422 | +#include "dbus_proxy.h" |
423 | + |
424 | +namespace Ubuntu { |
425 | + |
426 | +namespace Transfers { |
427 | + |
428 | +namespace System { |
429 | + |
430 | +class DBusProxyFactory : public QObject { |
431 | + Q_OBJECT |
432 | + |
433 | + public: |
434 | + virtual DBusProxy* createDBusProxy(QObject* parent=0); |
435 | + virtual DBusProxy* createDBusProxy( |
436 | + QSharedPointer<DBusConnection> connection, QObject* parent=0); |
437 | + |
438 | + static DBusProxyFactory* instance(); |
439 | + // only used for testing purposes |
440 | + static void setInstance(DBusProxyFactory* instance); |
441 | + static void deleteInstance(); |
442 | + |
443 | + protected: |
444 | + explicit DBusProxyFactory(QObject* parent=0); |
445 | + |
446 | + private: |
447 | + // used for the singleton |
448 | + static DBusProxyFactory* _instance; |
449 | + static QMutex _mutex; |
450 | +}; |
451 | + |
452 | +} // System |
453 | + |
454 | +} // Transfers |
455 | + |
456 | +} // Ubuntu |
457 | + |
458 | +#endif // DOWNLOADER_LIB_REQUEST_FACTORY_H |
459 | + |
460 | |
461 | === added file 'src/common/priv/ubuntu/transfers/system/pending_reply.cpp' |
462 | === added file 'src/common/priv/ubuntu/transfers/system/pending_reply.h' |
463 | --- src/common/priv/ubuntu/transfers/system/pending_reply.h 1970-01-01 00:00:00 +0000 |
464 | +++ src/common/priv/ubuntu/transfers/system/pending_reply.h 2014-05-08 15:17:33 +0000 |
465 | @@ -0,0 +1,74 @@ |
466 | +/* |
467 | + * Copyright 2014 Canonical Ltd. |
468 | + * |
469 | + * This library is free software; you can redistribute it and/or |
470 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
471 | + * License as published by the Free Software Foundation. |
472 | + * |
473 | + * This program is distributed in the hope that it will be useful, |
474 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
475 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
476 | + * General Public License for more details. |
477 | + * |
478 | + * You should have received a copy of the GNU Lesser General Public |
479 | + * License along with this library; if not, write to the |
480 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
481 | + * Boston, MA 02110-1301, USA. |
482 | + */ |
483 | + |
484 | +#ifndef DOWNLOADER_LIB_PENDING_REPLY_H |
485 | +#define DOWNLOADER_LIB_PENDING_REPLY_H |
486 | + |
487 | +#include <QDBusPendingReply> |
488 | + |
489 | +namespace Ubuntu { |
490 | + |
491 | +namespace Transfers { |
492 | + |
493 | +namespace System { |
494 | + |
495 | +template <class T> |
496 | +class PendingReply { |
497 | + public: |
498 | + PendingReply() { |
499 | + } |
500 | + |
501 | + PendingReply(const QDBusPendingReply<T>& reply) |
502 | + : _reply(reply) { |
503 | + } |
504 | + |
505 | + PendingReply(const PendingReply<T>& other) |
506 | + : _reply(other._reply) { |
507 | + } |
508 | + |
509 | + // added to help mocking |
510 | + virtual ~PendingReply() { |
511 | + } |
512 | + |
513 | + virtual T value () const { |
514 | + return _reply.value(); |
515 | + } |
516 | + |
517 | + virtual bool isError () const { |
518 | + return _reply.isError(); |
519 | + } |
520 | + |
521 | + virtual QDBusError error() const { |
522 | + return _reply.error(); |
523 | + } |
524 | + |
525 | + virtual void waitForFinished() { |
526 | + _reply.waitForFinished(); |
527 | + } |
528 | + |
529 | + private: |
530 | + QDBusPendingReply<T> _reply; |
531 | +}; |
532 | + |
533 | +} // System |
534 | + |
535 | +} // Transfers |
536 | + |
537 | +} // Ubuntu |
538 | + |
539 | +#endif // DOWNLOADER_LIB_PENDING_REPLY_H |
540 | |
541 | === modified file 'src/downloads/priv/ubuntu/downloads/manager.cpp' |
542 | --- src/downloads/priv/ubuntu/downloads/manager.cpp 2014-04-08 20:21:07 +0000 |
543 | +++ src/downloads/priv/ubuntu/downloads/manager.cpp 2014-05-08 15:17:33 +0000 |
544 | @@ -119,6 +119,19 @@ |
545 | emit sizeChanged(_downloadsQueue->size()); |
546 | } |
547 | |
548 | +QString |
549 | +DownloadManager::getCaller() { |
550 | + QString caller = ""; |
551 | + |
552 | + bool wasCalledFromDBus = calledFromDBus(); |
553 | + if (wasCalledFromDBus) { |
554 | + caller = connection().interface()->serviceOwner( |
555 | + message().service()); |
556 | + LOG(INFO) << "Owner is: " << caller; |
557 | + } |
558 | + return caller; |
559 | +} |
560 | + |
561 | QDBusObjectPath |
562 | DownloadManager::registerDownload(Download* download) { |
563 | download->setThrottle(_throttle); |
564 | @@ -143,18 +156,10 @@ |
565 | |
566 | QDBusObjectPath |
567 | DownloadManager::createDownload(DownloadCreationFunc createDownloadFunc) { |
568 | - QString owner = ""; |
569 | - |
570 | - bool wasCalledFromDBus = calledFromDBus(); |
571 | - if (wasCalledFromDBus) { |
572 | - owner = connection().interface()->serviceOwner( |
573 | - message().service()); |
574 | - LOG(INFO) << "Owner is: " << owner; |
575 | - } |
576 | - |
577 | - Download* download = createDownloadFunc(owner); |
578 | - |
579 | - if (wasCalledFromDBus && !download->isValid()) { |
580 | + auto owner = getCaller(); |
581 | + auto download = createDownloadFunc(owner); |
582 | + |
583 | + if (calledFromDBus() && !download->isValid()) { |
584 | sendErrorReply(QDBusError::InvalidArgs, download->lastError()); |
585 | // the result will be ignored thanks to the sendErrorReply |
586 | return QDBusObjectPath(); |
587 | @@ -257,15 +262,38 @@ |
588 | |
589 | QList<QDBusObjectPath> |
590 | DownloadManager::getAllDownloads() { |
591 | + // filter per app id if owner is not "" and the app is confined else |
592 | + // return all downloads |
593 | + QScopedPointer<System::AppArmor> appArmor(new System::AppArmor()); |
594 | + auto owner = getCaller(); |
595 | + auto appId = appArmor->appId(owner); |
596 | QList<QDBusObjectPath> paths; |
597 | - foreach(const QString& path, _downloadsQueue->paths()) |
598 | - paths << QDBusObjectPath(path); |
599 | + if (appArmor->isConfined(appId)) { |
600 | + LOG(INFO) << "Returning downloads for api with id" << appId; |
601 | + auto transfers = _downloadsQueue->transfers(); |
602 | + foreach(const QString& path, transfers.keys()) { |
603 | + auto t = transfers[path]; |
604 | + if (t->transferAppId() == appId) |
605 | + paths << QDBusObjectPath(path); |
606 | + } |
607 | + } else { |
608 | + LOG(INFO) << "Returning all downloads for unconfined app"; |
609 | + foreach(const QString& path, _downloadsQueue->paths()) |
610 | + paths << QDBusObjectPath(path); |
611 | + } |
612 | return paths; |
613 | } |
614 | |
615 | QList<QDBusObjectPath> |
616 | DownloadManager::getAllDownloadsWithMetadata(const QString &name, |
617 | const QString &value) { |
618 | + // filter per app id if owner is not "" and the app is confined else |
619 | + // return all downloads |
620 | + QScopedPointer<System::AppArmor> appArmor(new System::AppArmor()); |
621 | + auto owner = getCaller(); |
622 | + auto appId = appArmor->appId(owner); |
623 | + auto isConfined = appArmor->isConfined(appId); |
624 | + |
625 | QList<QDBusObjectPath> paths; |
626 | QHash<QString, Transfer*> downloads = _downloadsQueue->transfers(); |
627 | foreach(const QString& path, downloads.keys()) { |
628 | @@ -275,8 +303,11 @@ |
629 | if (metadata.contains(name)) { |
630 | QVariant data = metadata[name]; |
631 | if (data.canConvert(QMetaType::QString) |
632 | - && data.toString() == value) |
633 | - paths << QDBusObjectPath(path); |
634 | + && data.toString() == value) { |
635 | + if (!isConfined || appId == down->transferAppId()) { |
636 | + paths << QDBusObjectPath(path); |
637 | + } |
638 | + } |
639 | } |
640 | } |
641 | } |
642 | |
643 | === modified file 'src/downloads/priv/ubuntu/downloads/manager.h' |
644 | --- src/downloads/priv/ubuntu/downloads/manager.h 2014-03-28 15:50:24 +0000 |
645 | +++ src/downloads/priv/ubuntu/downloads/manager.h 2014-05-08 15:17:33 +0000 |
646 | @@ -98,7 +98,6 @@ |
647 | typedef std::function<Download*(QString)> DownloadCreationFunc; |
648 | |
649 | void init(); |
650 | - |
651 | void loadPreviewsDownloads(QString path); |
652 | void addDownload(Download* download); |
653 | QDBusObjectPath createDownload(DownloadCreationFunc createDownloadFunc); |
654 | @@ -108,6 +107,7 @@ |
655 | const QVariantMap& metadata, |
656 | StringMap headers); |
657 | void onDownloadsChanged(QString); |
658 | + QString getCaller(); |
659 | |
660 | private: |
661 | Application* _app = nullptr; |
662 | |
663 | === modified file 'tests/CMakeLists.txt' |
664 | --- tests/CMakeLists.txt 2014-03-27 12:54:03 +0000 |
665 | +++ tests/CMakeLists.txt 2014-05-08 15:17:33 +0000 |
666 | @@ -1,5 +1,6 @@ |
667 | set(DAEMON_TESTS |
668 | test_apn_request_factory |
669 | + test_apparmor |
670 | test_base_download |
671 | test_cancel_download_transition |
672 | test_daemon |
673 | @@ -35,6 +36,8 @@ |
674 | cryptographic_hash.h |
675 | database.h |
676 | dbus_connection.h |
677 | + dbus_proxy.h |
678 | + dbus_proxy_factory.h |
679 | download.h |
680 | factory.h |
681 | file_manager.h |
682 | @@ -42,6 +45,7 @@ |
683 | manager.h |
684 | matchers.h |
685 | network_reply.h |
686 | + pending_reply.h |
687 | process.h |
688 | process_factory.h |
689 | queue.h |
690 | @@ -114,6 +118,7 @@ |
691 | ${GLOG_LIBRARIES} |
692 | ${Qt5Core_LIBRARIES} |
693 | ${Qt5Sql_LIBRARIES} |
694 | + ${Qt5DBus_LIBRARIES} |
695 | ${Qt5Test_LIBRARIES} |
696 | ${GMOCK_LIBRARY} |
697 | ${GTEST_BOTH_LIBRARIES} |
698 | |
699 | === modified file 'tests/apparmor.h' |
700 | --- tests/apparmor.h 2014-03-12 16:18:31 +0000 |
701 | +++ tests/apparmor.h 2014-05-08 15:17:33 +0000 |
702 | @@ -37,6 +37,8 @@ |
703 | SecurityDetails*(const QString&)); |
704 | MOCK_METHOD2(getSecurityDetails, |
705 | SecurityDetails*(const QString&, const QString&)); |
706 | + MOCK_METHOD1(appId, QString(QString caller)); |
707 | + MOCK_METHOD1(isConfined, bool(QString appId)); |
708 | }; |
709 | |
710 | } // Ubuntu |
711 | |
712 | === added file 'tests/dbus_proxy.h' |
713 | --- tests/dbus_proxy.h 1970-01-01 00:00:00 +0000 |
714 | +++ tests/dbus_proxy.h 2014-05-08 15:17:33 +0000 |
715 | @@ -0,0 +1,74 @@ |
716 | +/* |
717 | + * Copyright 2014 Canonical Ltd. |
718 | + * |
719 | + * This library is free software; you can redistribute it and/or |
720 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
721 | + * License as published by the Free Software Foundation. |
722 | + * |
723 | + * This program is distributed in the hope that it will be useful, |
724 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
725 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
726 | + * General Public License for more details. |
727 | + * |
728 | + * You should have received a copy of the GNU Lesser General Public |
729 | + * License along with this library; if not, write to the |
730 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
731 | + * Boston, MA 02110-1301, USA. |
732 | + */ |
733 | + |
734 | +#ifndef FAKE_DBUS_PROXY_H |
735 | +#define FAKE_DBUS_PROXY_H |
736 | + |
737 | +#include <ubuntu/transfers/system/dbus_proxy.h> |
738 | +#include <gmock/gmock.h> |
739 | + |
740 | +namespace Ubuntu { |
741 | + |
742 | +namespace Transfers { |
743 | + |
744 | +using namespace System; |
745 | + |
746 | +namespace Tests { |
747 | + |
748 | +class MockDBusProxy : public DBusProxy { |
749 | + public: |
750 | + MockDBusProxy() : DBusProxy("", "", QDBusConnection::sessionBus()) {} |
751 | + |
752 | + MOCK_METHOD1(AddMatch, QDBusPendingReply<>(const QString&)); |
753 | + MOCK_METHOD1(GetAdtAuditSessionData, |
754 | + QDBusPendingReply<QByteArray>(const QString&)); |
755 | + MOCK_METHOD1(GetConnectionAppArmorSecurityContext, |
756 | + PendingReply<QString>*(const QString&)); |
757 | + MOCK_METHOD1(GetConnectionSELinuxSecurityContext, |
758 | + QDBusPendingReply<QByteArray>(const QString&)); |
759 | + MOCK_METHOD1(GetConnectionUnixProcessID, |
760 | + QDBusPendingReply<uint>(const QString&)); |
761 | + MOCK_METHOD1(GetConnectionUnixUser, |
762 | + QDBusPendingReply<uint>(const QString&)); |
763 | + MOCK_METHOD0(GetId, QDBusPendingReply<QString>()); |
764 | + MOCK_METHOD1(GetNameOwner, |
765 | + QDBusPendingReply<QString>(const QString&)); |
766 | + MOCK_METHOD0(Hello, QDBusPendingReply<QString>()); |
767 | + MOCK_METHOD0(ListActivatableNames, QDBusPendingReply<QStringList>()); |
768 | + MOCK_METHOD0(ListNames, QDBusPendingReply<QStringList>()); |
769 | + MOCK_METHOD1(ListQueuedOwners, |
770 | + QDBusPendingReply<QStringList>(const QString&)); |
771 | + MOCK_METHOD1(NameHasOwner, QDBusPendingReply<bool>(const QString&)); |
772 | + MOCK_METHOD1(ReleaseName, QDBusPendingReply<uint>(const QString&)); |
773 | + MOCK_METHOD0(ReloadConfig, QDBusPendingReply<>()); |
774 | + MOCK_METHOD1(RemoveMatch, QDBusPendingReply<>(const QString&)); |
775 | + MOCK_METHOD2(RequestName, |
776 | + QDBusPendingReply<uint>(const QString&, uint)); |
777 | + MOCK_METHOD2(StartServiceByName, |
778 | + QDBusPendingReply<uint>(const QString&, uint)); |
779 | + MOCK_METHOD1(UpdateActivationEnvironment, |
780 | + QDBusPendingReply<>(StringMap)); |
781 | +}; |
782 | + |
783 | +} // Ubuntu |
784 | + |
785 | +} // Transfers |
786 | + |
787 | +} // Tests |
788 | + |
789 | +#endif // FAKE_DBUS_PROXY_H |
790 | |
791 | === added file 'tests/dbus_proxy_factory.h' |
792 | --- tests/dbus_proxy_factory.h 1970-01-01 00:00:00 +0000 |
793 | +++ tests/dbus_proxy_factory.h 2014-05-08 15:17:33 +0000 |
794 | @@ -0,0 +1,46 @@ |
795 | +/* |
796 | + * Copyright 2014 Canonical Ltd. |
797 | + * |
798 | + * This library is free software; you can redistribute it and/or |
799 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
800 | + * License as published by the Free Software Foundation. |
801 | + * |
802 | + * This program is distributed in the hope that it will be useful, |
803 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
804 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
805 | + * General Public License for more details. |
806 | + * |
807 | + * You should have received a copy of the GNU Lesser General Public |
808 | + * License along with this library; if not, write to the |
809 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
810 | + * Boston, MA 02110-1301, USA. |
811 | + */ |
812 | + |
813 | +#ifndef FAKE_DBUS_PROXY_FACTORY_H |
814 | +#define FAKE_DBUS_PROXY_FACTORY_H |
815 | + |
816 | +#include <ubuntu/transfers/system/dbus_proxy_factory.h> |
817 | +#include <gmock/gmock.h> |
818 | + |
819 | +namespace Ubuntu { |
820 | + |
821 | +namespace Transfers { |
822 | + |
823 | +using namespace System; |
824 | + |
825 | +namespace Tests { |
826 | + |
827 | +class MockDBusProxyFactory : public DBusProxyFactory { |
828 | + public: |
829 | + MOCK_METHOD1(createDBusProxy, DBusProxy*(QObject*)); |
830 | + MOCK_METHOD2(createDBusProxy, |
831 | + DBusProxy*(QSharedPointer<DBusConnection>, QObject*)); |
832 | +}; |
833 | + |
834 | +} // Ubuntu |
835 | + |
836 | +} // Transfers |
837 | + |
838 | +} // Tests |
839 | + |
840 | +#endif // FAKE_DBUS_PROXY_FACTORY_H |
841 | |
842 | === modified file 'tests/download.h' |
843 | --- tests/download.h 2014-05-08 15:17:33 +0000 |
844 | +++ tests/download.h 2014-05-08 15:17:33 +0000 |
845 | @@ -89,6 +89,7 @@ |
846 | MOCK_CONST_METHOD0(state, Transfer::State()); |
847 | MOCK_CONST_METHOD0(path, QString()); |
848 | MOCK_CONST_METHOD0(metadata, QVariantMap()); |
849 | + MOCK_CONST_METHOD0(transferAppId, QString()); |
850 | MOCK_METHOD1(allowGSMDownload, void(bool)); |
851 | MOCK_METHOD0(isGSMDownloadAllowed, bool()); |
852 | |
853 | |
854 | === added file 'tests/pending_reply.h' |
855 | --- tests/pending_reply.h 1970-01-01 00:00:00 +0000 |
856 | +++ tests/pending_reply.h 2014-05-08 15:17:33 +0000 |
857 | @@ -0,0 +1,49 @@ |
858 | +/* |
859 | + * Copyright 2014 Canonical Ltd. |
860 | + * |
861 | + * This library is free software; you can redistribute it and/or |
862 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
863 | + * License as published by the Free Software Foundation. |
864 | + * |
865 | + * This program is distributed in the hope that it will be useful, |
866 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
867 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
868 | + * General Public License for more details. |
869 | + * |
870 | + * You should have received a copy of the GNU Lesser General Public |
871 | + * License along with this library; if not, write to the |
872 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
873 | + * Boston, MA 02110-1301, USA. |
874 | + */ |
875 | + |
876 | +#ifndef FAKE_PENDING_REPLY_H |
877 | +#define FAKE_PENDING_REPLY_H |
878 | + |
879 | +#include <ubuntu/transfers/system/pending_reply.h> |
880 | +#include <gmock/gmock.h> |
881 | + |
882 | +namespace Ubuntu { |
883 | + |
884 | +namespace Transfers { |
885 | + |
886 | +using namespace System; |
887 | + |
888 | +namespace Tests { |
889 | + |
890 | +template <class T> |
891 | +class MockPendingReply : public PendingReply<T> { |
892 | + public: |
893 | + MOCK_CONST_METHOD0_T(value, T()); |
894 | + MOCK_CONST_METHOD0_T(isError, bool()); |
895 | + MOCK_CONST_METHOD0_T(error, QDBusError()); |
896 | + MOCK_METHOD0_T(waitForFinished, void()); |
897 | +}; |
898 | + |
899 | +} // Ubuntu |
900 | + |
901 | +} // Transfers |
902 | + |
903 | +} // Tests |
904 | + |
905 | +#endif // FAKE_DBUS_PROXY_H |
906 | + |
907 | |
908 | === added file 'tests/test_apparmor.cpp' |
909 | --- tests/test_apparmor.cpp 1970-01-01 00:00:00 +0000 |
910 | +++ tests/test_apparmor.cpp 2014-05-08 15:17:33 +0000 |
911 | @@ -0,0 +1,162 @@ |
912 | +/* |
913 | + * Copyright 2014 Canonical Ltd. |
914 | + * |
915 | + * This library is free software; you can redistribute it and/or |
916 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
917 | + * License as published by the Free Software Foundation. |
918 | + * |
919 | + * This program is distributed in the hope that it will be useful, |
920 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
921 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
922 | + * General Public License for more details. |
923 | + * |
924 | + * You should have received a copy of the GNU Lesser General Public |
925 | + * License along with this library; if not, write to the |
926 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
927 | + * Boston, MA 02110-1301, USA. |
928 | + */ |
929 | + |
930 | +#include <QDBusMessage> |
931 | +#include <QScopedPointer> |
932 | +#include <ubuntu/transfers/system/apparmor.h> |
933 | +#include "dbus_proxy.h" |
934 | +#include "pending_reply.h" |
935 | +#include "test_apparmor.h" |
936 | + |
937 | +using ::testing::_; |
938 | +using ::testing::ByRef; |
939 | +using ::testing::Mock; |
940 | +using ::testing::Return; |
941 | + |
942 | +void |
943 | +TestAppArmor::init() { |
944 | + BaseTestCase::init(); |
945 | + _dbusProxyFactory = new MockDBusProxyFactory(); |
946 | + DBusProxyFactory::setInstance(_dbusProxyFactory ); |
947 | +} |
948 | + |
949 | +void |
950 | +TestAppArmor::cleanup() { |
951 | + BaseTestCase::cleanup(); |
952 | + DBusProxyFactory::deleteInstance(); |
953 | +} |
954 | + |
955 | +void |
956 | +TestAppArmor::testAppIdError() { |
957 | + QString caller = "my app"; |
958 | + auto dbusProxy = new MockDBusProxy(); |
959 | + auto reply = new MockPendingReply<QString>(); |
960 | + |
961 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
962 | + .Times(1) |
963 | + .WillOnce(Return(dbusProxy)); |
964 | + |
965 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(caller)) |
966 | + .Times(1) |
967 | + .WillOnce(Return(reply)); |
968 | + |
969 | + EXPECT_CALL(*reply, waitForFinished()) |
970 | + .Times(1); |
971 | + |
972 | + EXPECT_CALL(*reply, isError()) |
973 | + .Times(1) |
974 | + .WillOnce(Return(true)); |
975 | + |
976 | + QScopedPointer<AppArmor> appArmor(new AppArmor()); |
977 | + |
978 | + auto appId = appArmor->appId(caller); |
979 | + QCOMPARE(QString(), appId); |
980 | + |
981 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
982 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
983 | +} |
984 | + |
985 | +void |
986 | +TestAppArmor::testAppId() { |
987 | + QString caller = "my app"; |
988 | + QString expectedAppId = "APPID"; |
989 | + auto dbusProxy = new MockDBusProxy(); |
990 | + auto reply = new MockPendingReply<QString>(); |
991 | + |
992 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
993 | + .Times(1) |
994 | + .WillOnce(Return(dbusProxy)); |
995 | + |
996 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(caller)) |
997 | + .Times(1) |
998 | + .WillOnce(Return(reply)); |
999 | + |
1000 | + EXPECT_CALL(*reply, waitForFinished()) |
1001 | + .Times(1); |
1002 | + |
1003 | + EXPECT_CALL(*reply, isError()) |
1004 | + .Times(1) |
1005 | + .WillOnce(Return(false)); |
1006 | + |
1007 | + EXPECT_CALL(*reply, value()) |
1008 | + .Times(1) |
1009 | + .WillOnce(Return(expectedAppId)); |
1010 | + |
1011 | + QScopedPointer<AppArmor> appArmor(new AppArmor()); |
1012 | + |
1013 | + auto appId = appArmor->appId(caller); |
1014 | + QCOMPARE(expectedAppId, appId); |
1015 | + |
1016 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1017 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
1018 | +} |
1019 | + |
1020 | +void |
1021 | +TestAppArmor::testIsConfinedEmptyString() { |
1022 | + QString caller = ""; |
1023 | + auto dbusProxy = new MockDBusProxy(); |
1024 | + |
1025 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1026 | + .Times(1) |
1027 | + .WillOnce(Return(dbusProxy)); |
1028 | + |
1029 | + QScopedPointer<AppArmor> appArmor(new AppArmor()); |
1030 | + bool isConfined = appArmor->isConfined(caller); |
1031 | + |
1032 | + QVERIFY(!isConfined); |
1033 | + |
1034 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1035 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
1036 | +} |
1037 | + |
1038 | +void |
1039 | +TestAppArmor::testIsConfinedUnconfinedString() { |
1040 | + auto dbusProxy = new MockDBusProxy(); |
1041 | + |
1042 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1043 | + .Times(1) |
1044 | + .WillOnce(Return(dbusProxy)); |
1045 | + |
1046 | + QScopedPointer<AppArmor> appArmor(new AppArmor()); |
1047 | + bool isConfined = appArmor->isConfined(AppArmor::UNCONFINED_ID); |
1048 | + |
1049 | + QVERIFY(!isConfined); |
1050 | + |
1051 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1052 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
1053 | +} |
1054 | + |
1055 | +void |
1056 | +TestAppArmor::testIsConfinedAppIdString() { |
1057 | + QString caller = "APPID"; |
1058 | + auto dbusProxy = new MockDBusProxy(); |
1059 | + |
1060 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1061 | + .Times(1) |
1062 | + .WillOnce(Return(dbusProxy)); |
1063 | + |
1064 | + QScopedPointer<AppArmor> appArmor(new AppArmor()); |
1065 | + bool isConfined = appArmor->isConfined(caller); |
1066 | + |
1067 | + QVERIFY(isConfined); |
1068 | + |
1069 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1070 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
1071 | +} |
1072 | + |
1073 | +QTEST_MAIN(TestAppArmor) |
1074 | |
1075 | === added file 'tests/test_apparmor.h' |
1076 | --- tests/test_apparmor.h 1970-01-01 00:00:00 +0000 |
1077 | +++ tests/test_apparmor.h 2014-05-08 15:17:33 +0000 |
1078 | @@ -0,0 +1,51 @@ |
1079 | +/* |
1080 | + * Copyright 2014 Canonical Ltd. |
1081 | + * |
1082 | + * This library is free software; you can redistribute it and/or |
1083 | + * modify it under the terms of version 3 of the GNU Lesser General Public |
1084 | + * License as published by the Free Software Foundation. |
1085 | + * |
1086 | + * This program is distributed in the hope that it will be useful, |
1087 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1088 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1089 | + * General Public License for more details. |
1090 | + * |
1091 | + * You should have received a copy of the GNU Lesser General Public |
1092 | + * License along with this library; if not, write to the |
1093 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
1094 | + * Boston, MA 02110-1301, USA. |
1095 | + */ |
1096 | + |
1097 | +#ifndef TEST_APPARMOR_H |
1098 | +#define TEST_APPARMOR_H |
1099 | + |
1100 | +#include <QObject> |
1101 | +#include "base_testcase.h" |
1102 | +#include "dbus_proxy_factory.h" |
1103 | + |
1104 | +using namespace Ubuntu::Transfers::Tests; |
1105 | +using namespace Ubuntu::Transfers::System; |
1106 | + |
1107 | +class TestAppArmor : public BaseTestCase { |
1108 | + Q_OBJECT |
1109 | + |
1110 | +public: |
1111 | + explicit TestAppArmor(QObject *parent = 0) |
1112 | + : BaseTestCase("TestAppArmor", parent) { } |
1113 | + |
1114 | + private slots: // NOLINT(whitespace/indent) |
1115 | + |
1116 | + void init() override; |
1117 | + void cleanup() override; |
1118 | + |
1119 | + void testAppIdError(); |
1120 | + void testAppId(); |
1121 | + void testIsConfinedEmptyString(); |
1122 | + void testIsConfinedUnconfinedString(); |
1123 | + void testIsConfinedAppIdString(); |
1124 | + |
1125 | + private: |
1126 | + MockDBusProxyFactory* _dbusProxyFactory; |
1127 | +}; |
1128 | + |
1129 | +#endif // TEST_APN_REQUEST_FACTORY_H |
1130 | |
1131 | === modified file 'tests/test_download_manager.cpp' |
1132 | --- tests/test_download_manager.cpp 2014-04-08 12:44:15 +0000 |
1133 | +++ tests/test_download_manager.cpp 2014-05-08 15:17:33 +0000 |
1134 | @@ -22,8 +22,10 @@ |
1135 | #include <ubuntu/transfers/system/process_factory.h> |
1136 | #include <ubuntu/transfers/system/system_network_info.h> |
1137 | #include <gmock/gmock.h> |
1138 | +#include "dbus_proxy.h" |
1139 | #include "download.h" |
1140 | #include "matchers.h" |
1141 | +#include "pending_reply.h" |
1142 | #include "test_download_manager.h" |
1143 | |
1144 | using ::testing::_; |
1145 | @@ -43,8 +45,9 @@ |
1146 | _requestFactory = new MockRequestFactory(); |
1147 | RequestFactory::setInstance(_requestFactory); |
1148 | _factory = new MockDownloadFactory(); |
1149 | - qDebug() << "MOCK QUEUE" << _q; |
1150 | _man = new DownloadManager(_app, _conn, _factory, _q); |
1151 | + _dbusProxyFactory = new MockDBusProxyFactory(); |
1152 | + DBusProxyFactory::setInstance(_dbusProxyFactory ); |
1153 | } |
1154 | |
1155 | void |
1156 | @@ -55,6 +58,7 @@ |
1157 | RequestFactory::deleteInstance(); |
1158 | ProcessFactory::deleteInstance(); |
1159 | DownloadsDb::deleteInstance(); |
1160 | + DBusProxyFactory::deleteInstance(); |
1161 | delete _man; |
1162 | delete _conn; |
1163 | delete _app; |
1164 | @@ -68,6 +72,7 @@ |
1165 | QVERIFY(Mock::VerifyAndClearExpectations(_factory)); |
1166 | QVERIFY(Mock::VerifyAndClearExpectations(_q)); |
1167 | QVERIFY(Mock::VerifyAndClearExpectations(_requestFactory)); |
1168 | + QVERIFY(Mock::VerifyAndClearExpectations(_dbusProxyFactory)); |
1169 | } |
1170 | |
1171 | QCryptographicHash::Algorithm |
1172 | @@ -277,71 +282,6 @@ |
1173 | } |
1174 | |
1175 | void |
1176 | -TestDownloadManager::testGetAllDownloads() { |
1177 | - // assert that we return the downloads from the q |
1178 | - QStringList expectedPaths; |
1179 | - expectedPaths.append("/first/path/object"); |
1180 | - expectedPaths.append("/second/path/object"); |
1181 | - expectedPaths.append("/third/path/object"); |
1182 | - |
1183 | - EXPECT_CALL(*_q, paths()) |
1184 | - .Times(1) |
1185 | - .WillRepeatedly(Return(expectedPaths)); |
1186 | - |
1187 | - auto result = _man->getAllDownloads(); |
1188 | - foreach(auto path, result) { |
1189 | - QVERIFY(expectedPaths.contains(path.path())); |
1190 | - } |
1191 | - |
1192 | - verifyMocks(); |
1193 | -} |
1194 | - |
1195 | -void |
1196 | -TestDownloadManager::testAllDownloadsWithMetadata() { |
1197 | - auto key = QString("filter"); |
1198 | - auto value = QString("coconut"); |
1199 | - auto validPath = QString("/valid/metadata/path"); |
1200 | - |
1201 | - QVariantMap filteredMetadata; |
1202 | - filteredMetadata[key] = value; |
1203 | - QVariantMap metadata; |
1204 | - QMap<QString, QString> headers; |
1205 | - |
1206 | - QScopedPointer<MockDownload> first(new MockDownload("", "", "", "", |
1207 | - QUrl("http://one.ubunt.com"), metadata, headers)); |
1208 | - QScopedPointer<MockDownload> second(new MockDownload("", "", "", "", |
1209 | - QUrl("http://ubuntu.com"), metadata, headers)); |
1210 | - QScopedPointer<MockDownload> third(new MockDownload("", "", "", "", |
1211 | - QUrl("http://reddit.com"), metadata, headers)); |
1212 | - QHash<QString, Transfer*> downs; |
1213 | - downs[validPath] = first.data(); |
1214 | - downs["/second/object/path"] = second.data(); |
1215 | - downs["/third/object/path"] = third.data(); |
1216 | - |
1217 | - EXPECT_CALL(*first.data(), metadata()) |
1218 | - .Times(1) |
1219 | - .WillRepeatedly(Return(filteredMetadata)); |
1220 | - |
1221 | - EXPECT_CALL(*second.data(), metadata()) |
1222 | - .Times(1) |
1223 | - .WillRepeatedly(Return(metadata)); |
1224 | - |
1225 | - EXPECT_CALL(*third.data(), metadata()) |
1226 | - .Times(1) |
1227 | - .WillRepeatedly(Return(metadata)); |
1228 | - |
1229 | - EXPECT_CALL(*_q, transfers()) |
1230 | - .Times(1) |
1231 | - .WillRepeatedly(Return(downs)); |
1232 | - |
1233 | - auto result = _man->getAllDownloadsWithMetadata(key, value); |
1234 | - QCOMPARE(1, result.count()); |
1235 | - QCOMPARE(result[0].path(), validPath); |
1236 | - |
1237 | - verifyMocks(); |
1238 | -} |
1239 | - |
1240 | -void |
1241 | TestDownloadManager::testSetThrottleNotDownloads_data() { |
1242 | QTest::addColumn<qulonglong>("speed"); |
1243 | |
1244 | @@ -510,4 +450,277 @@ |
1245 | verifyMocks(); |
1246 | } |
1247 | |
1248 | +void |
1249 | +TestDownloadManager::testGetAllDownloadsUnconfined() { |
1250 | + QString expectedAppId = "unconfined"; |
1251 | + auto dbusProxy = new MockDBusProxy(); |
1252 | + auto reply = new MockPendingReply<QString>(); |
1253 | + |
1254 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1255 | + .Times(1) |
1256 | + .WillOnce(Return(dbusProxy)); |
1257 | + |
1258 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(_)) |
1259 | + .Times(1) |
1260 | + .WillOnce(Return(reply)); |
1261 | + |
1262 | + EXPECT_CALL(*reply, waitForFinished()) |
1263 | + .Times(1); |
1264 | + |
1265 | + EXPECT_CALL(*reply, isError()) |
1266 | + .Times(1) |
1267 | + .WillOnce(Return(false)); |
1268 | + |
1269 | + EXPECT_CALL(*reply, value()) |
1270 | + .Times(1) |
1271 | + .WillOnce(Return(expectedAppId)); |
1272 | + |
1273 | + QStringList expectedPaths; |
1274 | + expectedPaths.append("/first/path/object"); |
1275 | + expectedPaths.append("/second/path/object"); |
1276 | + expectedPaths.append("/third/path/object"); |
1277 | + |
1278 | + EXPECT_CALL(*_q, paths()) |
1279 | + .Times(1) |
1280 | + .WillRepeatedly(Return(expectedPaths)); |
1281 | + |
1282 | + auto result = _man->getAllDownloads(); |
1283 | + QCOMPARE(3, result.count()); |
1284 | + foreach(auto path, result) { |
1285 | + QVERIFY(expectedPaths.contains(path.path())); |
1286 | + } |
1287 | + |
1288 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1289 | + verifyMocks(); |
1290 | +} |
1291 | + |
1292 | +void |
1293 | +TestDownloadManager::testGetAllDownloadsConfined() { |
1294 | + QString expectedAppId = "APPID"; |
1295 | + auto dbusProxy = new MockDBusProxy(); |
1296 | + auto reply = new MockPendingReply<QString>(); |
1297 | + |
1298 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1299 | + .Times(1) |
1300 | + .WillOnce(Return(dbusProxy)); |
1301 | + |
1302 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(_)) |
1303 | + .Times(1) |
1304 | + .WillOnce(Return(reply)); |
1305 | + |
1306 | + EXPECT_CALL(*reply, waitForFinished()) |
1307 | + .Times(1); |
1308 | + |
1309 | + EXPECT_CALL(*reply, isError()) |
1310 | + .Times(1) |
1311 | + .WillOnce(Return(false)); |
1312 | + |
1313 | + EXPECT_CALL(*reply, value()) |
1314 | + .Times(1) |
1315 | + .WillOnce(Return(expectedAppId)); |
1316 | + |
1317 | + // create several downloads with diff app ids to check that we |
1318 | + // do getonly those with the correct app id |
1319 | + QVariantMap metadata; |
1320 | + QMap<QString, QString> headers; |
1321 | + QScopedPointer<MockDownload> first(new MockDownload("", "", "", "", |
1322 | + QUrl("http://one.ubunt.com"), metadata, headers)); |
1323 | + QScopedPointer<MockDownload> second(new MockDownload("", "", "", "", |
1324 | + QUrl("http://ubuntu.com"), metadata, headers)); |
1325 | + QScopedPointer<MockDownload> third(new MockDownload("", "", "", "", |
1326 | + QUrl("http://reddit.com"), metadata, headers)); |
1327 | + |
1328 | + QHash<QString, Transfer*> downs; |
1329 | + QStringList paths; |
1330 | + paths.append("/first/path/object"); |
1331 | + paths.append("/second/path/object"); |
1332 | + paths.append("/third/path/object"); |
1333 | + |
1334 | + downs[paths[0]] = first.data(); |
1335 | + downs[paths[1]] = second.data(); |
1336 | + downs[paths[2]] = third.data(); |
1337 | + |
1338 | + EXPECT_CALL(*first.data(), transferAppId()) |
1339 | + .Times(1) |
1340 | + .WillRepeatedly(Return(expectedAppId)); |
1341 | + |
1342 | + EXPECT_CALL(*second.data(), transferAppId()) |
1343 | + .Times(1) |
1344 | + .WillRepeatedly(Return(QString("SECONDAPP"))); |
1345 | + |
1346 | + EXPECT_CALL(*third.data(), transferAppId()) |
1347 | + .Times(1) |
1348 | + .WillRepeatedly(Return(QString("LASTAPP"))); |
1349 | + |
1350 | + EXPECT_CALL(*_q, transfers()) |
1351 | + .Times(1) |
1352 | + .WillRepeatedly(Return(downs)); |
1353 | + |
1354 | + auto result = _man->getAllDownloads(); |
1355 | + QCOMPARE(1, result.count()); |
1356 | + |
1357 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1358 | + verifyMocks(); |
1359 | +} |
1360 | + |
1361 | +void |
1362 | +TestDownloadManager::testAllDownloadsWithMetadataUnconfined() { |
1363 | + QString expectedAppId = "unconfined"; |
1364 | + auto dbusProxy = new MockDBusProxy(); |
1365 | + auto reply = new MockPendingReply<QString>(); |
1366 | + |
1367 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1368 | + .Times(1) |
1369 | + .WillOnce(Return(dbusProxy)); |
1370 | + |
1371 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(_)) |
1372 | + .Times(1) |
1373 | + .WillOnce(Return(reply)); |
1374 | + |
1375 | + EXPECT_CALL(*reply, waitForFinished()) |
1376 | + .Times(1); |
1377 | + |
1378 | + EXPECT_CALL(*reply, isError()) |
1379 | + .Times(1) |
1380 | + .WillOnce(Return(false)); |
1381 | + |
1382 | + EXPECT_CALL(*reply, value()) |
1383 | + .Times(1) |
1384 | + .WillOnce(Return(expectedAppId)); |
1385 | + |
1386 | + // create downloads to be used to filter |
1387 | + auto key = QString("filter"); |
1388 | + auto value = QString("coconut"); |
1389 | + auto validPath = QString("/valid/metadata/path"); |
1390 | + |
1391 | + QVariantMap filteredMetadata; |
1392 | + filteredMetadata[key] = value; |
1393 | + QVariantMap metadata; |
1394 | + QMap<QString, QString> headers; |
1395 | + |
1396 | + QScopedPointer<MockDownload> first(new MockDownload("", "", "", "", |
1397 | + QUrl("http://one.ubunt.com"), metadata, headers)); |
1398 | + QScopedPointer<MockDownload> second(new MockDownload("", "", "", "", |
1399 | + QUrl("http://ubuntu.com"), metadata, headers)); |
1400 | + QScopedPointer<MockDownload> third(new MockDownload("", "", "", "", |
1401 | + QUrl("http://reddit.com"), metadata, headers)); |
1402 | + QHash<QString, Transfer*> downs; |
1403 | + downs[validPath] = first.data(); |
1404 | + downs["/second/object/path"] = second.data(); |
1405 | + downs["/third/object/path"] = third.data(); |
1406 | + |
1407 | + EXPECT_CALL(*first.data(), metadata()) |
1408 | + .Times(1) |
1409 | + .WillRepeatedly(Return(filteredMetadata)); |
1410 | + |
1411 | + EXPECT_CALL(*first.data(), transferAppId()) |
1412 | + .Times(0); |
1413 | + |
1414 | + EXPECT_CALL(*second.data(), metadata()) |
1415 | + .Times(1) |
1416 | + .WillRepeatedly(Return(metadata)); |
1417 | + |
1418 | + EXPECT_CALL(*second.data(), transferAppId()) |
1419 | + .Times(0); |
1420 | + |
1421 | + EXPECT_CALL(*third.data(), metadata()) |
1422 | + .Times(1) |
1423 | + .WillRepeatedly(Return(metadata)); |
1424 | + |
1425 | + EXPECT_CALL(*third.data(), transferAppId()) |
1426 | + .Times(0); |
1427 | + |
1428 | + EXPECT_CALL(*_q, transfers()) |
1429 | + .Times(1) |
1430 | + .WillRepeatedly(Return(downs)); |
1431 | + |
1432 | + auto result = _man->getAllDownloadsWithMetadata(key, value); |
1433 | + QCOMPARE(1, result.count()); |
1434 | + QCOMPARE(result[0].path(), validPath); |
1435 | + |
1436 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1437 | + verifyMocks(); |
1438 | +} |
1439 | + |
1440 | +void |
1441 | +TestDownloadManager::testAllDownloadsWithMetadataConfined() { |
1442 | + QString expectedAppId = "APPID"; |
1443 | + auto dbusProxy = new MockDBusProxy(); |
1444 | + auto reply = new MockPendingReply<QString>(); |
1445 | + |
1446 | + EXPECT_CALL(*_dbusProxyFactory, createDBusProxy(_)) |
1447 | + .Times(1) |
1448 | + .WillOnce(Return(dbusProxy)); |
1449 | + |
1450 | + EXPECT_CALL(*dbusProxy, GetConnectionAppArmorSecurityContext(_)) |
1451 | + .Times(1) |
1452 | + .WillOnce(Return(reply)); |
1453 | + |
1454 | + EXPECT_CALL(*reply, waitForFinished()) |
1455 | + .Times(1); |
1456 | + |
1457 | + EXPECT_CALL(*reply, isError()) |
1458 | + .Times(1) |
1459 | + .WillOnce(Return(false)); |
1460 | + |
1461 | + EXPECT_CALL(*reply, value()) |
1462 | + .Times(1) |
1463 | + .WillOnce(Return(expectedAppId)); |
1464 | + |
1465 | + auto key = QString("filter"); |
1466 | + auto value = QString("coconut"); |
1467 | + auto validPath = QString("/valid/metadata/path"); |
1468 | + |
1469 | + QVariantMap filteredMetadata; |
1470 | + filteredMetadata[key] = value; |
1471 | + QVariantMap metadata; |
1472 | + QMap<QString, QString> headers; |
1473 | + |
1474 | + QScopedPointer<MockDownload> first(new MockDownload("", "", "", "", |
1475 | + QUrl("http://one.ubunt.com"), metadata, headers)); |
1476 | + QScopedPointer<MockDownload> second(new MockDownload("", "", "", "", |
1477 | + QUrl("http://ubuntu.com"), metadata, headers)); |
1478 | + QScopedPointer<MockDownload> third(new MockDownload("", "", "", "", |
1479 | + QUrl("http://reddit.com"), metadata, headers)); |
1480 | + QHash<QString, Transfer*> downs; |
1481 | + downs[validPath] = first.data(); |
1482 | + downs["/second/object/path"] = second.data(); |
1483 | + downs["/third/object/path"] = third.data(); |
1484 | + |
1485 | + EXPECT_CALL(*first.data(), metadata()) |
1486 | + .Times(1) |
1487 | + .WillRepeatedly(Return(filteredMetadata)); |
1488 | + |
1489 | + EXPECT_CALL(*first.data(), transferAppId()) |
1490 | + .Times(1) |
1491 | + .WillRepeatedly(Return(expectedAppId)); |
1492 | + |
1493 | + EXPECT_CALL(*second.data(), metadata()) |
1494 | + .Times(1) |
1495 | + .WillRepeatedly(Return(filteredMetadata)); |
1496 | + |
1497 | + EXPECT_CALL(*second.data(), transferAppId()) |
1498 | + .Times(1) |
1499 | + .WillRepeatedly(Return(QString("LEAPP"))); |
1500 | + |
1501 | + EXPECT_CALL(*third.data(), metadata()) |
1502 | + .Times(1) |
1503 | + .WillRepeatedly(Return(filteredMetadata)); |
1504 | + |
1505 | + EXPECT_CALL(*third.data(), transferAppId()) |
1506 | + .Times(1) |
1507 | + .WillRepeatedly(Return(QString("LEAPP"))); |
1508 | + |
1509 | + EXPECT_CALL(*_q, transfers()) |
1510 | + .Times(1) |
1511 | + .WillRepeatedly(Return(downs)); |
1512 | + |
1513 | + auto result = _man->getAllDownloadsWithMetadata(key, value); |
1514 | + QCOMPARE(1, result.count()); |
1515 | + QCOMPARE(result[0].path(), validPath); |
1516 | + |
1517 | + QVERIFY(Mock::VerifyAndClearExpectations(dbusProxy)); |
1518 | + verifyMocks(); |
1519 | +} |
1520 | + |
1521 | QTEST_MAIN(TestDownloadManager) |
1522 | |
1523 | === modified file 'tests/test_download_manager.h' |
1524 | --- tests/test_download_manager.h 2014-03-13 13:04:54 +0000 |
1525 | +++ tests/test_download_manager.h 2014-05-08 15:17:33 +0000 |
1526 | @@ -29,6 +29,7 @@ |
1527 | #include "base_testcase.h" |
1528 | #include "database.h" |
1529 | #include "dbus_connection.h" |
1530 | +#include "dbus_proxy_factory.h" |
1531 | #include "factory.h" |
1532 | #include "queue.h" |
1533 | #include "request_factory.h" |
1534 | @@ -62,8 +63,6 @@ |
1535 | // tests |
1536 | void testCreateDownload(); |
1537 | void testCreateDownloadWithHash(); |
1538 | - void testGetAllDownloads(); |
1539 | - void testAllDownloadsWithMetadata(); |
1540 | void testSetThrottleNotDownloads(); |
1541 | void testSetThrottleWithDownloads(); |
1542 | void testSizeChangedEmittedOnAddition(); |
1543 | @@ -72,6 +71,12 @@ |
1544 | void testStoppable(); |
1545 | void testNotStoppable(); |
1546 | |
1547 | + // all downloads tests |
1548 | + void testGetAllDownloadsUnconfined(); |
1549 | + void testGetAllDownloadsConfined(); |
1550 | + void testAllDownloadsWithMetadataUnconfined(); |
1551 | + void testAllDownloadsWithMetadataConfined(); |
1552 | + |
1553 | private: |
1554 | void verifyMocks(); |
1555 | QCryptographicHash::Algorithm algoFromString(const QString& data); |
1556 | @@ -84,6 +89,7 @@ |
1557 | MockDownloadQueue* _q; |
1558 | DownloadManager* _man; |
1559 | MockRequestFactory* _requestFactory; |
1560 | + MockDBusProxyFactory* _dbusProxyFactory; |
1561 | }; |
1562 | |
1563 | #endif // TEST_DOWNLOADER_H |
PASSED: Continuous integration, rev:257 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- ci/632/ jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- amd64-ci/ 522 jenkins. qa.ubuntu. com/job/ ubuntu- download- manager- trusty- armhf-ci/ 521
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- download- manager- ci/632/ rebuild
http://