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
=== modified file 'libubuntudownloadmanager/application.cpp'
--- libubuntudownloadmanager/application.cpp 2013-08-21 12:08:43 +0000
+++ libubuntudownloadmanager/application.cpp 2013-09-18 11:41:58 +0000
@@ -28,25 +28,24 @@
28 Q_DECLARE_PUBLIC(Application)28 Q_DECLARE_PUBLIC(Application)
2929
30 public:30 public:
31 explicit ApplicationPrivate(Application* parent);31 explicit ApplicationPrivate(Application* parent)
3232 : q_ptr(parent) {
33 virtual void exit(int returnCode);33 }
34
35 void exit(int returnCode) {
36 // get the application instance and exit
37 QCoreApplication* app = QCoreApplication::instance();
38 app->exit(returnCode);
39 }
40
41 QStringList arguments() {
42 return QCoreApplication::arguments();
43 }
3444
35 private:45 private:
36 Application* q_ptr;46 Application* q_ptr;
37};47};
3848
39ApplicationPrivate::ApplicationPrivate(Application* parent)
40 : q_ptr(parent) {
41}
42
43void
44ApplicationPrivate::exit(int returnCode) {
45 // get the application instance and exit
46 QCoreApplication* app = QCoreApplication::instance();
47 app->exit(returnCode);
48}
49
50/*49/*
51 * PUBLIC IMPLEMENTATION50 * PUBLIC IMPLEMENTATION
52 */51 */
@@ -63,3 +62,9 @@
63 qDebug() << "Exit app" << returnCode;62 qDebug() << "Exit app" << returnCode;
64 d->exit(returnCode);63 d->exit(returnCode);
65}64}
65
66QStringList
67Application::arguments() {
68 Q_D(Application);
69 return d->arguments();
70}
6671
=== modified file 'libubuntudownloadmanager/application.h'
--- libubuntudownloadmanager/application.h 2013-08-21 11:08:29 +0000
+++ libubuntudownloadmanager/application.h 2013-09-18 11:41:58 +0000
@@ -19,6 +19,7 @@
19#ifndef DOWNLOADER_LIB_APPLICATION_H19#ifndef DOWNLOADER_LIB_APPLICATION_H
20#define DOWNLOADER_LIB_APPLICATION_H20#define DOWNLOADER_LIB_APPLICATION_H
2121
22#include <QStringList>
22#include <QObject>23#include <QObject>
2324
24class ApplicationPrivate;25class ApplicationPrivate;
@@ -30,6 +31,7 @@
30 explicit Application(QObject *parent = 0);31 explicit Application(QObject *parent = 0);
3132
32 virtual void exit(int returnCode = 0);33 virtual void exit(int returnCode = 0);
34 virtual QStringList arguments();
3335
34 private:36 private:
35 // use pimpl so that we can mantains ABI compatibility37 // use pimpl so that we can mantains ABI compatibility
3638
=== modified file 'libubuntudownloadmanager/download_daemon.cpp'
--- libubuntudownloadmanager/download_daemon.cpp 2013-08-22 20:49:57 +0000
+++ libubuntudownloadmanager/download_daemon.cpp 2013-09-18 11:41:58 +0000
@@ -19,12 +19,16 @@
19#include <QtDBus/QDBusConnection>19#include <QtDBus/QDBusConnection>
20#include <QDebug>20#include <QDebug>
21#include <QSharedPointer>21#include <QSharedPointer>
22#include <QSslCertificate>
22#include "./application.h"23#include "./application.h"
23#include "./logger.h"24#include "./logger.h"
24#include "./download_manager.h"25#include "./download_manager.h"
25#include "./download_manager_adaptor.h"26#include "./download_manager_adaptor.h"
26#include "./download_daemon.h"27#include "./download_daemon.h"
2728
29#define DISABLE_TIMEOUT "-disable-timeout"
30#define SELFSIGNED_CERT "-self-signed-certs"
31
28/**32/**
29 * PRIVATE IMPLEMENATION33 * PRIVATE IMPLEMENATION
30 */34 */
@@ -33,24 +37,131 @@
33 Q_DECLARE_PUBLIC(DownloadDaemon)37 Q_DECLARE_PUBLIC(DownloadDaemon)
3438
35 public:39 public:
36 explicit DownloadDaemonPrivate(DownloadDaemon* parent);40 explicit DownloadDaemonPrivate(DownloadDaemon* parent)
37 explicit DownloadDaemonPrivate(Application* app,41 : q_ptr(parent) {
38 DBusConnection* conn,42 _app = new Application();
39 Timer* timer,43 _conn = QSharedPointer<DBusConnection>(new DBusConnection());
40 DownloadManager* man,44 _shutDownTimer = new Timer();
41 DownloadDaemon* parent);45 _downInterface = new DownloadManager(_conn, q_ptr);
42 ~DownloadDaemonPrivate();46 init();
4347 }
44 void start();48
45 void onTimeout();49 DownloadDaemonPrivate(Application* app,
46 void onDownloadManagerSizeChanged(int size);50 DBusConnection* conn,
51 Timer* timer,
52 DownloadManager* man,
53 DownloadDaemon* parent)
54 : _app(app),
55 _shutDownTimer(timer),
56 _conn(conn),
57 _downInterface(man),
58 q_ptr(parent) {
59 init();
60 }
61
62 ~DownloadDaemonPrivate() {
63 // no need to delete the adaptor because the interface is its parent
64 if (_downInterface)
65 delete _downInterface;
66 if (_app)
67 delete _app;
68 if (_shutDownTimer)
69 delete _shutDownTimer;
70
71 // stop logging
72 Logger::stopLogging();
73 }
74
75 void start() {
76 qDebug() << "Starting daemon";
77 _downAdaptor = new DownloadManagerAdaptor(_downInterface);
78 bool ret = _conn->registerService(
79 "com.canonical.applications.Downloader");
80 if (ret) {
81 qDebug() << "Service registered to"
82 << "com.canonical.applications.Downloader";
83 ret = _conn->registerObject("/", _downInterface);
84 qDebug() << ret;
85 if (!ret) {
86 qDebug() << "Could not register interface";
87 _app->exit(-1);
88 }
89 return;
90 }
91 qDebug() << "Could not register service";
92 _app->exit(-1);
93 }
94
95 void onTimeout() {
96 qDebug() << "Timeout reached, shutdown service.";
97 _app->exit(0);
98 }
99
100 void onDownloadManagerSizeChanged(int size) {
101 bool isActive = _shutDownTimer->isActive();
102 qDebug() << "Timer is active:" << isActive << "size is:" << size;
103
104 if (isActive && size > 0) {
105 qDebug() << "Timer must be stopped because we have" << size
106 << "downloads.";
107 _shutDownTimer->stop();
108 }
109 if (!isActive && size == 0) {
110 qDebug() << "Timer must be started because we have 0 downloads.";
111 _shutDownTimer->start(timeout);
112 }
113 }
47114
48 static const int timeout = 30000;115 static const int timeout = 30000;
49116
50 private:117 private:
51 void init();118 void parseCommandLine() {
119 QStringList args = _app->arguments();
120 if (args.contains(SELFSIGNED_CERT)) {
121 int index = args.indexOf(SELFSIGNED_CERT);
122 if (args.count() > index + 1) {
123 QString certsRegex = args[index + 1];
124 _certs = QSslCertificate::fromPath(certsRegex);
125 qDebug() << "Accepting self signed certs" << _certs;
126 } else {
127 qCritical() << "Missing certs path";
128 }
129 } // certs
130 _isTimeoutEnabled = !args.contains(DISABLE_TIMEOUT);
131 qDebug() << "Timeout is enabled:" << _isTimeoutEnabled;
132 }
133
134 void init() {
135 Q_Q(DownloadDaemon);
136
137 // parse command line to decide if the timer is enabled and if
138 // we accept self signed certs
139 parseCommandLine();
140 if (_isTimeoutEnabled) {
141 q->connect(_shutDownTimer, SIGNAL(timeout()),
142 q, SLOT(onTimeout()));
143 _shutDownTimer->start(timeout);
144 }
145
146 _downInterface->setAcceptedCertificates(_certs);
147 // connect to the download manager changes
148 q->connect(_downInterface,
149 SIGNAL(sizeChanged(int)), // NOLINT (readability/function)
150 q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function)
151
152 // set logging
153 Logger::setupLogging();
154#ifdef DEBUG
155 Logger::setLogLevel(QtDebugMsg);
156#else
157 if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "")
158 Logger::setLogLevel(QtDebugMsg);
159#endif
160 }
52161
53 private:162 private:
163 bool _isTimeoutEnabled;
164 QList<QSslCertificate> _certs;
54 Application* _app;165 Application* _app;
55 Timer* _shutDownTimer;166 Timer* _shutDownTimer;
56 QSharedPointer<DBusConnection> _conn;167 QSharedPointer<DBusConnection> _conn;
@@ -59,105 +170,6 @@
59 DownloadDaemon* q_ptr;170 DownloadDaemon* q_ptr;
60};171};
61172
62DownloadDaemonPrivate::DownloadDaemonPrivate(DownloadDaemon* parent)
63 : q_ptr(parent) {
64 _app = new Application();
65 _conn = QSharedPointer<DBusConnection>(new DBusConnection());
66 _shutDownTimer = new Timer();
67 _downInterface = new DownloadManager(_conn, q_ptr);
68 init();
69}
70
71DownloadDaemonPrivate::DownloadDaemonPrivate(Application* app,
72 DBusConnection* conn,
73 Timer* timer,
74 DownloadManager* man,
75 DownloadDaemon* parent)
76 : _app(app),
77 _shutDownTimer(timer),
78 _conn(conn),
79 _downInterface(man),
80 q_ptr(parent) {
81 init();
82}
83
84void DownloadDaemonPrivate::init() {
85 Q_Q(DownloadDaemon);
86
87 q->connect(_shutDownTimer, SIGNAL(timeout()),
88 q, SLOT(onTimeout()));
89 _shutDownTimer->start(timeout);
90
91 // connect to the download manager changes
92 q->connect(_downInterface,
93 SIGNAL(sizeChanged(int)), // NOLINT (readability/function)
94 q, SLOT(onDownloadManagerSizeChanged(int))); // NOLINT (readability/function)
95
96 // set logging
97 Logger::setupLogging();
98#ifdef DEBUG
99 Logger::setLogLevel(QtDebugMsg);
100#else
101 if (qgetenv("UBUNTU_DOWNLOADER_DEBUG") != "")
102 Logger::setLogLevel(QtDebugMsg);
103#endif
104}
105
106DownloadDaemonPrivate::~DownloadDaemonPrivate() {
107 // no need to delete the adaptor because the interface is its parent
108 if (_downInterface)
109 delete _downInterface;
110 if (_app)
111 delete _app;
112 if (_shutDownTimer)
113 delete _shutDownTimer;
114
115 // stop logging
116 Logger::setupLogging();
117}
118
119void
120DownloadDaemonPrivate::start() {
121 qDebug() << "Starting daemon";
122 _downAdaptor = new DownloadManagerAdaptor(_downInterface);
123 bool ret = _conn->registerService("com.canonical.applications.Downloader");
124 if (ret) {
125 qDebug() << "Service registered to"
126 << "com.canonical.applications.Downloader";
127 ret = _conn->registerObject("/", _downInterface);
128 qDebug() << ret;
129 if (!ret) {
130 qDebug() << "Could not register interface";
131 _app->exit(-1);
132 }
133 return;
134 }
135 qDebug() << "Could not register service";
136 _app->exit(-1);
137}
138
139void
140DownloadDaemonPrivate::onTimeout() {
141 qDebug() << "Timeout reached, shutdown service.";
142 _app->exit(0);
143}
144
145void
146DownloadDaemonPrivate::onDownloadManagerSizeChanged(int size) {
147 bool isActive = _shutDownTimer->isActive();
148 qDebug() << "Timer is active:" << isActive << "size is:" << size;
149
150 if (isActive && size > 0) {
151 qDebug() << "Timer must be stopped because we have" << size
152 << "downloads.";
153 _shutDownTimer->stop();
154 }
155 if (!isActive && size == 0) {
156 qDebug() << "Timer must be started because we have 0 downloads.";
157 _shutDownTimer->start(timeout);
158 }
159}
160
161/**173/**
162 * PUBLIC IMPLEMENTATION174 * PUBLIC IMPLEMENTATION
163 */175 */
164176
=== modified file 'libubuntudownloadmanager/download_daemon.h'
--- libubuntudownloadmanager/download_daemon.h 2013-08-22 20:49:57 +0000
+++ libubuntudownloadmanager/download_daemon.h 2013-09-18 11:41:58 +0000
@@ -33,11 +33,11 @@
3333
34 public:34 public:
35 explicit DownloadDaemon(QObject *parent = 0);35 explicit DownloadDaemon(QObject *parent = 0);
36 explicit DownloadDaemon(Application* app,36 DownloadDaemon(Application* app,
37 DBusConnection* conn,37 DBusConnection* conn,
38 Timer* timer,38 Timer* timer,
39 DownloadManager* man,39 DownloadManager* man,
40 QObject *parent = 0);40 QObject *parent = 0);
4141
42 public slots: // NOLINT (whitespace/indent)42 public slots: // NOLINT (whitespace/indent)
43 void start();43 void start();
4444
=== modified file 'libubuntudownloadmanager/download_factory.cpp'
--- libubuntudownloadmanager/download_factory.cpp 2013-09-18 10:18:24 +0000
+++ libubuntudownloadmanager/download_factory.cpp 2013-09-18 11:41:58 +0000
@@ -166,6 +166,14 @@
166 return down;166 return down;
167 }167 }
168168
169 QList<QSslCertificate> acceptedCertificates() {
170 return _nam->acceptedCertificates();
171 }
172
173 void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
174 _nam->setAcceptedCertificates(certs);
175 }
176
169 private:177 private:
170 QSharedPointer<AppArmor> _apparmor;178 QSharedPointer<AppArmor> _apparmor;
171 QSharedPointer<SystemNetworkInfo> _networkInfo;179 QSharedPointer<SystemNetworkInfo> _networkInfo;
@@ -245,3 +253,15 @@
245 return d->createDownloadForGroup(isConfined, rootPath, url, hash, algo,253 return d->createDownloadForGroup(isConfined, rootPath, url, hash, algo,
246 metadata, headers);254 metadata, headers);
247}255}
256
257QList<QSslCertificate>
258DownloadFactory::acceptedCertificates() {
259 Q_D(DownloadFactory);
260 return d->acceptedCertificates();
261}
262
263void
264DownloadFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
265 Q_D(DownloadFactory);
266 d->setAcceptedCertificates(certs);
267}
248268
=== modified file 'libubuntudownloadmanager/download_factory.h'
--- libubuntudownloadmanager/download_factory.h 2013-09-18 10:18:24 +0000
+++ libubuntudownloadmanager/download_factory.h 2013-09-18 11:41:58 +0000
@@ -77,6 +77,11 @@
77 const QVariantMap& metadata,77 const QVariantMap& metadata,
78 const QMap<QString, QString>& headers);78 const QMap<QString, QString>& headers);
7979
80 // mainly for testing purposes
81
82 virtual QList<QSslCertificate> acceptedCertificates();
83 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
84
80 private:85 private:
81 // use pimpl so that we can mantains ABI compatibility86 // use pimpl so that we can mantains ABI compatibility
82 DownloadFactoryPrivate* d_ptr;87 DownloadFactoryPrivate* d_ptr;
8388
=== modified file 'libubuntudownloadmanager/download_manager.cpp'
--- libubuntudownloadmanager/download_manager.cpp 2013-09-10 12:18:34 +0000
+++ libubuntudownloadmanager/download_manager.cpp 2013-09-18 11:41:58 +0000
@@ -40,10 +40,11 @@
40 _apparmor = QSharedPointer<AppArmor>(new AppArmor());40 _apparmor = QSharedPointer<AppArmor>(new AppArmor());
41 _networkInfo = QSharedPointer<SystemNetworkInfo>(41 _networkInfo = QSharedPointer<SystemNetworkInfo>(
42 new SystemNetworkInfo());42 new SystemNetworkInfo());
43 _nam = QSharedPointer<RequestFactory>(new RequestFactory());43 QSharedPointer<RequestFactory> nam = QSharedPointer<RequestFactory>(
44 new RequestFactory());
44 _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory());45 _processFactory = QSharedPointer<ProcessFactory>(new ProcessFactory());
45 _downloadFactory = QSharedPointer<DownloadFactory>(46 _downloadFactory = QSharedPointer<DownloadFactory>(
46 new DownloadFactory(_apparmor, _networkInfo, _nam,47 new DownloadFactory(_apparmor, _networkInfo, nam,
47 _processFactory));48 _processFactory));
48 _downloadsQueue = QSharedPointer<DownloadQueue>(49 _downloadsQueue = QSharedPointer<DownloadQueue>(
49 new DownloadQueue(_networkInfo));50 new DownloadQueue(_networkInfo));
@@ -91,8 +92,17 @@
91 Q_UNUSED(path);92 Q_UNUSED(path);
92 }93 }
9394
95 QList<QSslCertificate> acceptedCertificates() {
96 return _downloadFactory->acceptedCertificates();
97 }
98
99 void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
100 qDebug() << __PRETTY_FUNCTION__ << certs;
101 _downloadFactory->setAcceptedCertificates(certs);
102 }
103
94 void onDownloadsChanged(QString path) {104 void onDownloadsChanged(QString path) {
95 qDebug() << __FUNCTION__ << path;105 qDebug() << __PRETTY_FUNCTION__ << path;
96 Q_Q(DownloadManager);106 Q_Q(DownloadManager);
97 emit q->sizeChanged(_downloadsQueue->size());107 emit q->sizeChanged(_downloadsQueue->size());
98 }108 }
@@ -188,7 +198,6 @@
188 qulonglong _throttle;198 qulonglong _throttle;
189 QSharedPointer<AppArmor> _apparmor;199 QSharedPointer<AppArmor> _apparmor;
190 QSharedPointer<SystemNetworkInfo> _networkInfo;200 QSharedPointer<SystemNetworkInfo> _networkInfo;
191 QSharedPointer<RequestFactory> _nam;
192 QSharedPointer<ProcessFactory> _processFactory;201 QSharedPointer<ProcessFactory> _processFactory;
193 QSharedPointer<DownloadFactory> _downloadFactory;202 QSharedPointer<DownloadFactory> _downloadFactory;
194 QSharedPointer<DownloadQueue> _downloadsQueue;203 QSharedPointer<DownloadQueue> _downloadsQueue;
@@ -226,6 +235,19 @@
226 d->loadPreviewsDownloads(path);235 d->loadPreviewsDownloads(path);
227}236}
228237
238QList<QSslCertificate>
239DownloadManager::acceptedCertificates() {
240 Q_D(DownloadManager);
241 return d->acceptedCertificates();
242}
243
244
245void
246DownloadManager::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
247 Q_D(DownloadManager);
248 return d->setAcceptedCertificates(certs);
249}
250
229qulonglong251qulonglong
230DownloadManager::defaultThrottle() {252DownloadManager::defaultThrottle() {
231 Q_D(DownloadManager);253 Q_D(DownloadManager);
232254
=== modified file 'libubuntudownloadmanager/download_manager.h'
--- libubuntudownloadmanager/download_manager.h 2013-09-09 10:30:18 +0000
+++ libubuntudownloadmanager/download_manager.h 2013-09-18 11:41:58 +0000
@@ -24,6 +24,7 @@
24#include <QtDBus/QDBusObjectPath>24#include <QtDBus/QDBusObjectPath>
25#include <QtDBus/QDBusContext>25#include <QtDBus/QDBusContext>
26#include <QSharedPointer>26#include <QSharedPointer>
27#include <QSslCertificate>
27#include "./dbus_connection.h"28#include "./dbus_connection.h"
28#include "./download.h"29#include "./download.h"
29#include "./download_queue.h"30#include "./download_queue.h"
@@ -44,8 +45,13 @@
44 DownloadFactory* downloadFactory,45 DownloadFactory* downloadFactory,
45 DownloadQueue* queue,46 DownloadQueue* queue,
46 QObject *parent = 0);47 QObject *parent = 0);
48
47 void loadPreviewsDownloads(const QString &path);49 void loadPreviewsDownloads(const QString &path);
4850
51 // mainly for testing purposes
52 virtual QList<QSslCertificate> acceptedCertificates();
53 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
54
49 public slots: // NOLINT(whitespace/indent)55 public slots: // NOLINT(whitespace/indent)
50 QDBusObjectPath createDownload(DownloadStruct download);56 QDBusObjectPath createDownload(DownloadStruct download);
5157
5258
=== modified file 'libubuntudownloadmanager/request_factory.cpp'
--- libubuntudownloadmanager/request_factory.cpp 2013-07-23 16:03:10 +0000
+++ libubuntudownloadmanager/request_factory.cpp 2013-09-18 11:41:58 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include <QNetworkAccessManager>19#include <QNetworkAccessManager>
20#include <QSslError>
20#include "./request_factory.h"21#include "./request_factory.h"
2122
22/*23/*
@@ -27,24 +28,41 @@
27 Q_DECLARE_PUBLIC(RequestFactory)28 Q_DECLARE_PUBLIC(RequestFactory)
2829
29 public:30 public:
30 explicit RequestFactoryPrivate(RequestFactory* parent);31 explicit RequestFactoryPrivate(RequestFactory* parent)
3132 : q_ptr(parent) {
32 NetworkReply* get(const QNetworkRequest& request);33 _nam = new QNetworkAccessManager();
34 }
35
36 NetworkReply* get(const QNetworkRequest& request) {
37 QNetworkReply* reply = _nam->get(request);
38
39 if (_certs.count() > 0) {
40 // build the expected ssl errors
41 QList<QSslError> expectedSslErrors;
42 foreach(const QSslCertificate& certificate, _certs) {
43 QSslError error(QSslError::SelfSignedCertificate, certificate);
44 expectedSslErrors.append(error);
45 }
46 reply->ignoreSslErrors(expectedSslErrors);
47 }
48
49 return new NetworkReply(reply);
50 }
51
52 QList<QSslCertificate> acceptedCertificates() {
53 return _certs;
54 }
55
56 void setAcceptedCertificates(const QList<QSslCertificate>& certs) {
57 _certs = certs;
58 }
59
33 private:60 private:
61 QList<QSslCertificate> _certs;
34 QNetworkAccessManager* _nam;62 QNetworkAccessManager* _nam;
35 RequestFactory* q_ptr;63 RequestFactory* q_ptr;
36};64};
3765
38RequestFactoryPrivate::RequestFactoryPrivate(RequestFactory* parent)
39 : q_ptr(parent) {
40 _nam = new QNetworkAccessManager();
41}
42
43NetworkReply*
44RequestFactoryPrivate::get(const QNetworkRequest& request) {
45 return new NetworkReply(_nam->get(request));
46}
47
48/*66/*
49 * PUBLIC IMPLEMENTATION67 * PUBLIC IMPLEMENTATION
50 */68 */
@@ -59,3 +77,15 @@
59 Q_D(RequestFactory);77 Q_D(RequestFactory);
60 return d->get(request);78 return d->get(request);
61}79}
80
81QList<QSslCertificate>
82RequestFactory::acceptedCertificates() {
83 Q_D(RequestFactory);
84 return d->acceptedCertificates();
85}
86
87void
88RequestFactory::setAcceptedCertificates(const QList<QSslCertificate>& certs) {
89 Q_D(RequestFactory);
90 d->setAcceptedCertificates(certs);
91}
6292
=== modified file 'libubuntudownloadmanager/request_factory.h'
--- libubuntudownloadmanager/request_factory.h 2013-07-23 16:03:57 +0000
+++ libubuntudownloadmanager/request_factory.h 2013-09-18 11:41:58 +0000
@@ -21,6 +21,7 @@
2121
22#include <QNetworkRequest>22#include <QNetworkRequest>
23#include <QObject>23#include <QObject>
24#include <QSslCertificate>
24#include "./app-downloader-lib_global.h"25#include "./app-downloader-lib_global.h"
25#include "./network_reply.h"26#include "./network_reply.h"
2627
@@ -34,6 +35,10 @@
3435
35 virtual NetworkReply* get(const QNetworkRequest& request);36 virtual NetworkReply* get(const QNetworkRequest& request);
3637
38 // mainly for testing purposes
39 virtual QList<QSslCertificate> acceptedCertificates();
40 virtual void setAcceptedCertificates(const QList<QSslCertificate>& certs);
41
37 private:42 private:
38 // use pimpl so that we can mantains ABI compatibility43 // use pimpl so that we can mantains ABI compatibility
39 RequestFactoryPrivate* d_ptr;44 RequestFactoryPrivate* d_ptr;
4045
=== modified file 'ubuntu-download-manager-tests/fake_application.cpp'
--- ubuntu-download-manager-tests/fake_application.cpp 2013-08-21 11:40:25 +0000
+++ ubuntu-download-manager-tests/fake_application.cpp 2013-09-18 11:41:58 +0000
@@ -16,7 +16,7 @@
16 * Boston, MA 02110-1301, USA.16 * Boston, MA 02110-1301, USA.
17 */17 */
1818
19#include "fake_application.h"19#include "./fake_application.h"
2020
21FakeApplication::FakeApplication(QObject *parent)21FakeApplication::FakeApplication(QObject *parent)
22 : Application(parent),22 : Application(parent),
@@ -35,3 +35,20 @@
35 _called.append(methodData);35 _called.append(methodData);
36 }36 }
37}37}
38
39QStringList
40FakeApplication::arguments() {
41 if (_recording) {
42 QList<QObject*> inParams;
43 QList<QObject*> outParams;
44 MethodParams params(inParams, outParams);
45 MethodData methodData("arguments", params);
46 _called.append(methodData);
47 }
48 return _args;
49}
50
51void
52FakeApplication::setArguments(QStringList args) {
53 _args = args;
54}
3855
=== modified file 'ubuntu-download-manager-tests/fake_application.h'
--- ubuntu-download-manager-tests/fake_application.h 2013-08-21 12:21:49 +0000
+++ ubuntu-download-manager-tests/fake_application.h 2013-09-18 11:41:58 +0000
@@ -30,6 +30,11 @@
30 explicit FakeApplication(QObject *parent = 0);30 explicit FakeApplication(QObject *parent = 0);
3131
32 void exit(int returnCode = 0) override;32 void exit(int returnCode = 0) override;
33
34 QStringList arguments() override;
35 void setArguments(QStringList args);
36 private:
37 QStringList _args;
33};38};
3439
35#endif // FAKE_APPLICATION_H40#endif // FAKE_APPLICATION_H
3641
=== modified file 'ubuntu-download-manager-tests/fake_download_manager.cpp'
--- ubuntu-download-manager-tests/fake_download_manager.cpp 2013-08-22 20:49:57 +0000
+++ ubuntu-download-manager-tests/fake_download_manager.cpp 2013-09-18 11:41:58 +0000
@@ -30,3 +30,27 @@
30 emit sizeChanged(size);30 emit sizeChanged(size);
31}31}
3232
33QList<QSslCertificate>
34FakeDownloadManager::acceptedCertificates() {
35 if (_recording) {
36 QList<QObject*> inParams;
37 QList<QObject*> outParams;
38 MethodParams params(inParams, outParams);
39 MethodData methodData("acceptedCertificates", params);
40 _called.append(methodData);
41 }
42 return DownloadManager::acceptedCertificates();
43}
44
45void
46FakeDownloadManager::setAcceptedCertificates(
47 const QList<QSslCertificate>& certs) {
48 if (_recording) {
49 QList<QObject*> inParams;
50 QList<QObject*> outParams;
51 MethodParams params(inParams, outParams);
52 MethodData methodData("setAcceptedCertificates", params);
53 _called.append(methodData);
54 }
55 DownloadManager::setAcceptedCertificates(certs);
56}
3357
=== modified file 'ubuntu-download-manager-tests/fake_download_manager.h'
--- ubuntu-download-manager-tests/fake_download_manager.h 2013-08-22 20:49:57 +0000
+++ ubuntu-download-manager-tests/fake_download_manager.h 2013-09-18 11:41:58 +0000
@@ -32,6 +32,8 @@
32 QObject *parent = 0);32 QObject *parent = 0);
3333
34 void emitSizeChaged(int size);34 void emitSizeChaged(int size);
35 QList<QSslCertificate> acceptedCertificates() override;
36 void setAcceptedCertificates(const QList<QSslCertificate>& certs) override;
35};37};
3638
37#endif // FAKE_DOWNLOAD_MANAGER_H39#endif // FAKE_DOWNLOAD_MANAGER_H
3840
=== modified file 'ubuntu-download-manager-tests/fake_request_factory.cpp'
--- ubuntu-download-manager-tests/fake_request_factory.cpp 2013-07-23 17:55:51 +0000
+++ ubuntu-download-manager-tests/fake_request_factory.cpp 2013-09-18 11:41:58 +0000
@@ -56,3 +56,28 @@
56 }56 }
57 return reply;57 return reply;
58}58}
59
60QList<QSslCertificate>
61FakeRequestFactory::acceptedCertificates() {
62 if (_recording) {
63 QList<QObject*> inParams;
64 QList<QObject*> outParams;
65 MethodParams params(inParams, outParams);
66 MethodData methodData("acceptedCertificates", params);
67 _called.append(methodData);
68 }
69 return RequestFactory::acceptedCertificates();
70}
71
72void
73FakeRequestFactory::setAcceptedCertificates(
74 const QList<QSslCertificate>& certs) {
75 if (_recording) {
76 QList<QObject*> inParams;
77 QList<QObject*> outParams;
78 MethodParams params(inParams, outParams);
79 MethodData methodData("setAcceptedCertificates", params);
80 _called.append(methodData);
81 }
82 RequestFactory::setAcceptedCertificates(certs);
83}
5984
=== modified file 'ubuntu-download-manager-tests/fake_request_factory.h'
--- ubuntu-download-manager-tests/fake_request_factory.h 2013-07-23 17:57:12 +0000
+++ ubuntu-download-manager-tests/fake_request_factory.h 2013-09-18 11:41:58 +0000
@@ -46,6 +46,8 @@
4646
47 // overriden methods used to fake the nam47 // overriden methods used to fake the nam
48 NetworkReply* get(const QNetworkRequest& request);48 NetworkReply* get(const QNetworkRequest& request);
49 QList<QSslCertificate> acceptedCertificates() override;
50 void setAcceptedCertificates(const QList<QSslCertificate>& certs) override;
49};51};
5052
51#endif // FAKE_QNETWORK_ACCESS_MANAGER_H53#endif // FAKE_QNETWORK_ACCESS_MANAGER_H
5254
=== modified file 'ubuntu-download-manager-tests/test_download_daemon.cpp'
--- ubuntu-download-manager-tests/test_download_daemon.cpp 2013-08-22 20:49:57 +0000
+++ ubuntu-download-manager-tests/test_download_daemon.cpp 2013-09-18 11:41:58 +0000
@@ -141,3 +141,44 @@
141 QCOMPARE(QString("exit"), calledMethods[0].methodName());141 QCOMPARE(QString("exit"), calledMethods[0].methodName());
142}142}
143143
144void
145TestDownloadDaemon::testDisableTimeout() {
146 _timer->record();
147
148 // set the args so that we disable the timeout
149 QStringList args;
150 args << "-disable-timeout";
151 _app->setArguments(args);
152
153 // assert that start is never called
154 _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
155 QList<MethodData> calledMethods = _timer->calledMethods();
156 QCOMPARE(0, calledMethods.count());
157}
158
159void
160TestDownloadDaemon::testSelfSignedCerts() {
161 _man->record();
162 QStringList args;
163 args << "-self-signed-certs" << "*.pem";
164 _app->setArguments(args);
165
166 // assert that we set the certs
167 _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
168 QList<MethodData> calledMethods = _man->calledMethods();
169 QCOMPARE(1, calledMethods.count());
170 QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName());
171}
172
173void
174TestDownloadDaemon::testSelfSignedCertsMissingPath() {
175 _man->record();
176 QStringList args;
177 args << "-self-signed-certs";
178 _app->setArguments(args);
179
180 // assert that we do not crash
181 _daemon = new DownloadDaemon(_app, _conn, _timer, _man, this);
182 QList<MethodData> calledMethods = _man->calledMethods();
183 QCOMPARE(1, calledMethods.count());
184}
144185
=== modified file 'ubuntu-download-manager-tests/test_download_daemon.h'
--- ubuntu-download-manager-tests/test_download_daemon.h 2013-08-22 20:49:57 +0000
+++ ubuntu-download-manager-tests/test_download_daemon.h 2013-09-18 11:41:58 +0000
@@ -43,6 +43,9 @@
43 void testTimerStop();43 void testTimerStop();
44 void testTimerStart();44 void testTimerStart();
45 void testTimeoutExit();45 void testTimeoutExit();
46 void testDisableTimeout();
47 void testSelfSignedCerts();
48 void testSelfSignedCertsMissingPath();
4649
47 private:50 private:
48 FakeTimer* _timer;51 FakeTimer* _timer;
4952
=== modified file 'ubuntu-download-manager-tests/test_download_manager.cpp'
--- ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-10 12:18:34 +0000
+++ ubuntu-download-manager-tests/test_download_manager.cpp 2013-09-18 11:41:58 +0000
@@ -20,7 +20,6 @@
20#include <download_factory.h>20#include <download_factory.h>
21#include <download_struct.h>21#include <download_struct.h>
22#include "./fake_process_factory.h"22#include "./fake_process_factory.h"
23#include "./fake_request_factory.h"
24#include "./fake_system_network_info.h"23#include "./fake_system_network_info.h"
25#include "./test_download_manager.h"24#include "./test_download_manager.h"
2625
@@ -35,10 +34,11 @@
35 _q = new FakeDownloadQueue(QSharedPointer<SystemNetworkInfo>(_networkInfo));34 _q = new FakeDownloadQueue(QSharedPointer<SystemNetworkInfo>(_networkInfo));
36 _uuidFactory = new FakeUuidFactory();35 _uuidFactory = new FakeUuidFactory();
37 _apparmor = new FakeAppArmor(QSharedPointer<UuidFactory>(_uuidFactory));36 _apparmor = new FakeAppArmor(QSharedPointer<UuidFactory>(_uuidFactory));
37 _requestFactory = new FakeRequestFactory();
38 _downloadFactory = new FakeDownloadFactory(38 _downloadFactory = new FakeDownloadFactory(
39 QSharedPointer<AppArmor>(_apparmor),39 QSharedPointer<AppArmor>(_apparmor),
40 QSharedPointer<SystemNetworkInfo>(_networkInfo),40 QSharedPointer<SystemNetworkInfo>(_networkInfo),
41 QSharedPointer<RequestFactory>(new FakeRequestFactory()),41 QSharedPointer<RequestFactory>(_requestFactory),
42 QSharedPointer<ProcessFactory>(new FakeProcessFactory()));42 QSharedPointer<ProcessFactory>(new FakeProcessFactory()));
43 _man = new DownloadManager(qSharedPointerCast<DBusConnection>(_conn),43 _man = new DownloadManager(qSharedPointerCast<DBusConnection>(_conn),
44 _networkInfo, _downloadFactory, _q);44 _networkInfo, _downloadFactory, _q);
@@ -471,3 +471,16 @@
471 QList<QVariant> arguments = spy.takeFirst();471 QList<QVariant> arguments = spy.takeFirst();
472 QCOMPARE(arguments.at(0).toInt(), size);472 QCOMPARE(arguments.at(0).toInt(), size);
473}473}
474
475void
476TestDownloadManager::testSetSelfSignedCerts() {
477 // assert that the factory does get the certs
478 _requestFactory->record();
479 QList<QSslCertificate> certs;
480 _man->setAcceptedCertificates(certs);
481
482 QList<MethodData> calledMethods = _requestFactory->calledMethods();
483 qDebug() << calledMethods;
484 QCOMPARE(1, calledMethods.count());
485 QCOMPARE(QString("setAcceptedCertificates"), calledMethods[0].methodName());
486}
474487
=== modified file 'ubuntu-download-manager-tests/test_download_manager.h'
--- ubuntu-download-manager-tests/test_download_manager.h 2013-09-10 12:18:34 +0000
+++ ubuntu-download-manager-tests/test_download_manager.h 2013-09-18 11:41:58 +0000
@@ -28,6 +28,7 @@
28#include "./fake_dbus_connection.h"28#include "./fake_dbus_connection.h"
29#include "./fake_download_queue.h"29#include "./fake_download_queue.h"
30#include "./fake_download_factory.h"30#include "./fake_download_factory.h"
31#include "./fake_request_factory.h"
31#include "./fake_uuid_factory.h"32#include "./fake_uuid_factory.h"
32#include "./fake_system_network_info.h"33#include "./fake_system_network_info.h"
3334
@@ -59,12 +60,14 @@
59 void testSetThrottleWithDownloads();60 void testSetThrottleWithDownloads();
60 void testSizeChangedEmittedOnAddition();61 void testSizeChangedEmittedOnAddition();
61 void testSizeChangedEmittedOnRemoval();62 void testSizeChangedEmittedOnRemoval();
63 void testSetSelfSignedCerts();
6264
63 private:65 private:
64 QCryptographicHash::Algorithm algoFromString(const QString& data);66 QCryptographicHash::Algorithm algoFromString(const QString& data);
6567
66 private:68 private:
67 FakeSystemNetworkInfo* _networkInfo;69 FakeSystemNetworkInfo* _networkInfo;
70 FakeRequestFactory* _requestFactory;
68 FakeDownloadFactory* _downloadFactory;71 FakeDownloadFactory* _downloadFactory;
69 QSharedPointer<FakeDBusConnection> _conn;72 QSharedPointer<FakeDBusConnection> _conn;
70 FakeDownloadQueue* _q;73 FakeDownloadQueue* _q;

Subscribers

People subscribed via source and target branches