Merge lp:~mandel/ubuntu-download-manager/valid-hash-method into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 128
Merged at revision: 138
Proposed branch: lp:~mandel/ubuntu-download-manager/valid-hash-method
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/valid-urls
Diff against target: 824 lines (+188/-70)
19 files modified
libubuntudownloadmanager/download_factory.cpp (+6/-6)
libubuntudownloadmanager/download_factory.h (+3/-4)
libubuntudownloadmanager/download_manager.cpp (+5/-7)
libubuntudownloadmanager/group_download.cpp (+15/-5)
libubuntudownloadmanager/group_download.h (+2/-2)
libubuntudownloadmanager/hash_algorithm.cpp (+8/-0)
libubuntudownloadmanager/hash_algorithm.h (+4/-0)
libubuntudownloadmanager/single_download.cpp (+11/-3)
libubuntudownloadmanager/single_download.h (+1/-2)
ubuntu-download-manager-tests/fake_download.cpp (+1/-1)
ubuntu-download-manager-tests/fake_download.h (+1/-1)
ubuntu-download-manager-tests/fake_download_factory.cpp (+3/-3)
ubuntu-download-manager-tests/fake_download_factory.h (+3/-3)
ubuntu-download-manager-tests/test_download.cpp (+50/-14)
ubuntu-download-manager-tests/test_download.h (+4/-1)
ubuntu-download-manager-tests/test_download_factory.cpp (+11/-10)
ubuntu-download-manager-tests/test_downloads_db.cpp (+4/-6)
ubuntu-download-manager-tests/test_group_download.cpp (+52/-1)
ubuntu-download-manager-tests/test_group_download.h (+4/-1)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/valid-hash-method
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
PS Jenkins bot continuous-integration Approve
Diego Sarmentero (community) Approve
Review via email: mp+187490@code.launchpad.net

Commit message

Return DBus error when the hash method is not known.

Description of the change

Return DBus error when the hash method is not known.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
127. By Manuel de la Peña

Merged valid-urls into valid-hash-method.

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

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

