Merge lp:~mandel/ubuntu-download-manager/test-mode into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 125
Merged at revision: 125
Proposed branch: lp:~mandel/ubuntu-download-manager/test-mode
Merge into: lp:ubuntu-download-manager
Diff against target: 885 lines (+392/-150)
20 files modified
libubuntudownloadmanager/application.cpp (+19/-14)
libubuntudownloadmanager/application.h (+2/-0)
libubuntudownloadmanager/download_daemon.cpp (+123/-111)
libubuntudownloadmanager/download_daemon.h (+5/-5)
libubuntudownloadmanager/download_factory.cpp (+20/-0)
libubuntudownloadmanager/download_factory.h (+5/-0)
libubuntudownloadmanager/download_manager.cpp (+26/-4)
libubuntudownloadmanager/download_manager.h (+6/-0)
libubuntudownloadmanager/request_factory.cpp (+43/-13)
libubuntudownloadmanager/request_factory.h (+5/-0)
ubuntu-download-manager-tests/fake_application.cpp (+18/-1)
ubuntu-download-manager-tests/fake_application.h (+5/-0)
ubuntu-download-manager-tests/fake_download_manager.cpp (+24/-0)
ubuntu-download-manager-tests/fake_download_manager.h (+2/-0)
ubuntu-download-manager-tests/fake_request_factory.cpp (+25/-0)
ubuntu-download-manager-tests/fake_request_factory.h (+2/-0)
ubuntu-download-manager-tests/test_download_daemon.cpp (+41/-0)
ubuntu-download-manager-tests/test_download_daemon.h (+3/-0)
ubuntu-download-manager-tests/test_download_manager.cpp (+15/-2)
ubuntu-download-manager-tests/test_download_manager.h (+3/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/test-mode
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Mike McCracken (community) Approve
Ying-Chun Liu (community) Approve
Review via email: mp+186015@code.launchpad.net

Commit message

Provide two command line args to be used in tests.

Description of the change

Provide two command line args to be used in tests.

To post a comment you must log in.
Revision history for this message
Ying-Chun Liu (paulliu) wrote :

853 + _man->setAcceptedCertificates(certs);
854 +/*
855 + QList<MethodData> calledMethods = _requestFactory->calledMethods();
856 + qDebug() << calledMethods;
857 + QCOMPARE(1, calledMethods.count());
858 + QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName());
859 + */
860 +}

If the QCOMPARE is commented out, this test looks like an empty test?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Manuel de la Peña (mandel) wrote :

> 853 + _man->setAcceptedCertificates(certs);
> 854 +/*
> 855 + QList<MethodData> calledMethods = _requestFactory->calledMethods();
> 856 + qDebug() << calledMethods;
> 857 + QCOMPARE(1, calledMethods.count());
> 858 + QCOMPARE(QString("setAcceptedCertificates"),
> calledMethods[0].methodName());
> 859 + */
> 860 +}
>
> If the QCOMPARE is commented out, this test looks like an empty test?

Indeed, I must have done that while debugging, I'll fix that!

123. By Manuel de la Peña

Uncomment QCOMPARE.

Revision history for this message
Ying-Chun Liu (paulliu) wrote :

Looks good. +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Barry Warsaw (barry) wrote :

I tested the -self-signed-certs option locally against some of my system-image tests. It appears to work as intended for both the good-path (https downloads with a valid self-signed cert) and bad-paths (https download with self-signed cert not added, and with bad self-signed cert).

LGTM!

Revision history for this message
Mike McCracken (mikemc) wrote :

Approved with minor comments:

the comments "// set the args so that we..." in TestDownloadDaemon::testSelfSignedCerts*() functions
appear to be copy n' paste errors.

typo: #define DISABPLE_TIMEOUT typo in download_daemon.cpp

review: Approve
124. By Manuel de la Peña

Fixed typo and wrong comments.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
125. By Manuel de la Peña