Merged valid-urls into valid-hash-method.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntudownloadmanager/download_factory.cpp'
2--- libubuntudownloadmanager/download_factory.cpp 2013-09-18 11:40:57 +0000
3+++ libubuntudownloadmanager/download_factory.cpp 2013-09-25 16:08:32 +0000
4@@ -94,7 +94,7 @@
5 Download* createDownload(const QString& dbusOwner,
6 const QUrl& url,
7 const QString& hash,
8- QCryptographicHash::Algorithm algo,
9+ const QString& algo,
10 const QVariantMap& metadata,
11 const QMap<QString, QString>& headers) {
12 QUuid id;
13@@ -114,7 +114,7 @@
14
15 Download* createDownload(const QString& dbusOwner,
16 StructList downloads,
17- QCryptographicHash::Algorithm algo,
18+ const QString& algo,
19 bool allowed3G,
20 const QVariantMap& metadata,
21 StringMap headers) {
22@@ -152,7 +152,7 @@
23 const QString& rootPath,
24 const QUrl& url,
25 const QString& hash,
26- QCryptographicHash::Algorithm algo,
27+ const QString& algo,
28 const QVariantMap& metadata,
29 const QMap<QString, QString>& headers) {
30 QUuid id;
31@@ -211,7 +211,7 @@
32 DownloadFactory::createDownload(const QString& dbusOwner,
33 const QUrl& url,
34 const QString& hash,
35- QCryptographicHash::Algorithm algo,
36+ const QString& algo,
37 const QVariantMap& metadata,
38 const QMap<QString, QString>& headers) {
39 Q_D(DownloadFactory);
40@@ -221,7 +221,7 @@
41 Download*
42 DownloadFactory::createDownload(const QString& dbusOwner,
43 StructList downloads,
44- QCryptographicHash::Algorithm algo,
45+ const QString& algo,
46 bool allowed3G,
47 const QVariantMap& metadata,
48 StringMap headers) {
49@@ -246,7 +246,7 @@
50 const QString& rootPath,
51 const QUrl& url,
52 const QString& hash,
53- QCryptographicHash::Algorithm algo,
54+ const QString& algo,
55 const QVariantMap& metadata,
56 const QMap<QString, QString>& headers) {
57 Q_D(DownloadFactory);
58
59=== modified file 'libubuntudownloadmanager/download_factory.h'
60--- libubuntudownloadmanager/download_factory.h 2013-09-18 11:40:57 +0000
61+++ libubuntudownloadmanager/download_factory.h 2013-09-25 16:08:32 +0000
62@@ -19,7 +19,6 @@
63 #ifndef DOWNLOADER_LIB_DOWNLOAD_FACTORY_H
64 #define DOWNLOADER_LIB_DOWNLOAD_FACTORY_H
65
66-#include <QCryptographicHash>
67 #include <QObject>
68 #include <QSharedPointer>
69 #include "./apparmor.h"
70@@ -50,13 +49,13 @@
71 virtual Download* createDownload(const QString& dbusOwner,
72 const QUrl& url,
73 const QString& hash,
74- QCryptographicHash::Algorithm algo,
75+ const QString& algo,
76 const QVariantMap& metadata,
77 const QMap<QString, QString>& headers);
78
79 virtual Download* createDownload(const QString& dbusOwner,
80 StructList downloads,
81- QCryptographicHash::Algorithm algo,
82+ const QString& algo,
83 bool allowed3G,
84 const QVariantMap& metadata,
85 StringMap headers);
86@@ -73,7 +72,7 @@
87 const QString& rootPath,
88 const QUrl& url,
89 const QString& hash,
90- QCryptographicHash::Algorithm algo,
91+ const QString& algo,
92 const QVariantMap& metadata,
93 const QMap<QString, QString>& headers);
94
95
96=== modified file 'libubuntudownloadmanager/download_manager.cpp'
97--- libubuntudownloadmanager/download_manager.cpp 2013-09-25 16:08:32 +0000
98+++ libubuntudownloadmanager/download_manager.cpp 2013-09-25 16:08:32 +0000
99@@ -20,7 +20,6 @@
100 #include <QRegExp>
101 #include "./apparmor.h"
102 #include "./download_queue.h"
103-#include "./hash_algorithm.h"
104 #include "./request_factory.h"
105 #include "./system_network_info.h"
106 #include "./download_manager.h"
107@@ -155,7 +154,7 @@
108
109 QDBusObjectPath createDownload(const QString& url,
110 const QString& hash,
111- QCryptographicHash::Algorithm algo,
112+ const QString& algo,
113 const QVariantMap& metadata,
114 StringMap headers) {
115 DownloadCreationFunc createDownloadFunc =
116@@ -173,7 +172,7 @@
117 }
118
119 QDBusObjectPath createDownloadGroup(StructList downloads,
120- QCryptographicHash::Algorithm algo,
121+ const QString& algo,
122 bool allowed3G,
123 const QVariantMap& metadata,
124 StringMap headers) {
125@@ -314,8 +313,7 @@
126 DownloadManager::createDownload(DownloadStruct download) {
127 Q_D(DownloadManager);
128 return d->createDownload(download.getUrl(), download.getHash(),
129- HashAlgorithm::getHashAlgo(download.getAlgorithm()),
130- download.getMetadata(), download.getHeaders());
131+ download.getAlgorithm(), download.getMetadata(), download.getHeaders());
132 }
133
134 QDBusObjectPath
135@@ -325,8 +323,8 @@
136 const QVariantMap& metadata,
137 StringMap headers) {
138 Q_D(DownloadManager);
139- return d->createDownloadGroup(downloads,
140- HashAlgorithm::getHashAlgo(algorithm), allowed3G, metadata, headers);
141+ return d->createDownloadGroup(downloads, algorithm, allowed3G, metadata,
142+ headers);
143 }
144
145 QList<QDBusObjectPath>
146
147=== modified file 'libubuntudownloadmanager/group_download.cpp'
148--- libubuntudownloadmanager/group_download.cpp 2013-09-25 16:08:32 +0000
149+++ libubuntudownloadmanager/group_download.cpp 2013-09-25 16:08:32 +0000
150@@ -18,6 +18,7 @@
151
152 #include <QDebug>
153 #include "./download_adaptor.h"
154+#include "./hash_algorithm.h"
155 #include "./single_download.h"
156 #include "./uuid_factory.h"
157 #include "./group_download.h"
158@@ -31,7 +32,7 @@
159
160 public:
161 GroupDownloadPrivate(QList<GroupDownloadStruct> downloads,
162- QCryptographicHash::Algorithm algo,
163+ const QString& algo,
164 bool isGSMDownloadAllowed,
165 QSharedPointer<SystemNetworkInfo> networkInfo,
166 QSharedPointer<DownloadFactory> downloadFactory,
167@@ -47,7 +48,7 @@
168 }
169
170 GroupDownloadPrivate(QList<GroupDownloadStruct> downloads,
171- QCryptographicHash::Algorithm algo,
172+ const QString& algo,
173 bool isGSMDownloadAllowed,
174 QSharedPointer<SystemNetworkInfo> networkInfo,
175 QSharedPointer<DownloadFactory> downFactory,
176@@ -64,12 +65,21 @@
177 }
178
179 void init(QList<GroupDownloadStruct> downloads,
180- QCryptographicHash::Algorithm algo,
181+ const QString& algo,
182 bool isGSMDownloadAllowed) {
183 Q_Q(GroupDownload);
184 QVariantMap metadata = q->metadata();
185 QMap<QString, QString> headers = q->headers();
186
187+ // check if the algo is correct if not do not even build the
188+ // single downloads
189+ if (!HashAlgorithm::isValidAlgo(algo)) {
190+ q->setIsValid(false);
191+ q->setLastError(
192+ QString("Invalid hash algorithm: '%1'").arg(algo));
193+ return;
194+ }
195+
196 // build downloads and add them to the q, it will take care of
197 // starting them etc..
198 foreach(GroupDownloadStruct download, downloads) {
199@@ -304,7 +314,7 @@
200 bool isConfined,
201 const QString& rootPath,
202 QList<GroupDownloadStruct> downloads,
203- QCryptographicHash::Algorithm algo,
204+ const QString& algo,
205 bool isGSMDownloadAllowed,
206 const QVariantMap& metadata,
207 const QMap<QString, QString>& headers,
208@@ -322,7 +332,7 @@
209 bool isConfined,
210 const QString& rootPath,
211 QList<GroupDownloadStruct> downloads,
212- QCryptographicHash::Algorithm algo,
213+ const QString& algo,
214 bool isGSMDownloadAllowed,
215 const QVariantMap& metadata,
216 const QMap<QString, QString>& headers,
217
218=== modified file 'libubuntudownloadmanager/group_download.h'
219--- libubuntudownloadmanager/group_download.h 2013-09-16 15:57:06 +0000
220+++ libubuntudownloadmanager/group_download.h 2013-09-25 16:08:32 +0000
221@@ -39,7 +39,7 @@
222 bool isConfined,
223 const QString& rootPath,
224 QList<GroupDownloadStruct> downloads,
225- QCryptographicHash::Algorithm algo,
226+ const QString& algo,
227 bool isGSMDownloadAllowed,
228 const QVariantMap& metadata,
229 const QMap<QString, QString>& headers,
230@@ -52,7 +52,7 @@
231 bool isConfined,
232 const QString& rootPath,
233 QList<GroupDownloadStruct> downloads,
234- QCryptographicHash::Algorithm algo,
235+ const QString& algo,
236 bool isGSMDownloadAllowed,
237 const QVariantMap& metadata,
238 const QMap<QString, QString>& headers,
239
240=== modified file 'libubuntudownloadmanager/hash_algorithm.cpp'
241--- libubuntudownloadmanager/hash_algorithm.cpp 2013-08-28 14:03:51 +0000
242+++ libubuntudownloadmanager/hash_algorithm.cpp 2013-09-25 16:08:32 +0000
243@@ -18,6 +18,9 @@
244
245 #include "./hash_algorithm.h"
246
247+QList<QString> HashAlgorithm::algoList = QList<QString>() << "md5" << "sha1"
248+ << "sha224" << "sha256" << "sha384" << "sha512";
249+
250 QCryptographicHash::Algorithm
251 HashAlgorithm::getHashAlgo(const QString& algorithm) {
252 // lowercase the algorithm just in case
253@@ -60,3 +63,8 @@
254 return "";
255 }
256 }
257+
258+bool
259+HashAlgorithm::isValidAlgo(const QString& algorithm) {
260+ return algoList.contains(algorithm.toLower());
261+}
262
263=== modified file 'libubuntudownloadmanager/hash_algorithm.h'
264--- libubuntudownloadmanager/hash_algorithm.h 2013-08-28 14:03:51 +0000
265+++ libubuntudownloadmanager/hash_algorithm.h 2013-09-25 16:08:32 +0000
266@@ -20,12 +20,16 @@
267 #define DOWNLOADER_LIB_HASH_ALGORITHM_H
268
269 #include <QCryptographicHash>
270+#include <QList>
271 #include <QString>
272
273 class HashAlgorithm {
274 public:
275 static QCryptographicHash::Algorithm getHashAlgo(const QString& algorithm);
276 static QString getHashAlgo(QCryptographicHash::Algorithm algorithm);
277+ static bool isValidAlgo(const QString& algorithm);
278+ private:
279+ static QList<QString> algoList;
280 };
281
282 #endif // DOWNLOADER_LIB_HASH_ALGORITHM_H
283
284=== modified file 'libubuntudownloadmanager/single_download.cpp'
285--- libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:32 +0000
286+++ libubuntudownloadmanager/single_download.cpp 2013-09-25 16:08:32 +0000
287@@ -17,12 +17,14 @@
288 */
289
290 #include <QBuffer>
291+#include <QCryptographicHash>
292 #include <QDir>
293 #include <QDebug>
294 #include <QStringList>
295 #include <QFile>
296 #include <QFileInfo>
297 #include <QSslError>
298+#include "./hash_algorithm.h"
299 #include "./single_download.h"
300 #include "./network_reply.h"
301 #include "./xdg_basedir.h"
302@@ -57,7 +59,7 @@
303
304 SingleDownloadPrivate(const QUrl& url,
305 const QString& hash,
306- QCryptographicHash::Algorithm algo,
307+ const QString& algo,
308 QSharedPointer<RequestFactory> nam,
309 QSharedPointer<ProcessFactory> processFactory,
310 SingleDownload* parent)
311@@ -65,11 +67,17 @@
312 : _totalSize(0),
313 _url(url),
314 _hash(hash),
315- _algo(algo),
316 _requestFactory(nam),
317 _processFactory(processFactory),
318 q_ptr(parent) {
319+ Q_Q(SingleDownload);
320 init();
321+ _algo = HashAlgorithm::getHashAlgo(algo);
322+ // check that the algorithm is correct if the hash is not emtpy
323+ if (!_hash.isEmpty() && !HashAlgorithm::isValidAlgo(algo)) {
324+ q->setIsValid(false);
325+ q->setLastError(QString("Invalid hash algorithm: '%1'").arg(algo));
326+ }
327 }
328
329 ~SingleDownloadPrivate() {
330@@ -502,7 +510,7 @@
331 const QString& rootPath,
332 const QUrl& url,
333 const QString& hash,
334- QCryptographicHash::Algorithm algo,
335+ const QString& algo,
336 const QVariantMap& metadata,
337 const QMap<QString, QString> &headers,
338 QSharedPointer<SystemNetworkInfo> networkInfo,
339
340=== modified file 'libubuntudownloadmanager/single_download.h'
341--- libubuntudownloadmanager/single_download.h 2013-09-16 15:57:06 +0000
342+++ libubuntudownloadmanager/single_download.h 2013-09-25 16:08:32 +0000
343@@ -19,7 +19,6 @@
344 #ifndef DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
345 #define DOWNLOADER_LIB_SINGLE_DOWNLOAD_H
346
347-#include <QCryptographicHash>
348 #include <QNetworkReply>
349 #include <QProcess>
350 #include <QSharedPointer>
351@@ -53,7 +52,7 @@
352 const QString& rootPath,
353 const QUrl& url,
354 const QString& hash,
355- QCryptographicHash::Algorithm algo,
356+ const QString& algo,
357 const QVariantMap& metadata,
358 const QMap<QString, QString>& headers,
359 QSharedPointer<SystemNetworkInfo> networkInfo,
360
361=== modified file 'ubuntu-download-manager-tests/fake_download.cpp'
362--- ubuntu-download-manager-tests/fake_download.cpp 2013-09-16 15:57:06 +0000
363+++ ubuntu-download-manager-tests/fake_download.cpp 2013-09-25 16:08:32 +0000
364@@ -41,7 +41,7 @@
365 const QString& rootPath,
366 const QUrl& url,
367 const QString& hash,
368- QCryptographicHash::Algorithm algo,
369+ const QString& algo,
370 const QVariantMap& metadata,
371 const QMap<QString, QString>& headers,
372 QSharedPointer<SystemNetworkInfo> networkInfo,
373
374=== modified file 'ubuntu-download-manager-tests/fake_download.h'
375--- ubuntu-download-manager-tests/fake_download.h 2013-09-16 15:57:06 +0000
376+++ ubuntu-download-manager-tests/fake_download.h 2013-09-25 16:08:32 +0000
377@@ -45,7 +45,7 @@
378 const QString& rootPath,
379 const QUrl& url,
380 const QString& hash,
381- QCryptographicHash::Algorithm algo,
382+ const QString& algo,
383 const QVariantMap& metadata,
384 const QMap<QString, QString> &headers,
385 QSharedPointer<SystemNetworkInfo> networkInfo,
386
387=== modified file 'ubuntu-download-manager-tests/fake_download_factory.cpp'
388--- ubuntu-download-manager-tests/fake_download_factory.cpp 2013-09-18 10:18:24 +0000
389+++ ubuntu-download-manager-tests/fake_download_factory.cpp 2013-09-25 16:08:32 +0000
390@@ -60,7 +60,7 @@
391 FakeDownloadFactory::createDownload(const QString& downloadOwner,
392 const QUrl& url,
393 const QString& hash,
394- QCryptographicHash::Algorithm algo,
395+ const QString& algo,
396 const QVariantMap& metadata,
397 const QMap<QString, QString>& headers) {
398 qDebug() << __PRETTY_FUNCTION__;
399@@ -84,7 +84,7 @@
400 Download*
401 FakeDownloadFactory::createDownload(const QString& downloadOwner,
402 StructList downloads,
403- QCryptographicHash::Algorithm algo,
404+ const QString& algo,
405 bool allowed3G,
406 const QVariantMap& metadata,
407 StringMap headers) {
408@@ -137,7 +137,7 @@
409 const QString& rootPath,
410 const QUrl& url,
411 const QString& hash,
412- QCryptographicHash::Algorithm algo,
413+ const QString& algo,
414 const QVariantMap& metadata,
415 const QMap<QString, QString>& headers) {
416 QUuid id;
417
418=== modified file 'ubuntu-download-manager-tests/fake_download_factory.h'
419--- ubuntu-download-manager-tests/fake_download_factory.h 2013-09-18 10:18:24 +0000
420+++ ubuntu-download-manager-tests/fake_download_factory.h 2013-09-25 16:08:32 +0000
421@@ -42,13 +42,13 @@
422 Download* createDownload(const QString& downloadOwner,
423 const QUrl& url,
424 const QString& hash,
425- QCryptographicHash::Algorithm algo,
426+ const QString& algo,
427 const QVariantMap& metadata,
428 const QMap<QString, QString>& headers) override;
429
430 Download* createDownload(const QString& downloadOwner,
431 StructList downloads,
432- QCryptographicHash::Algorithm algo,
433+ const QString& algo,
434 bool allowed3G,
435 const QVariantMap& metadata,
436 StringMap headers) override;
437@@ -63,7 +63,7 @@
438 const QString& rootPath,
439 const QUrl& url,
440 const QString& hash,
441- QCryptographicHash::Algorithm algo,
442+ const QString& algo,
443 const QVariantMap& metadata,
444 const QMap<QString, QString>& headers) override;
445
446
447=== modified file 'ubuntu-download-manager-tests/test_download.cpp'
448--- ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:32 +0000
449+++ ubuntu-download-manager-tests/test_download.cpp 2013-09-25 16:08:32 +0000
450@@ -21,6 +21,7 @@
451 #include <QNetworkRequest>
452 #include <QSignalSpy>
453 #include <QSslError>
454+#include <hash_algorithm.h>
455 #include "./fake_network_reply.h"
456 #include "./fake_process.h"
457 #include "./test_download.h"
458@@ -71,7 +72,7 @@
459 _rootPath = _testDir.absolutePath();
460 _path = "random path to dbus";
461 _url = QUrl("http://ubuntu.com");
462- _algo = QCryptographicHash::Sha256;
463+ _algo = "Sha256";
464 _networkInfo = new FakeSystemNetworkInfo();
465 _reqFactory = new FakeRequestFactory();
466 _processFactory = new FakeProcessFactory();
467@@ -138,20 +139,20 @@
468 QTest::addColumn<QString>("path");
469 QTest::addColumn<QUrl>("url");
470 QTest::addColumn<QString>("hash");
471- QTest::addColumn<int>("algo");
472+ QTest::addColumn<QString>("algo");
473
474 QTest::newRow("First row") << QUuid::createUuid()
475 << "/path/to/first/app" << QUrl("http://ubuntu.com")
476- << "my-first-hash" << static_cast<int>(QCryptographicHash::Md4);
477+ << "my-first-hash" << "md5";
478 QTest::newRow("Second row") << QUuid::createUuid()
479 << "/path/to/second/app" << QUrl("http://ubuntu.com/juju")
480- << "my-second-hash" << static_cast<int>(QCryptographicHash::Md5);
481+ << "my-second-hash" << "Md5";
482 QTest::newRow("Third row") << QUuid::createUuid()
483 << "/path/to/third/app" << QUrl("http://ubuntu.com/tablet")
484- << "my-third-hash" << static_cast<int>(QCryptographicHash::Sha1);
485+ << "my-third-hash" << "Sha1";
486 QTest::newRow("Last row") << QUuid::createUuid()
487 << "/path/to/last/app" << QUrl("http://ubuntu.com/phone")
488- << "my-last-hash" << static_cast<int>(QCryptographicHash::Sha256);
489+ << "my-last-hash" << "Sha256";
490 }
491
492 void
493@@ -160,11 +161,10 @@
494 QFETCH(QString, path);
495 QFETCH(QUrl, url);
496 QFETCH(QString, hash);
497- QFETCH(int, algo);
498+ QFETCH(QString, algo);
499
500 SingleDownload* download = new SingleDownload(id, path, _isConfined,
501- _rootPath, url, hash,
502- (QCryptographicHash::Algorithm)algo, _metadata, _headers,
503+ _rootPath, url, hash, algo, _metadata, _headers,
504 QSharedPointer<SystemNetworkInfo>(_networkInfo),
505 QSharedPointer<RequestFactory>(_reqFactory),
506 QSharedPointer<ProcessFactory>(_processFactory));
507@@ -173,7 +173,7 @@
508 QCOMPARE(download->path(), path);
509 QCOMPARE(download->url(), url);
510 QCOMPARE(download->hash(), hash);
511- QCOMPARE(static_cast<int>(download->hashAlgorithm()), algo);
512+ QCOMPARE(download->hashAlgorithm(), HashAlgorithm::getHashAlgo(algo));
513 QCOMPARE(download->state(), Download::IDLE);
514 QCOMPARE(download->progress(), 0ULL);
515 QCOMPARE(download->totalSize(), 0ULL);
516@@ -942,15 +942,17 @@
517 QByteArray secondData(200, 's');
518 QByteArray thirdData(300, 't');
519 QByteArray lastData(400, 'l');
520+ QCryptographicHash::Algorithm algorithm =
521+ HashAlgorithm::getHashAlgo(_algo);
522
523 QTest::newRow("First row") << firstData
524- << QString(QCryptographicHash::hash(firstData, _algo).toHex());
525+ << QString(QCryptographicHash::hash(firstData, algorithm).toHex());
526 QTest::newRow("Second row") << secondData
527- << QString(QCryptographicHash::hash(secondData, _algo).toHex());
528+ << QString(QCryptographicHash::hash(secondData, algorithm).toHex());
529 QTest::newRow("Third row") << thirdData
530- << QString(QCryptographicHash::hash(thirdData, _algo).toHex());
531+ << QString(QCryptographicHash::hash(thirdData, algorithm).toHex());
532 QTest::newRow("Last row") << lastData
533- << QString(QCryptographicHash::hash(lastData, _algo).toHex());
534+ << QString(QCryptographicHash::hash(lastData, algorithm).toHex());
535 }
536
537 void
538@@ -1748,3 +1750,37 @@
539
540 QVERIFY(download->isValid());
541 }
542+
543+void
544+TestDownload::testInvalidHashAlgorithm() {
545+ SingleDownload* download = new SingleDownload(_id, _path, _isConfined,
546+ _rootPath, _url,
547+ "hash", "not-valid-algo", _metadata, _headers,
548+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
549+ QSharedPointer<RequestFactory>(_reqFactory),
550+ QSharedPointer<ProcessFactory>(_processFactory));
551+ QVERIFY(!download->isValid());
552+}
553+
554+void
555+TestDownload::testValidHashAlgorithm_data() {
556+ QTest::addColumn<QString>("algo");
557+
558+ QTest::newRow("md5") << "md5";
559+ QTest::newRow("sha1") << "sha1";
560+ QTest::newRow("sha224") << "sha224";
561+ QTest::newRow("sha256") << "sha256";
562+ QTest::newRow("sha384") << "sha384";
563+ QTest::newRow("sha512") << "sha512";
564+}
565+
566+void
567+TestDownload::testValidHashAlgorithm() {
568+ QFETCH(QString, algo);
569+ SingleDownload* download = new SingleDownload(_id, _path, _isConfined,
570+ _rootPath, _url, "hash", algo, _metadata, _headers,
571+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
572+ QSharedPointer<RequestFactory>(_reqFactory),
573+ QSharedPointer<ProcessFactory>(_processFactory));
574+ QVERIFY(download->isValid());
575+}
576
577=== modified file 'ubuntu-download-manager-tests/test_download.h'
578--- ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:32 +0000
579+++ ubuntu-download-manager-tests/test_download.h 2013-09-25 16:08:32 +0000
580@@ -126,6 +126,9 @@
581 // isValid tests
582 void testInvalidUrl();
583 void testValidUrl();
584+ void testInvalidHashAlgorithm();
585+ void testValidHashAlgorithm_data();
586+ void testValidHashAlgorithm();
587
588 private:
589 bool removeDir(const QString& dirName);
590@@ -139,7 +142,7 @@
591 QMap<QString, QString> _headers;
592 QString _path;
593 QUrl _url;
594- QCryptographicHash::Algorithm _algo;
595+ QString _algo;
596 FakeSystemNetworkInfo* _networkInfo;
597 FakeRequestFactory* _reqFactory;
598 FakeProcessFactory* _processFactory;
599
600=== modified file 'ubuntu-download-manager-tests/test_download_factory.cpp'
601--- ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-18 10:18:24 +0000
602+++ ubuntu-download-manager-tests/test_download_factory.cpp 2013-09-25 16:08:32 +0000
603@@ -17,6 +17,7 @@
604 */
605
606 #include <single_download.h>
607+#include <hash_algorithm.h>
608 #include "./test_download_factory.h"
609
610 TestDownloadFactory::TestDownloadFactory(QObject *parent)
611@@ -66,7 +67,7 @@
612 _apparmor->record();
613
614 QString hash = "my-hash";
615- QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
616+ QString algo = "Md5";
617
618 // same as above but assert hash and hash algo
619 Download* download = _downFactory->createDownload("", QUrl(),
620@@ -83,7 +84,7 @@
621
622 SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
623 QCOMPARE(hash, single->hash());
624- QCOMPARE(algo, single->hashAlgorithm());
625+ QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
626 }
627
628 void
629@@ -93,7 +94,7 @@
630 // create a download, assert that it was
631 // created and that the id and the path are correctly set
632 Download* download = _downFactory->createDownload("",
633- QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
634+ QList<GroupDownloadStruct>(), "Md5",
635 true, QVariantMap(), QMap<QString, QString>());
636
637 QList<MethodData> calledMethods = _apparmor->calledMethods();
638@@ -160,7 +161,7 @@
639 metadata["objectpath"] = id.toString();
640
641 QString hash = "my-hash";
642- QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
643+ QString algo = "Md5";
644
645 // same as above but assert hash and hash algo
646 Download* download = _downFactory->createDownload("", QUrl(),
647@@ -175,7 +176,7 @@
648
649 SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
650 QCOMPARE(hash, single->hash());
651- QCOMPARE(algo, single->hashAlgorithm());
652+ QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
653 }
654
655 void
656@@ -186,7 +187,7 @@
657 metadata["objectpath"] = "bad-id";
658
659 QString hash = "my-hash";
660- QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
661+ QString algo = "Md5";
662
663 // same as above but assert hash and hash algo
664 Download* download = _downFactory->createDownload("", QUrl(),
665@@ -203,7 +204,7 @@
666
667 SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
668 QCOMPARE(hash, single->hash());
669- QCOMPARE(algo, single->hashAlgorithm());
670+ QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
671 }
672
673 void
674@@ -218,7 +219,7 @@
675 metadata["objectpath"] = id.toString();
676
677 Download* download = _downFactory->createDownload("",
678- QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
679+ QList<GroupDownloadStruct>(), "Md5",
680 true, metadata, QMap<QString, QString>());
681
682 QList<MethodData> calledMethods = _apparmor->calledMethods();
683@@ -239,7 +240,7 @@
684 metadata["objectpath"] = "bad-id";
685
686 Download* download = _downFactory->createDownload("",
687- QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
688+ QList<GroupDownloadStruct>(), "Md5",
689 true, metadata, QMap<QString, QString>());
690
691 QList<MethodData> calledMethods = _apparmor->calledMethods();
692@@ -273,7 +274,7 @@
693 TestDownloadFactory::testCreateDownloadForGroupWithHash() {
694 _apparmor->record();
695 Download* download = _downFactory->createDownloadForGroup(true, "", QUrl(),
696- "", QCryptographicHash::Md5, QVariantMap(), QMap<QString, QString>());
697+ "", "Md5", QVariantMap(), QMap<QString, QString>());
698
699 QList<MethodData> calledMethods = _apparmor->calledMethods();
700 QCOMPARE(1, calledMethods.count());
701
702=== modified file 'ubuntu-download-manager-tests/test_downloads_db.cpp'
703--- ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-16 15:57:06 +0000
704+++ ubuntu-download-manager-tests/test_downloads_db.cpp 2013-09-25 16:08:32 +0000
705@@ -182,8 +182,7 @@
706 QSharedPointer<ProcessFactory>(new FakeProcessFactory());
707
708 FakeDownload* download = new FakeDownload(id, path, false, "", url, hash,
709- HashAlgorithm::getHashAlgo(hashAlgoString), metadata, headers,
710- networkInfo, nam, processFactory);
711+ hashAlgoString, metadata, headers, networkInfo, nam, processFactory);
712
713 _db->storeSingleDownload(download);
714 // query that the download is there and that the data is correct
715@@ -280,16 +279,15 @@
716 QSharedPointer<ProcessFactory>(new FakeProcessFactory());
717
718 FakeDownload* download = new FakeDownload(id, path, true, "", url, hash,
719- HashAlgorithm::getHashAlgo(hashAlgoString), metadata, headers,
720- networkInfo, nam, processFactory);
721+ hashAlgoString, metadata, headers, networkInfo, nam, processFactory);
722
723 _db->storeSingleDownload(download);
724
725 // create a second download with same id but a diff path to test is update
726 QString newPath = path + path;
727 FakeDownload* secondDownload = new FakeDownload(id, newPath, true, "",
728- url, hash, HashAlgorithm::getHashAlgo(hashAlgoString), metadata,
729- headers, networkInfo, nam, processFactory);
730+ url, hash, hashAlgoString, metadata, headers, networkInfo, nam,
731+ processFactory);
732
733 _db->storeSingleDownload(secondDownload);
734
735
736=== modified file 'ubuntu-download-manager-tests/test_group_download.cpp'
737--- ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:32 +0000
738+++ ubuntu-download-manager-tests/test_group_download.cpp 2013-09-25 16:08:32 +0000
739@@ -31,7 +31,7 @@
740 _path = "/group/dbus/path";
741 _isConfined = true;
742 _rootPath = "/random/dbus/path";
743- _algo = QCryptographicHash::Md5;
744+ _algo = "Md5";
745 _isGSMDownloadAllowed = true;
746 _networkInfo = new FakeSystemNetworkInfo();
747 _nam = new FakeRequestFactory();
748@@ -801,3 +801,54 @@
749
750 QVERIFY(group->isValid());
751 }
752+
753+void
754+TestGroupDownload::testInvalidHashAlgorithm() {
755+ QList<GroupDownloadStruct> downloadsStruct;
756+ downloadsStruct.append(GroupDownloadStruct("http://one.ubuntu.com",
757+ "local_file", ""));
758+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
759+ "other_local_file", ""));
760+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
761+ "other_reddit_local_file", ""));
762+
763+ GroupDownload* group = new GroupDownload(_id, _path, false, _rootPath,
764+ downloadsStruct, "wrong", _isGSMDownloadAllowed, _metadata, _headers,
765+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
766+ QSharedPointer<DownloadFactory>(_downloadFactory),
767+ QSharedPointer<FileManager>(_fileManager));
768+
769+ QVERIFY(!group->isValid());
770+}
771+
772+void
773+TestGroupDownload::testValidHashAlgorithm_data() {
774+ QTest::addColumn<QString>("algo");
775+
776+ QTest::newRow("md5") << "md5";
777+ QTest::newRow("sha1") << "sha1";
778+ QTest::newRow("sha224") << "sha224";
779+ QTest::newRow("sha256") << "sha256";
780+ QTest::newRow("sha384") << "sha384";
781+ QTest::newRow("sha512") << "sha512";
782+}
783+
784+void
785+TestGroupDownload::testValidHashAlgorithm() {
786+ QFETCH(QString, algo);
787+ QList<GroupDownloadStruct> downloadsStruct;
788+ downloadsStruct.append(GroupDownloadStruct("http://one.ubuntu.com",
789+ "local_file", ""));
790+ downloadsStruct.append(GroupDownloadStruct("http://ubuntu.com",
791+ "other_local_file", ""));
792+ downloadsStruct.append(GroupDownloadStruct("http://reddit.com",
793+ "other_reddit_local_file", ""));
794+
795+ GroupDownload* group = new GroupDownload(_id, _path, false, _rootPath,
796+ downloadsStruct, algo, _isGSMDownloadAllowed, _metadata, _headers,
797+ QSharedPointer<SystemNetworkInfo>(_networkInfo),
798+ QSharedPointer<DownloadFactory>(_downloadFactory),
799+ QSharedPointer<FileManager>(_fileManager));
800+
801+ QVERIFY(group->isValid());
802+}
803
804=== modified file 'ubuntu-download-manager-tests/test_group_download.h'
805--- ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:32 +0000
806+++ ubuntu-download-manager-tests/test_group_download.h 2013-09-25 16:08:32 +0000
807@@ -71,13 +71,16 @@
808 // isValid tests
809 void testInvalidUrl();
810 void testValidUrl();
811+ void testInvalidHashAlgorithm();
812+ void testValidHashAlgorithm_data();
813+ void testValidHashAlgorithm();
814
815 private:
816 QUuid _id;
817 QString _path;
818 bool _isConfined;
819 QString _rootPath;
820- QCryptographicHash::Algorithm _algo;
821+ QString _algo;
822 bool _isGSMDownloadAllowed;
823 QVariantMap _metadata;
824 QMap<QString, QString> _headers;

Subscribers

People subscribed via source and target branches