Merged with trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/application.cpp'
2--- libubuntudownloadmanager/application.cpp 2013-08-21 12:08:43 +0000
3+++ libubuntudownloadmanager/application.cpp 2013-09-18 11:41:58 +0000
4@@ -28,25 +28,24 @@
5 Q_DECLARE_PUBLIC(Application)
6
7 public:
8- explicit ApplicationPrivate(Application* parent);
9-
10- virtual void exit(int returnCode);
11+ explicit ApplicationPrivate(Application* parent)
12+ : q_ptr(parent) {
13+ }
14+
15+ void exit(int returnCode) {
16+ // get the application instance and exit
17+ QCoreApplication* app = QCoreApplication::instance();
18+ app->exit(returnCode);
19+ }
20+
21+ QStringList arguments() {
22+ return QCoreApplication::arguments();
23+ }
24
25 private:
26 Application* q_ptr;
27 };
28
29-ApplicationPrivate::ApplicationPrivate(Application* parent)
30- : q_ptr(parent) {
31-}
32-
33-void
34-ApplicationPrivate::exit(int returnCode) {
35- // get the application instance and exit
36- QCoreApplication* app = QCoreApplication::instance();
37- app->exit(returnCode);
38-}
39-
40 /*
41 * PUBLIC IMPLEMENTATION
42 */
43@@ -63,3 +62,9 @@
44 qDebug() << "Exit app" << returnCode;
45 d->exit(returnCode);
46 }
47+
48+QStringList
49+Application::arguments() {
50+ Q_D(Application);
51+ return d->arguments();
52+}
53
54=== modified file 'libubuntudownloadmanager/application.h'
55--- libubuntudownloadmanager/application.h 2013-08-21 11:08:29 +0000
56+++ libubuntudownloadmanager/application.h 2013-09-18 11:41:58 +0000
57@@ -19,6 +19,7 @@
58 #ifndef DOWNLOADER_LIB_APPLICATION_H
59 #define DOWNLOADER_LIB_APPLICATION_H
60
61+#include <QStringList>
62 #include <QObject>
63
64 class ApplicationPrivate;
65@@ -30,6 +31,7 @@
66 explicit Application(QObject *parent = 0);
67
68 virtual void exit(int returnCode = 0);
69+ virtual QStringList arguments();
70
71 private:
72 // use pimpl so that we can mantains ABI compatibility
73
74=== modified file 'libubuntudownloadmanager/download_daemon.cpp'
75--- libubuntudownloadmanager/download_daemon.cpp 2013-08-22 20:49:57 +0000
76+++ libubuntudownloadmanager/download_daemon.cpp 2013-09-18 11:41:58 +0000
77@@ -19,12 +19,16 @@
78 #include <QtDBus/QDBusConnection>
79 #include <QDebug>
80 #include <QSharedPointer>
81+#include <QSslCertificate>
82 #include "./application.h"
83 #include "./logger.h"
84 #include "./download_manager.h"
85 #include "./download_manager_adaptor.h"
86 #include "./download_daemon.h"
87
88+#define DISABLE_TIMEOUT "-disable-timeout"
89+#define SELFSIGNED_CERT "-self-signed-certs"
90+
91 /**
92 * PRIVATE IMPLEMENATION
93 */
94@@ -33,24 +37,131 @@
95 Q_DECLARE_PUBLIC(DownloadDaemon)
96
97 public:
98- explicit DownloadDaemonPrivate(DownloadDaemon* parent);
99- explicit DownloadDaemonPrivate(Application* app,
100- DBusConnection* conn,
101- Timer* timer,
102- DownloadManager* man,
103- DownloadDaemon* parent);
104- ~DownloadDaemonPrivate();
105-
106- void start();
107- void onTimeout();
108- void onDownloadManagerSizeChanged(int size);
109+ explicit DownloadDaemonPrivate(DownloadDaemon* parent)
110+ : q_ptr(parent) {
111+ _app = new Application();
112+ _conn = QSharedPointer<DBusConnection>(new DBusConnection());
113+ _shutDownTimer = new Timer();
114+ _downInterface = new DownloadManager(_conn, q_ptr);
115+ init();
116+ }
117+
118+ DownloadDaemonPrivate(Application* app,
119+ DBusConnection* conn,
120+ Timer* timer,
121+ DownloadManager* man,
122+ DownloadDaemon* parent)
123+ : _app(app),
124+ _shutDownTimer(timer),
125+ _conn(conn),
126+ _downInterface(man),
127+ q_ptr(parent) {
128+ init();
129+ }
130+
131+ ~DownloadDaemonPrivate() {
132+ // no need to delete the adaptor because the interface is its parent
133+ if (_downInterface)
134+ delete _downInterface;
135+ if (_app)
136+ delete _app;
137+ if (_shutDownTimer)
138+ delete _shutDownTimer;
139+
140+ // stop logging
141+ Logger::stopLogging();
142+ }
143+
144+ void start() {
145+ qDebug() << "Starting daemon";
146+ _downAdaptor = new DownloadManagerAdaptor(_downInterface);
147+ bool ret = _conn->registerService(
148+ "com.canonical.applications.Downloader");
149+ if (ret) {
150+ qDebug() << "Service registered to"
151+ << "com.canonical.applications.Downloader";
152+ ret = _conn->registerObject("/", _downInterface);
153+ qDebug() << ret;
154+ if (!ret) {
155+ qDebug() << "Could not register interface";
156+ _app->exit(-1);
157+ }
158+ return;
159+ }
160+ qDebug() << "Could not register service";
161+ _app->exit(-1);
162+ }
163+
164+ void onTimeout() {
165+ qDebug() << "Timeout reached, shutdown service.";
166+ _app->exit(0);
167+ }
168+
169+ void onDownloadManagerSizeChanged(int size) {
170+ bool isActive = _shutDownTimer->isActive();
171+ qDebug() << "Timer is active:" << isActive << "size is:" << size;
172+
173+ if (isActive && size > 0) {
174+ qDebug() << "Timer must be stopped because we have" << size
175+ << "downloads.";
176+ _shutDownTimer->stop();
177+ }
178+ if (!isActive && size == 0) {
179+ qDebug() << "Timer must be started because we have 0 downloads.";
180+ _shutDownTimer->start(timeout);
181+ }
182+ }
183
184 static const int timeout = 30000;
185
186 private:
187- void init();
188+ void parseCommandLine() {
189+ QStringList args = _app->arguments();
190+ if (args.contains(SELFSIGNED_CERT)) {
191+ int index = args.indexOf(SELFSIGNED_CERT);
192+ if (args.count() > index + 1) {
193+ QString certsRegex = args[index + 1];
194+ _certs = QSslCertificate::fromPath(certsRegex);
195+ qDebug() << "Accepting self signed certs" << _certs;
196+ } else {
197+ qCritical() << "Missing certs path";
198+ }
199+ } // certs
200+ _isTimeoutEnabled = !args.contains(DISABLE_TIMEOUT);
201+ qDebug() << "Timeout is enabled:" << _isTimeoutEnabled;
202+ }
203+
204+ void init() {
205+ Q_Q(DownloadDaemon);
206+
207+ // parse command line to decide if the timer is enabled and if
208+ // we accept self signed certs
209+ parseCommandLine();
210+ if (_isTimeoutEnabled) {
211+ q->connect(_shutDownTimer, SIGNAL(timeout()),
212+ q, SLOT(onTimeout()));
213+ _shutDownTimer->start(timeout);
214+ }
215+
216+ _downInterface->setAcceptedCertificates(_certs);
217+ // connect to the download manager changes
218+ q->connect(_downInterface,
219+ SIGNAL(sizeChanged(int)), // NOLINT (readability/function)
220+ q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function)
221+
222+ // set logging
223+ Logger::setupLogging();
224+#ifdef DEBUG
225+ Logger::setLogLevel(QtDebugMsg);
226+#else
227+ if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "")
228+ Logger::setLogLevel(QtDebugMsg);
229+#endif
230+ }
231
232 private:
233+ bool _isTimeoutEnabled;
234+ QList<QSslCertificate> _certs;
235 Application* _app;
236 Timer* _shutDownTimer;
237 QSharedPointer<DBusConnection> _conn;
238@@ -59,105 +170,6 @@
239 DownloadDaemon* q_ptr;
240 };
241
242-DownloadDaemonPrivate::DownloadDaemonPrivate(DownloadDaemon* parent)
243- : q_ptr(parent) {
244- _app = new Application();
245- _conn = QSharedPointer<DBusConnection>(new DBusConnection());
246- _shutDownTimer = new Timer();
247- _downInterface = new DownloadManager(_conn, q_ptr);
248- init();
249-}
250-
251-DownloadDaemonPrivate::DownloadDaemonPrivate(Application* app,
252- DBusConnection* conn,
253- Timer* timer,
254- DownloadManager* man,
255- DownloadDaemon* parent)
256- : _app(app),
257- _shutDownTimer(timer),
258- _conn(conn),
259- _downInterface(man),
260- q_ptr(parent) {
261- init();
262-}
263-
264-void DownloadDaemonPrivate::init() {
265- Q_Q(DownloadDaemon);
266-
267- q->connect(_shutDownTimer, SIGNAL(timeout()),
268- q, SLOT(onTimeout()));
269- _shutDownTimer->start(timeout);
270-
271- // connect to the download manager changes
272- q->connect(_downInterface,
273- SIGNAL(sizeChanged(int)), // NOLINT (readability/function)
274- q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function)
275-
276- // set logging
277- Logger::setupLogging();
278-#ifdef DEBUG
279- Logger::setLogLevel(QtDebugMsg);
280-#else
281- if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "")
282- Logger::setLogLevel(QtDebugMsg);
283-#endif
284-}
285-
286-DownloadDaemonPrivate::~DownloadDaemonPrivate() {
287- // no need to delete the adaptor because the interface is its parent
288- if (_downInterface)
289- delete _downInterface;
290- if (_app)
291- delete _app;
292- if (_shutDownTimer)
293- delete _shutDownTimer;
294-
295- // stop logging
296- Logger::setupLogging();
297-}
298-
299-void
300-DownloadDaemonPrivate::start() {
301- qDebug() << "Starting daemon";
302- _downAdaptor = new DownloadManagerAdaptor(_downInterface);
303- bool ret = _conn->registerService("com.canonical.applications.Downloader");
304- if (ret) {
305- qDebug() << "Service registered to"
306- << "com.canonical.applications.Downloader";
307- ret = _conn->registerObject("/", _downInterface);
308- qDebug() << ret;
309- if (!ret) {
310- qDebug() << "Could not register interface";
311- _app->exit(-1);
312- }
313- return;
314- }
315- qDebug() << "Could not register service";
316- _app->exit(-1);
317-}
318-
319-void
320-DownloadDaemonPrivate::onTimeout() {
321- qDebug() << "Timeout reached, shutdown service.";
322- _app->exit(0);
323-}
324-
325-void
326-DownloadDaemonPrivate::onDownloadManagerSizeChanged(int size) {
327- bool isActive = _shutDownTimer->isActive();
328- qDebug() << "Timer is active:" << isActive << "size is:" << size;
329-
330- if (isActive && size > 0) {
331- qDebug() << "Timer must be stopped because we have" << size
332- << "downloads.";
333- _shutDownTimer->stop();
334- }
335- if (!isActive && size == 0) {
336- qDebug() << "Timer must be started because we have 0 downloads.";
337- _shutDownTimer->start(timeout);
338- }
339-}
340-
341 /**
342 * PUBLIC IMPLEMENTATION
343 */
344
345=== modified file 'libubuntudownloadmanager/download_daemon.h'
346--- libubuntudownloadmanager/download_daemon.h 2013-08-22 20:49:57 +0000
347+++ libubuntudownloadmanager/download_daemon.h 2013-09-18 11:41:58 +0000
348@@ -33,11 +33,11 @@
349
350 public:
351 explicit DownloadDaemon(QObject *parent = 0);
352- explicit DownloadDaemon(Application* app,
353- DBusConnection* conn,
354- Timer* timer,
355- DownloadManager* man,
356- QObject *parent = 0);
357+ DownloadDaemon(Application* app,
358+ DBusConnection* conn,
359+ Timer* timer,
360+ DownloadManager* man,
361+ QObject *parent = 0);
362
363 public slots: // NOLINT (whitespace/indent)
364 void start();
365
366=== modified file 'libubuntudownloadmanager/download_factory.cpp'
367--- libubuntudownloadmanager/download_factory.cpp 2013-09-18 10:18:24 +0000
368+++ libubuntudownloadmanager/download_factory.cpp 2013-09-18 11:41:58 +0000
369@@ -166,6 +166,14 @@
370 return down;
371 }
372
373+ QList<QSslCertificate> acceptedCertificates() {
374+ return _nam->acceptedCertificates();
375+ }
376+
377+ void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
378+ _nam->setAcceptedCertificates(certs);
379+ }
380+
381 private:
382 QSharedPointer<AppArmor> _apparmor;
383 QSharedPointer<SystemNetworkInfo> _networkInfo;
384@@ -245,3 +253,15 @@
385 return d->createDownloadForGroup(isConfined, rootPath, url, hash, algo,
386 metadata, headers);
387 }
388+
389+QList<QSslCertificate>
390+DownloadFactory::acceptedCertificates() {
391+ Q_D(DownloadFactory);
392+ return d->acceptedCertificates();
393+}
394+
395+void
396+DownloadFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
397+ Q_D(DownloadFactory);
398+ d->setAcceptedCertificates(certs);
399+}
400
401=== modified file 'libubuntudownloadmanager/download_factory.h'
402--- libubuntudownloadmanager/download_factory.h 2013-09-18 10:18:24 +0000
403+++ libubuntudownloadmanager/download_factory.h 2013-09-18 11:41:58 +0000
404@@ -77,6 +77,11 @@
405 const QVariantMap& metadata,
406 const QMap<QString, QString>& headers);
407
408+ // mainly for testing purposes
409+
410+ virtual QList<QSslCertificate> acceptedCertificates();
411+ virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
412+
413 private:
414 // use pimpl so that we can mantains ABI compatibility
415 DownloadFactoryPrivate* d_ptr;
416
417=== modified file 'libubuntudownloadmanager/download_manager.cpp'
418--- libubuntudownloadmanager/download_manager.cpp 2013-09-10 12:18:34 +0000
419+++ libubuntudownloadmanager/download_manager.cpp 2013-09-18 11:41:58 +0000
420@@ -40,10 +40,11 @@
421 _apparmor = QSharedPointer<AppArmor>(new AppArmor());
422 _networkInfo = QSharedPointer<SystemNetworkInfo>(
423 new SystemNetworkInfo());
424- _nam = QSharedPointer<RequestFactory>(new RequestFactory());
425+ QSharedPointer<RequestFactory> nam = QSharedPointer<RequestFactory>(
426+ new RequestFactory());
427 _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory());
428 _downloadFactory = QSharedPointer<DownloadFactory>(
429- new DownloadFactory(_apparmor, _networkInfo, _nam,
430+ new DownloadFactory(_apparmor, _networkInfo, nam,
431 _processFactory));
432 _downloadsQueue = QSharedPointer<DownloadQueue>(
433 new DownloadQueue(_networkInfo));
434@@ -91,8 +92,17 @@
435 Q_UNUSED(path);
436 }
437
438+ QList<QSslCertificate> acceptedCertificates() {
439+ return _downloadFactory->acceptedCertificates();
440+ }
441+
442+ void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
443+ qDebug() << __PRETTY_FUNCTION__ << certs;
444+ _downloadFactory->setAcceptedCertificates(certs);
445+ }
446+
447 void onDownloadsChanged(QString path) {
448- qDebug() << __FUNCTION__ << path;
449+ qDebug() << __PRETTY_FUNCTION__ << path;
450 Q_Q(DownloadManager);
451 emit q->sizeChanged(_downloadsQueue->size());
452 }
453@@ -188,7 +198,6 @@
454 qulonglong _throttle;
455 QSharedPointer<AppArmor> _apparmor;
456 QSharedPointer<SystemNetworkInfo> _networkInfo;
457- QSharedPointer<RequestFactory> _nam;
458 QSharedPointer<ProcessFactory> _processFactory;
459 QSharedPointer<DownloadFactory> _downloadFactory;
460 QSharedPointer<DownloadQueue> _downloadsQueue;
461@@ -226,6 +235,19 @@
462 d->loadPreviewsDownloads(path);
463 }
464
465+QList<QSslCertificate>
466+DownloadManager::acceptedCertificates() {
467+ Q_D(DownloadManager);
468+ return d->acceptedCertificates();
469+}
470+
471+
472+void
473+DownloadManager::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
474+ Q_D(DownloadManager);
475+ return d->setAcceptedCertificates(certs);
476+}
477+
478 qulonglong
479 DownloadManager::defaultThrottle() {
480 Q_D(DownloadManager);
481
482=== modified file 'libubuntudownloadmanager/download_manager.h'
483--- libubuntudownloadmanager/download_manager.h 2013-09-09 10:30:18 +0000
484+++ libubuntudownloadmanager/download_manager.h 2013-09-18 11:41:58 +0000
485@@ -24,6 +24,7 @@
486 #include <QtDBus/QDBusObjectPath>
487 #include <QtDBus/QDBusContext>
488 #include <QSharedPointer>
489+#include <QSslCertificate>
490 #include "./dbus_connection.h"
491 #include "./download.h"
492 #include "./download_queue.h"
493@@ -44,8 +45,13 @@
494 DownloadFactory* downloadFactory,
495 DownloadQueue* queue,
496 QObject *parent = 0);
497+
498 void loadPreviewsDownloads(const QString &path);
499
500+ // mainly for testing purposes
501+ virtual QList<QSslCertificate> acceptedCertificates();
502+ virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
503+
504 public slots: // NOLINT(whitespace/indent)
505 QDBusObjectPath createDownload(DownloadStruct download);
506
507
508=== modified file 'libubuntudownloadmanager/request_factory.cpp'
509--- libubuntudownloadmanager/request_factory.cpp 2013-07-23 16:03:10 +0000
510+++ libubuntudownloadmanager/request_factory.cpp 2013-09-18 11:41:58 +0000
511@@ -17,6 +17,7 @@
512 */
513
514 #include <QNetworkAccessManager>
515+#include <QSslError>
516 #include "./request_factory.h"
517
518 /*
519@@ -27,24 +28,41 @@
520 Q_DECLARE_PUBLIC(RequestFactory)
521
522 public:
523- explicit RequestFactoryPrivate(RequestFactory* parent);
524-
525- NetworkReply* get(const QNetworkRequest& request);
526+ explicit RequestFactoryPrivate(RequestFactory* parent)
527+ : q_ptr(parent) {
528+ _nam = new QNetworkAccessManager();
529+ }
530+
531+ NetworkReply* get(const QNetworkRequest& request) {
532+ QNetworkReply* reply = _nam->get(request);
533+
534+ if (_certs.count() > 0) {
535+ // build the expected ssl errors
536+ QList<QSslError> expectedSslErrors;
537+ foreach(const QSslCertificate& certificate, _certs) {
538+ QSslError error(QSslError::SelfSignedCertificate, certificate);
539+ expectedSslErrors.append(error);
540+ }
541+ reply->ignoreSslErrors(expectedSslErrors);
542+ }
543+
544+ return new NetworkReply(reply);
545+ }
546+
547+ QList<QSslCertificate> acceptedCertificates() {
548+ return _certs;
549+ }
550+
551+ void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
552+ _certs = certs;
553+ }
554+
555 private:
556+ QList<QSslCertificate> _certs;
557 QNetworkAccessManager* _nam;
558 RequestFactory* q_ptr;
559 };
560
561-RequestFactoryPrivate::RequestFactoryPrivate(RequestFactory* parent)
562- : q_ptr(parent) {
563- _nam = new QNetworkAccessManager();
564-}
565-
566-NetworkReply*
567-RequestFactoryPrivate::get(const QNetworkRequest& request) {
568- return new NetworkReply(_nam->get(request));
569-}
570-
571 /*
572 * PUBLIC IMPLEMENTATION
573 */
574@@ -59,3 +77,15 @@
575 Q_D(RequestFactory);
576 return d->get(request);
577 }
578+
579+QList<QSslCertificate>
580+RequestFactory::acceptedCertificates() {
581+ Q_D(RequestFactory);
582+ return d->acceptedCertificates();
583+}
584+
585+void
586+RequestFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
587+ Q_D(RequestFactory);
588+ d->setAcceptedCertificates(certs);
589+}
590
591=== modified file 'libubuntudownloadmanager/request_factory.h'
592--- libubuntudownloadmanager/request_factory.h 2013-07-23 16:03:57 +0000
593+++ libubuntudownloadmanager/request_factory.h 2013-09-18 11:41:58 +0000
594@@ -21,6 +21,7 @@
595
596 #include <QNetworkRequest>
597 #include <QObject>
598+#include <QSslCertificate>
599 #include "./app-downloader-lib_global.h"
600 #include "./network_reply.h"
601
602@@ -34,6 +35,10 @@
603
604 virtual NetworkReply* get(const QNetworkRequest& request);
605
606+ // mainly for testing purposes
607+ virtual QList<QSslCertificate> acceptedCertificates();
608+ virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
609+
610 private:
611 // use pimpl so that we can mantains ABI compatibility
612 RequestFactoryPrivate* d_ptr;
613
614=== modified file 'ubuntu-download-manager-tests/fake_application.cpp'
615--- ubuntu-download-manager-tests/fake_application.cpp 2013-08-21 11:40:25 +0000
616+++ ubuntu-download-manager-tests/fake_application.cpp 2013-09-18 11:41:58 +0000
617@@ -16,7 +16,7 @@
618 * Boston, MA 02110-1301, USA.
619 */
620
621-#include "fake_application.h"
622+#include "./fake_application.h"
623
624 FakeApplication::FakeApplication(QObject *parent)
625 : Application(parent),
626@@ -35,3 +35,20 @@
627 _called.append(methodData);
628 }
629 }
630+
631+QStringList
632+FakeApplication::arguments() {
633+ if (_recording) {
634+ QList<QObject*> inParams;
635+ QList<QObject*> outParams;
636+ MethodParams params(inParams, outParams);
637+ MethodData methodData("arguments", params);
638+ _called.append(methodData);
639+ }
640+ return _args;
641+}
642+
643+void
644+FakeApplication::setArguments(QStringList args) {
645+ _args = args;
646+}
647
648=== modified file 'ubuntu-download-manager-tests/fake_application.h'
649--- ubuntu-download-manager-tests/fake_application.h 2013-08-21 12:21:49 +0000
650+++ ubuntu-download-manager-tests/fake_application.h 2013-09-18 11:41:58 +0000
651@@ -30,6 +30,11 @@
652 explicit FakeApplication(QObject *parent = 0);
653
654 void exit(int returnCode = 0) override;
655+
656+ QStringList arguments() override;
657+ void setArguments(QStringList args);
658+ private:
659+ QStringList _args;
660 };
661
662 #endif // FAKE_APPLICATION_H
663
664=== modified file 'ubuntu-download-manager-tests/fake_download_manager.cpp'
665--- ubuntu-download-manager-tests/fake_download_manager.cpp 2013-08-22 20:49:57 +0000
666+++ ubuntu-download-manager-tests/fake_download_manager.cpp 2013-09-18 11:41:58 +0000
667@@ -30,3 +30,27 @@
668 emit sizeChanged(size);
669 }
670
671+QList<QSslCertificate>
672+FakeDownloadManager::acceptedCertificates() {
673+ if (_recording) {
674+ QList<QObject*> inParams;
675+ QList<QObject*> outParams;
676+ MethodParams params(inParams, outParams);
677+ MethodData methodData("acceptedCertificates", params);
678+ _called.append(methodData);
679+ }
680+ return DownloadManager::acceptedCertificates();
681+}
682+
683+void
684+FakeDownloadManager::setAcceptedCertificates(
685+ const QList<QSslCertificate>& certs) {
686+ if (_recording) {
687+ QList<QObject*> inParams;
688+ QList<QObject*> outParams;
689+ MethodParams params(inParams, outParams);
690+ MethodData methodData("setAcceptedCertificates", params);
691+ _called.append(methodData);
692+ }
693+ DownloadManager::setAcceptedCertificates(certs);
694+}
695
696=== modified file 'ubuntu-download-manager-tests/fake_download_manager.h'
697--- ubuntu-download-manager-tests/fake_download_manager.h 2013-08-22 20:49:57 +0000
698+++ ubuntu-download-manager-tests/fake_download_manager.h 2013-09-18 11:41:58 +0000
699@@ -32,6 +32,8 @@
700 QObject *parent = 0);
701
702 void emitSizeChaged(int size);
703+ QList<QSslCertificate> acceptedCertificates() override;
704+ void setAcceptedCertificates(const QList<QSslCertificate>& certs) override;
705 };
706
707 #endif // FAKE_DOWNLOAD_MANAGER_H
708
709=== modified file 'ubuntu-download-manager-tests/fake_request_factory.cpp'
710--- ubuntu-download-manager-tests/fake_request_factory.cpp 2013-07-23 17:55:51 +0000
711+++ ubuntu-download-manager-tests/fake_request_factory.cpp 2013-09-18 11:41:58 +0000
712@@ -56,3 +56,28 @@
713 }
714 return reply;
715 }
716+
717+QList<QSslCertificate>
718+FakeRequestFactory::acceptedCertificates() {
719+ if (_recording) {
720+ QList<QObject*> inParams;
721+ QList<QObject*> outParams;
722+ MethodParams params(inParams, outParams);
723+ MethodData methodData("acceptedCertificates", params);
724+ _called.append(methodData);
725+ }
726+ return RequestFactory::acceptedCertificates();
727+}
728+
729+void
730+FakeRequestFactory::setAcceptedCertificates(
731+ const QList<QSslCertificate>& certs) {
732+ if (_recording) {
733+ QList<QObject*> inParams;
734+ QList<QObject*> outParams;
735+ MethodParams params(inParams, outParams);
736+ MethodData methodData("setAcceptedCertificates", params);
737+ _called.append(methodData);
738+ }
739+ RequestFactory::setAcceptedCertificates(certs);
740+}
741
742=== modified file 'ubuntu-download-manager-tests/fake_request_factory.h'
743--- ubuntu-download-manager-tests/fake_request_factory.h 2013-07-23 17:57:12 +0000
744+++ ubuntu-download-manager-tests/fake_request_factory.h 2013-09-18 11:41:58 +0000
745@@ -46,6 +46,8 @@
746
747 // overriden methods used to fake the nam
748 NetworkReply* get(const QNetworkRequest& request);
749+ QList<QSslCertificate> acceptedCertificates() override;
750+ void setAcceptedCertificates(const QList<QSslCertificate>& certs) override;
751 };
752
753 #endif // FAKE_QNETWORK_ACCESS_MANAGER_H
754
755=== modified file 'ubuntu-download-manager-tests/test_download_daemon.cpp'
756--- ubuntu-download-manager-tests/test_download_daemon.cpp 2013-08-22 20:49:57 +0000
757+++ ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-18 11:41:58 +0000
758@@ -141,3 +141,44 @@
759 QCOMPARE(QString("exit"), calledMethods[0].methodName());
760 }
761
762+void
763+TestDownloadDaemon::testDisableTimeout() {
764+ _timer->record();
765+
766+ // set the args so that we disable the timeout
767+ QStringList args;
768+ args << "-disable-timeout";
769+ _app->setArguments(args);
770+
771+ // assert that start is never called
772+ _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
773+ QList<MethodData> calledMethods = _timer->calledMethods();
774+ QCOMPARE(0, calledMethods.count());
775+}
776+
777+void
778+TestDownloadDaemon::testSelfSignedCerts() {
779+ _man->record();
780+ QStringList args;
781+ args << "-self-signed-certs" << "*.pem";
782+ _app->setArguments(args);
783+
784+ // assert that we set the certs
785+ _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
786+ QList<MethodData> calledMethods = _man->calledMethods();
787+ QCOMPARE(1, calledMethods.count());
788+ QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName());
789+}
790+
791+void
792+TestDownloadDaemon::testSelfSignedCertsMissingPath() {
793+ _man->record();
794+ QStringList args;
795+ args << "-self-signed-certs";
796+ _app->setArguments(args);
797+
798+ // assert that we do not crash
799+ _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
800+ QList<MethodData> calledMethods = _man->calledMethods();
801+ QCOMPARE(1, calledMethods.count());
802+}
803
804=== modified file 'ubuntu-download-manager-tests/test_download_daemon.h'
805--- ubuntu-download-manager-tests/test_download_daemon.h 2013-08-22 20:49:57 +0000
806+++ ubuntu-download-manager-tests/test_download_daemon.h 2013-09-18 11:41:58 +0000
807@@ -43,6 +43,9 @@
808 void testTimerStop();
809 void testTimerStart();
810 void testTimeoutExit();
811+ void testDisableTimeout();
812+ void testSelfSignedCerts();
813+ void testSelfSignedCertsMissingPath();
814
815 private:
816 FakeTimer* _timer;
817
818=== modified file 'ubuntu-download-manager-tests/test_download_manager.cpp'
819--- ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-10 12:18:34 +0000
820+++ ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-18 11:41:58 +0000
821@@ -20,7 +20,6 @@
822 #include <download_factory.h>
823 #include <download_struct.h>
824 #include "./fake_process_factory.h"
825-#include "./fake_request_factory.h"
826 #include "./fake_system_network_info.h"
827 #include "./test_download_manager.h"
828
829@@ -35,10 +34,11 @@
830 _q = new FakeDownloadQueue(QSharedPointer<SystemNetworkInfo>(_networkInfo));
831 _uuidFactory = new FakeUuidFactory();
832 _apparmor = new FakeAppArmor(QSharedPointer<UuidFactory>(_uuidFactory));
833+ _requestFactory = new FakeRequestFactory();
834 _downloadFactory = new FakeDownloadFactory(
835 QSharedPointer<AppArmor>(_apparmor),
836 QSharedPointer<SystemNetworkInfo>(_networkInfo),
837- QSharedPointer<RequestFactory>(new FakeRequestFactory()),
838+ QSharedPointer<RequestFactory>(_requestFactory),
839 QSharedPointer<ProcessFactory>(new FakeProcessFactory()));
840 _man = new DownloadManager(qSharedPointerCast<DBusConnection>(_conn),
841 _networkInfo, _downloadFactory, _q);
842@@ -471,3 +471,16 @@
843 QList<QVariant> arguments = spy.takeFirst();
844 QCOMPARE(arguments.at(0).toInt(), size);
845 }
846+
847+void
848+TestDownloadManager::testSetSelfSignedCerts() {
849+ // assert that the factory does get the certs
850+ _requestFactory->record();
851+ QList<QSslCertificate> certs;
852+ _man->setAcceptedCertificates(certs);
853+
854+ QList<MethodData> calledMethods = _requestFactory->calledMethods();
855+ qDebug() << calledMethods;
856+ QCOMPARE(1, calledMethods.count());
857+ QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName());
858+}
859
860=== modified file 'ubuntu-download-manager-tests/test_download_manager.h'
861--- ubuntu-download-manager-tests/test_download_manager.h 2013-09-10 12:18:34 +0000
862+++ ubuntu-download-manager-tests/test_download_manager.h 2013-09-18 11:41:58 +0000
863@@ -28,6 +28,7 @@
864 #include "./fake_dbus_connection.h"
865 #include "./fake_download_queue.h"
866 #include "./fake_download_factory.h"
867+#include "./fake_request_factory.h"
868 #include "./fake_uuid_factory.h"
869 #include "./fake_system_network_info.h"
870
871@@ -59,12 +60,14 @@
872 void testSetThrottleWithDownloads();
873 void testSizeChangedEmittedOnAddition();
874 void testSizeChangedEmittedOnRemoval();
875+ void testSetSelfSignedCerts();
876
877 private:
878 QCryptographicHash::Algorithm algoFromString(const QString& data);
879
880 private:
881 FakeSystemNetworkInfo* _networkInfo;
882+ FakeRequestFactory* _requestFactory;
883 FakeDownloadFactory* _downloadFactory;
884 QSharedPointer<FakeDBusConnection> _conn;
885 FakeDownloadQueue* _q;

Subscribers

People subscribed via source and target branches