Merge lp:~diegosarmentero/clickmanager-plugin/sign-url into lp:clickmanager-plugin

Proposed by Diego Sarmentero on 2013-09-25
Status: Merged
Approved by: Diego Sarmentero on 2013-09-26
Approved revision: 22
Merged at revision: 12
Proposed branch: lp:~diegosarmentero/clickmanager-plugin/sign-url
Merge into: lp:clickmanager-plugin
Diff against target: 839 lines (+246/-38)
27 files modified
debian/control (+3/-0)
src/application.cpp (+13/-4)
src/application.h (+10/-1)
src/clickmanager.cpp (+46/-11)
src/clickmanager.h (+19/-7)
src/clickmanager_plugin.cpp (+2/-0)
src/download/downloader.cpp (+6/-2)
src/download/downloader.h (+6/-2)
src/download_tracker.cpp (+4/-0)
src/download_tracker.h (+5/-1)
src/network/network.cpp (+3/-0)
src/network/network.h (+4/-0)
src/src.pro (+3/-2)
tests/fakedownloader.cpp (+11/-2)
tests/fakedownloader.h (+6/-2)
tests/fakenetwork.cpp (+4/-0)
tests/fakenetwork.h (+4/-0)
tests/fakeprocess.cpp (+4/-0)
tests/fakeprocess.h (+4/-0)
tests/fakessoservice.cpp (+16/-0)
tests/fakessoservice.h (+27/-0)
tests/test_main.cpp (+2/-0)
tests/testapplication.cpp (+4/-0)
tests/testapplication.h (+4/-0)
tests/testclickmanager.cpp (+23/-0)
tests/testclickmanager.h (+6/-0)
tests/tests.pro (+7/-4)
To merge this branch: bzr merge lp:~diegosarmentero/clickmanager-plugin/sign-url
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-09-26
Alejandro J. Cura (community) Approve on 2013-09-26
dobey (community) 2013-09-25 Abstain on 2013-09-26
Review via email: mp+187602@code.launchpad.net

Commit message

- Support signed url.
- Improve error handling.

Description of the change

Use ubuntuone-credentials to get the token and use that token to sign the urls when a click download needs to be started.

To post a comment you must log in.
20. By Diego Sarmentero on 2013-09-25

update debian/control to include new dependencies

dobey (dobey) wrote :

+#include <ubuntuoneauth-2.0/ssoservice.h>

This is wrong. You should only include <ssoservice> as the ubuntuoneauth-2.0 should come from the INCLUDES paths passed to the compiler (as -I/usr/include/ubuntuoneauth-2.0/ for example).

review: Needs Fixing
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
21. By Diego Sarmentero on 2013-09-26

fixing includes

Diego Sarmentero (diegosarmentero) wrote :

> +#include <ubuntuoneauth-2.0/ssoservice.h>
>
> This is wrong. You should only include <ssoservice> as the ubuntuoneauth-2.0
> should come from the INCLUDES paths passed to the compiler (as
> -I/usr/include/ubuntuoneauth-2.0/ for example).

Fixed

PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
dobey (dobey) :
review: Abstain
Alejandro J. Cura (alecu) wrote :

While reviewing this I found a bug for clickmanager-plugin here: #1231422, but this branch looks good to me.

review: Approve
dobey (dobey) wrote :

I'm abstaining for now, because this really should be 2 separate branches, one which adds the ClickPlugin namespace changes, and another which depends on that one, which adds the URL signing bits. I don't want to block this too long, given our current time frame, but I do want to state such changes should be split into separate branches when they are this invasive. So I am choosing to Abstain rather than vote Needs Fixing.

22. By Diego Sarmentero on 2013-09-26

* Automatic snapshot from revision 9
[ Ɓukasz 'sil2100' Zemczak ]
* Automatic snapshot from revision 5 (bootstrap)
[ Ubuntu daily release ]
* Automatic snapshot from revision 6

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 'debian/control'
2--- debian/control 2013-09-18 13:27:46 +0000
3+++ debian/control 2013-09-26 16:47:31 +0000
4@@ -4,6 +4,9 @@
5 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
6 Build-Depends: debhelper (>= 9),
7 libapt-pkg-dev,
8+ libubuntuoneauth-2.0-dev,
9+ libsignon-qt5-dev,
10+ libaccounts-qt5-dev,
11 qt5-default,
12 qt5-qmake,
13 qtbase5-dev,
14
15=== modified file 'src/application.cpp'
16--- src/application.cpp 2013-09-13 10:12:01 +0000
17+++ src/application.cpp 2013-09-26 16:47:31 +0000
18@@ -21,6 +21,8 @@
19 #include <apt-pkg/debversion.h>
20 #include <QDebug>
21
22+namespace ClickPlugin {
23+
24 Application::Application(QQuickItem *parent) :
25 QQuickItem(parent)
26 {
27@@ -47,13 +49,20 @@
28 {
29 this->m_remote_version = version;
30
31- debVersioningSystem debVersion;
32-
33- int result = debVersion.CmpVersion(this->m_local_version.toUtf8().data(),
34- this->m_remote_version.toUtf8().data());
35+ int result = debVS.CmpVersion(this->m_local_version.toUtf8().data(),
36+ this->m_remote_version.toUtf8().data());
37 if(result == -1) {
38 this->m_update = true;
39 }else{
40 this->m_update = false;
41 }
42 }
43+
44+void Application::setError(QString error) {
45+ this->m_error = error;
46+ if(!this->m_error.isEmpty()) {
47+ emit this->errorChanged();
48+ }
49+}
50+
51+}
52
53=== modified file 'src/application.h'
54--- src/application.h 2013-09-13 10:12:01 +0000
55+++ src/application.h 2013-09-26 16:47:31 +0000
56@@ -22,6 +22,8 @@
57 #include <QQuickItem>
58 #include <QString>
59
60+namespace ClickPlugin {
61+
62 class Application : public QQuickItem
63 {
64 Q_OBJECT
65@@ -36,6 +38,7 @@
66 Q_PROPERTY(bool updateState READ updateState WRITE setUpdateState NOTIFY updatesStateChanged)
67 Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
68 Q_PROPERTY(QString dbusPath READ dbusPath NOTIFY dbusPathChanged)
69+ Q_PROPERTY(QString error READ getError NOTIFY errorChanged)
70
71 signals:
72 void titleChanged();
73@@ -46,6 +49,7 @@
74 void updatesStateChanged();
75 void selectedChanged();
76 void dbusPathChanged();
77+ void errorChanged();
78
79 public:
80 Application(QQuickItem *parent = 0);
81@@ -60,6 +64,7 @@
82 bool updateRequired() { return this->m_update; }
83 bool updateState() { return this->m_update_state; }
84 bool selected() { return this->m_selected; }
85+ QString getError() { return this->m_error; }
86
87 void initializeApplication(QString packagename, QString title, QString version);
88 void setRemoteVersion(QString& version);
89@@ -68,6 +73,7 @@
90 void setDbusPath(QString dbuspath) { this->m_dbuspath = dbuspath; emit this->dbusPathChanged(); }
91 void setBinaryFilesize(int size) { this->m_binary_filesize = size; emit this->binaryFilesizeChanged(); }
92 void setIconUrl(QString icon) { this->m_icon_url = icon; emit this->iconUrlChanged(); }
93+ void setError(QString error);
94
95 private:
96 QString m_packagename;
97@@ -76,12 +82,15 @@
98 QString m_remote_version;
99 QString m_dbuspath;
100 QString m_icon_url;
101+ QString m_error;
102 int m_binary_filesize;
103 bool m_update;
104 bool m_update_state;
105 bool m_selected;
106 };
107
108-QML_DECLARE_TYPE(Application)
109+}
110+
111+QML_DECLARE_TYPE(ClickPlugin::Application)
112
113 #endif // APPLICATION_H
114
115=== modified file 'src/clickmanager.cpp'
116--- src/clickmanager.cpp 2013-09-23 14:26:39 +0000
117+++ src/clickmanager.cpp 2013-09-26 16:47:31 +0000
118@@ -25,34 +25,54 @@
119 #include <QJsonValue>
120 #include <QDebug>
121
122+namespace ClickPlugin {
123+
124 ClickManager::ClickManager(QQuickItem *parent):
125 QQuickItem(parent)
126 , m_process(this)
127 {
128- this->m_updatesAvailable = false;
129- this->connect(&(this->m_process), SIGNAL(finished(int)),
130+ QObject::connect(&m_service, SIGNAL(credentialsFound(const Token&)),
131+ this, SLOT(handleCredentialsFound(Token)));
132+ QObject::connect(&m_service, SIGNAL(credentialsNotFound()),
133+ this, SLOT(handleCredentialsNotFound()));
134+ QObject::connect(&(this->m_process), SIGNAL(finished(int)),
135 this, SLOT(processOutput()));
136- this->connect(&(this->network), SIGNAL(updatesFound()),
137+ QObject::connect(&(this->m_network), SIGNAL(updatesFound()),
138 this, SLOT(processUpdates()));
139- this->connect(&(this->network), SIGNAL(updatesNotFound()),
140+ QObject::connect(&(this->m_network), SIGNAL(updatesNotFound()),
141 this, SIGNAL(updatesNotFound()));
142- this->connect(&(this->network), SIGNAL(downloadUrlFound(QString,QString)),
143+ QObject::connect(&(this->m_network), SIGNAL(downloadUrlFound(QString,QString)),
144 this, SLOT(downloadUrlObtained(QString,QString)));
145- this->connect(&(this->downloader), SIGNAL(downloadCreated(QString,QString)),
146+ QObject::connect(&(this->downloader), SIGNAL(downloadCreated(QString,QString)),
147 this, SLOT(downloadCreated(QString,QString)));
148+ QObject::connect(&(this->downloader), SIGNAL(downloadNotCreated(QString,QString)),
149+ this, SLOT(downloadNotCreated(QString,QString)));
150 }
151
152 ClickManager::~ClickManager()
153 {
154 }
155
156-void ClickManager::checkUpdates()
157+void ClickManager::handleCredentialsFound(Token token)
158 {
159+ qDebug() << "Credentials found.";
160+ this->m_token = token;
161 QStringList args("list");
162 args << "--manifest";
163 this->m_process.start("click", args);
164 }
165
166+void ClickManager::handleCredentialsNotFound()
167+{
168+ qDebug() << "No credentials were found.";
169+ emit this->credentialsNotFound();
170+}
171+
172+void ClickManager::checkUpdates()
173+{
174+ this->m_service.getCredentials();
175+}
176+
177 void ClickManager::processOutput()
178 {
179 QString output(this->m_process.readAllStandardOutput());
180@@ -72,7 +92,7 @@
181 this->m_apps[app->getPackageName()] = app;
182 }
183
184- this->network.checkForNewVersions(this->m_apps);
185+ this->m_network.checkForNewVersions(this->m_apps);
186 }
187
188 void ClickManager::processUpdates()
189@@ -90,13 +110,20 @@
190 void ClickManager::startDownload(QString packagename)
191 {
192 qDebug() << "Download Package:" << packagename;
193- this->network.getResourceUrl(packagename);
194+ this->m_network.getResourceUrl(packagename);
195 }
196
197 void ClickManager::downloadUrlObtained(QString packagename, QString url)
198 {
199- this->downloader.startDownload(packagename, url.append("?noauth=1"));
200- qDebug() << "Download Url:" << url;
201+ if(this->m_token.isValid()) {
202+ QString authHeader = this->m_token.signUrl(url, QStringLiteral("GET"));
203+ qDebug() << "Download Url:" << url;
204+ this->m_apps[packagename]->setError("");
205+ this->downloader.startDownload(packagename, url, authHeader);
206+ } else {
207+ Application* app = this->m_apps[packagename];
208+ app->setError("Invalid User Token");
209+ }
210 }
211
212 void ClickManager::downloadCreated(QString packagename, QString dbuspath)
213@@ -105,3 +132,11 @@
214 this->m_apps[packagename]->setDbusPath(dbuspath);
215 this->m_apps[packagename]->setUpdateState(true);
216 }
217+
218+void ClickManager::downloadNotCreated(QString packagename, QString error)
219+{
220+ Application* app = this->m_apps[packagename];
221+ app->setError(error);
222+}
223+
224+}
225
226=== modified file 'src/clickmanager.h'
227--- src/clickmanager.h 2013-09-23 14:20:48 +0000
228+++ src/clickmanager.h 2013-09-26 16:47:31 +0000
229@@ -25,23 +25,29 @@
230 #include <QVariant>
231 #include <QVariantList>
232 #include "application.h"
233+#include <token.h>
234
235 #ifdef TESTS
236 #include "fakeprocess.h"
237 #include "fakenetwork.h"
238 #include "fakedownloader.h"
239 #include "testclickmanager.h"
240+#include "fakessoservice.h"
241 #else
242+#include <ssoservice.h>
243 #include <QProcess>
244 #include "network/network.h"
245 #include "download/downloader.h"
246 #endif
247
248+using namespace UbuntuOne;
249+
250+namespace ClickPlugin {
251+
252 class ClickManager : public QQuickItem
253 {
254 Q_OBJECT
255 Q_DISABLE_COPY(ClickManager)
256- Q_PROPERTY(bool updatesAvailable READ updatesAvailable NOTIFY updatesAvailableChanged)
257 Q_PROPERTY(QVariantList model READ model NOTIFY modelChanged)
258
259 #ifdef TESTS
260@@ -49,9 +55,9 @@
261 #endif
262
263 signals:
264- void updatesAvailableChanged();
265 void modelChanged();
266 void updatesNotFound();
267+ void credentialsNotFound();
268
269 public:
270 ClickManager(QQuickItem *parent = 0);
271@@ -60,7 +66,6 @@
272 Q_INVOKABLE void checkUpdates();
273 Q_INVOKABLE void startDownload(QString packagename);
274
275- bool updatesAvailable() { return this->m_updatesAvailable; }
276 QVariantList model() const { return this->m_model; }
277
278 private slots:
279@@ -68,25 +73,32 @@
280 void processUpdates();
281 void downloadUrlObtained(QString packagename, QString url);
282 void downloadCreated(QString packagename, QString dbuspath);
283+ void downloadNotCreated(QString packagename, QString error);
284+ void handleCredentialsFound(Token token);
285+ void handleCredentialsNotFound();
286
287 private:
288- bool m_updatesAvailable;
289 QHash<QString, Application*> m_apps;
290 QVariantList m_model;
291+ Token m_token;
292 #ifdef TESTS
293- FakeNetwork network;
294+ FakeSsoService m_service;
295+ FakeNetwork m_network;
296 FakeDownloader downloader;
297 FakeProcess m_process;
298 #else
299+ SSOService m_service;
300 QProcess m_process;
301- Network network;
302+ Network m_network;
303 Downloader downloader;
304 #endif
305
306 void checkForUpdates();
307 };
308
309-QML_DECLARE_TYPE(ClickManager)
310+}
311+
312+QML_DECLARE_TYPE(ClickPlugin::ClickManager)
313
314 #endif // CLICKMANAGER_H
315
316
317=== modified file 'src/clickmanager_plugin.cpp'
318--- src/clickmanager_plugin.cpp 2013-09-13 10:12:01 +0000
319+++ src/clickmanager_plugin.cpp 2013-09-26 16:47:31 +0000
320@@ -23,6 +23,8 @@
321
322 #include <qqml.h>
323
324+using namespace ClickPlugin;
325+
326 void ClickManagerPlugin::registerTypes(const char *uri)
327 {
328 // @uri com.ubuntu.click
329
330=== modified file 'src/download/downloader.cpp'
331--- src/download/downloader.cpp 2013-09-23 14:50:58 +0000
332+++ src/download/downloader.cpp 2013-09-26 16:47:31 +0000
333@@ -23,6 +23,8 @@
334 #define DOWNLOAD_COMMAND "post-download-command"
335 #define APP_ID "app_id"
336
337+namespace ClickPlugin {
338+
339 Downloader::Downloader(QObject *parent) :
340 QObject(parent)
341 {
342@@ -33,7 +35,7 @@
343 this->manager = new DownloadManager("com.canonical.applications.Downloader", "/", QDBusConnection::sessionBus(), 0);
344 }
345
346-void Downloader::startDownload(QString& packagename, QString& url)
347+void Downloader::startDownload(QString& packagename, QString& url, QString& authHeader)
348 {
349 QVariantMap vmap;
350 QStringList args;
351@@ -41,14 +43,16 @@
352 vmap[DOWNLOAD_COMMAND] = args;
353 vmap[APP_ID] = packagename;
354 StringMap map;
355+ map["Authorization"] = authHeader;
356 DownloadStruct down = DownloadStruct(url, vmap, map);
357 QDBusPendingReply<QDBusObjectPath> reply = this->manager->createDownload(down);
358 reply.waitForFinished();
359 if (reply.isError()) {
360- emit this->downloadNotCreated(packagename);
361+ emit this->downloadNotCreated(packagename, reply.error().message());
362 }else{
363 QDBusObjectPath path = reply.value();
364 emit this->downloadCreated(packagename, path.path());
365 }
366 }
367
368+}
369
370=== modified file 'src/download/downloader.h'
371--- src/download/downloader.h 2013-09-10 19:01:19 +0000
372+++ src/download/downloader.h 2013-09-26 16:47:31 +0000
373@@ -24,21 +24,25 @@
374 #include <QDBusObjectPath>
375 #include "downloadmanager.h"
376
377+namespace ClickPlugin {
378+
379 class Downloader : public QObject
380 {
381 Q_OBJECT
382 public:
383 explicit Downloader(QObject *parent = 0);
384
385- void startDownload(QString& packagename, QString& url);
386+ void startDownload(QString& packagename, QString& url, QString& authHeader);
387
388 signals:
389 void downloadCreated(QString packagename, QString dbuspath);
390- void downloadNotCreated(QString packagename);
391+ void downloadNotCreated(QString packagename, QString error);
392
393 private:
394 DownloadManager* manager;
395
396 };
397
398+}
399+
400 #endif // DOWNLOADER_H
401
402=== modified file 'src/download_tracker.cpp'
403--- src/download_tracker.cpp 2013-09-13 10:12:01 +0000
404+++ src/download_tracker.cpp 2013-09-26 16:47:31 +0000
405@@ -22,6 +22,8 @@
406 #include "download_tracker.h"
407 #include <QDebug>
408
409+namespace ClickPlugin {
410+
411 DownloadTracker::DownloadTracker(QQuickItem *parent) :
412 QQuickItem(parent)
413 {
414@@ -70,3 +72,5 @@
415 this->adaptor->start();
416 }
417 }
418+
419+}
420
421=== modified file 'src/download_tracker.h'
422--- src/download_tracker.h 2013-09-13 10:12:01 +0000
423+++ src/download_tracker.h 2013-09-26 16:47:31 +0000
424@@ -27,6 +27,8 @@
425 #include <QDBusObjectPath>
426 #include <download/downloadtrackeradaptor.h>
427
428+namespace ClickPlugin {
429+
430 class DownloadTracker : public QQuickItem
431 {
432 Q_OBJECT
433@@ -61,6 +63,8 @@
434 void startService();
435 };
436
437-QML_DECLARE_TYPE(DownloadTracker)
438+}
439+
440+QML_DECLARE_TYPE(ClickPlugin::DownloadTracker)
441
442 #endif // MYTYPE_H
443
444=== modified file 'src/network/network.cpp'
445--- src/network/network.cpp 2013-09-23 14:20:48 +0000
446+++ src/network/network.cpp 2013-09-26 16:47:31 +0000
447@@ -27,6 +27,7 @@
448 #define URL_APPS "https://myapps.developer.ubuntu.com/dev/api/click-metadata/"
449 #define URL_PACKAGE "https://search.apps.ubuntu.com/api/v1/package/"
450
451+namespace ClickPlugin {
452
453 Network::Network(QObject *parent) :
454 QObject(parent)
455@@ -127,3 +128,5 @@
456 this->_request->setUrl(QUrl(URL_PACKAGE + packagename));
457 this->_nam->get(*this->_request);
458 }
459+
460+}
461
462=== modified file 'src/network/network.h'
463--- src/network/network.h 2013-09-10 19:01:19 +0000
464+++ src/network/network.h 2013-09-26 16:47:31 +0000
465@@ -25,6 +25,8 @@
466 #include <QHash>
467 #include "application.h"
468
469+namespace ClickPlugin {
470+
471 class Network : public QObject
472 {
473 Q_OBJECT
474@@ -49,4 +51,6 @@
475 QHash<QString, Application*> _apps;
476 };
477
478+}
479+
480 #endif // NETWORK_H
481
482=== modified file 'src/src.pro'
483--- src/src.pro 2013-09-13 15:34:29 +0000
484+++ src/src.pro 2013-09-26 16:47:31 +0000
485@@ -1,6 +1,6 @@
486 TEMPLATE = lib
487 TARGET = ClickManager
488-QT += qml quick core dbus
489+QT += qml quick core dbus xml network
490 CONFIG += qt plugin
491
492 TARGET = $$qtLibraryTarget($$TARGET)
493@@ -52,4 +52,5 @@
494 INSTALLS += target qmldir
495 }
496
497-LIBS += -lapt-pkg
498+QMAKE_CXXFLAGS += -I /usr/include/ubuntuoneauth-2.0 -I /usr/include/signon-qt5 -I /usr/include/accounts-qt5
499+LIBS += -lapt-pkg -lubuntuoneauth-2.0 -lsignon-qt5 -laccounts-qt5
500
501=== modified file 'tests/fakedownloader.cpp'
502--- tests/fakedownloader.cpp 2013-09-13 11:00:52 +0000
503+++ tests/fakedownloader.cpp 2013-09-26 16:47:31 +0000
504@@ -17,13 +17,22 @@
505 */
506
507 #include "fakedownloader.h"
508+#include <QDebug>
509+
510+namespace ClickPlugin {
511
512 FakeDownloader::FakeDownloader(QObject *parent) :
513 QObject(parent)
514 {
515 }
516
517-void FakeDownloader::startDownload(QString& packagename, QString& url)
518+void FakeDownloader::startDownload(QString& packagename, QString& url, QString authHeader)
519 {
520- emit this->downloadCreated(packagename, "/com/canonical/download/path");
521+ if(authHeader.isEmpty()) {
522+ emit this->downloadNotCreated(packagename, QString("DOWNLOAD ERROR"));
523+ } else {
524+ emit this->downloadCreated(packagename, "/com/canonical/download/path");
525+ }
526+}
527+
528 }
529
530=== modified file 'tests/fakedownloader.h'
531--- tests/fakedownloader.h 2013-09-13 11:00:52 +0000
532+++ tests/fakedownloader.h 2013-09-26 16:47:31 +0000
533@@ -21,18 +21,22 @@
534
535 #include <QObject>
536
537+namespace ClickPlugin {
538+
539 class FakeDownloader : public QObject
540 {
541 Q_OBJECT
542 public:
543 explicit FakeDownloader(QObject *parent = 0);
544
545- void startDownload(QString& packagename, QString& url);
546+ void startDownload(QString& packagename, QString& url, QString authHeader);
547
548 signals:
549 void downloadCreated(QString packagename, QString dbuspath);
550- void downloadNotCreated(QString packagename);
551+ void downloadNotCreated(QString packagename, QString error);
552
553 };
554
555+}
556+
557 #endif // FAKEDOWNLOADER_H
558
559=== modified file 'tests/fakenetwork.cpp'
560--- tests/fakenetwork.cpp 2013-09-13 11:00:52 +0000
561+++ tests/fakenetwork.cpp 2013-09-26 16:47:31 +0000
562@@ -18,6 +18,8 @@
563
564 #include "fakenetwork.h"
565
566+namespace ClickPlugin {
567+
568 FakeNetwork::FakeNetwork(QObject *parent) :
569 QObject(parent)
570 {
571@@ -37,3 +39,5 @@
572 {
573 emit this->downloadUrlFound(packagename, "http://canonical.com");
574 }
575+
576+}
577
578=== modified file 'tests/fakenetwork.h'
579--- tests/fakenetwork.h 2013-09-13 11:00:52 +0000
580+++ tests/fakenetwork.h 2013-09-26 16:47:31 +0000
581@@ -24,6 +24,8 @@
582 #include <QString>
583 #include "application.h"
584
585+namespace ClickPlugin {
586+
587 class FakeNetwork : public QObject
588 {
589 Q_OBJECT
590@@ -41,4 +43,6 @@
591
592 };
593
594+}
595+
596 #endif // FAKENETWORK_H
597
598=== modified file 'tests/fakeprocess.cpp'
599--- tests/fakeprocess.cpp 2013-09-23 15:32:01 +0000
600+++ tests/fakeprocess.cpp 2013-09-26 16:47:31 +0000
601@@ -21,6 +21,8 @@
602 #include <QTextStream>
603 #include <QDir>
604
605+namespace ClickPlugin {
606+
607 FakeProcess::FakeProcess(QObject *parent) :
608 QObject(parent)
609 {
610@@ -55,3 +57,5 @@
611 {
612
613 }
614+
615+}
616
617=== modified file 'tests/fakeprocess.h'
618--- tests/fakeprocess.h 2013-09-23 15:32:01 +0000
619+++ tests/fakeprocess.h 2013-09-26 16:47:31 +0000
620@@ -23,6 +23,8 @@
621 #include <QString>
622 #include <QStringList>
623
624+namespace ClickPlugin {
625+
626 class FakeProcess : public QObject
627 {
628 Q_OBJECT
629@@ -41,4 +43,6 @@
630
631 };
632
633+}
634+
635 #endif // FAKEPROCESS_H
636
637=== added file 'tests/fakessoservice.cpp'
638--- tests/fakessoservice.cpp 1970-01-01 00:00:00 +0000
639+++ tests/fakessoservice.cpp 2013-09-26 16:47:31 +0000
640@@ -0,0 +1,16 @@
641+#include "fakessoservice.h"
642+
643+namespace ClickPlugin {
644+
645+FakeSsoService::FakeSsoService(QObject *parent) :
646+ QObject(parent)
647+{
648+}
649+
650+void FakeSsoService::getCredentials()
651+{
652+ Token token("token_key", "token_secret", "consumer_key", "consumer_secret");
653+ emit this->credentialsFound(token);
654+}
655+
656+}
657
658=== added file 'tests/fakessoservice.h'
659--- tests/fakessoservice.h 1970-01-01 00:00:00 +0000
660+++ tests/fakessoservice.h 2013-09-26 16:47:31 +0000
661@@ -0,0 +1,27 @@
662+#ifndef FAKESSOSERVICE_H
663+#define FAKESSOSERVICE_H
664+
665+#include <QObject>
666+#include <token.h>
667+
668+using namespace UbuntuOne;
669+
670+namespace ClickPlugin {
671+
672+class FakeSsoService : public QObject
673+{
674+ Q_OBJECT
675+public:
676+ explicit FakeSsoService(QObject *parent = 0);
677+
678+ void getCredentials();
679+
680+signals:
681+ void credentialsFound(const Token&);
682+ void credentialsNotFound();
683+
684+};
685+
686+}
687+
688+#endif // FAKESSOSERVICE_H
689
690=== modified file 'tests/test_main.cpp'
691--- tests/test_main.cpp 2013-09-13 10:12:01 +0000
692+++ tests/test_main.cpp 2013-09-26 16:47:31 +0000
693@@ -21,6 +21,8 @@
694 #include "testapplication.h"
695 #include "testclickmanager.h"
696
697+using namespace ClickPlugin;
698+
699 int main()
700 {
701
702
703=== modified file 'tests/testapplication.cpp'
704--- tests/testapplication.cpp 2013-09-13 11:00:52 +0000
705+++ tests/testapplication.cpp 2013-09-26 16:47:31 +0000
706@@ -21,6 +21,8 @@
707
708 #include "application.h"
709
710+namespace ClickPlugin {
711+
712 void TestApplication::testCompareVersion()
713 {
714 Application app;
715@@ -30,3 +32,5 @@
716 app.setRemoteVersion(version);
717 QCOMPARE(app.updateRequired(), true);
718 }
719+
720+}
721
722=== modified file 'tests/testapplication.h'
723--- tests/testapplication.h 2013-09-13 11:00:52 +0000
724+++ tests/testapplication.h 2013-09-26 16:47:31 +0000
725@@ -23,6 +23,8 @@
726
727 #include <QtTest/QtTest>
728
729+namespace ClickPlugin {
730+
731 class TestApplication : public QObject
732 {
733 Q_OBJECT
734@@ -32,4 +34,6 @@
735
736 };
737
738+}
739+
740 #endif // TESTAPPLICATION_H
741
742=== modified file 'tests/testclickmanager.cpp'
743--- tests/testclickmanager.cpp 2013-09-13 11:00:52 +0000
744+++ tests/testclickmanager.cpp 2013-09-26 16:47:31 +0000
745@@ -21,6 +21,8 @@
746 #include "clickmanager.h"
747 #include "application.h"
748
749+namespace ClickPlugin {
750+
751 void TestClickManager::cleanup()
752 {
753 this->m_signal_counter = 0;
754@@ -57,3 +59,24 @@
755 QCOMPARE(app->updateState(), true);
756 QCOMPARE(app->dbusPath(), QString("/com/canonical/download/path"));
757 }
758+
759+void TestClickManager::testTokenObtained()
760+{
761+ ClickManager manager;
762+ manager.checkUpdates();
763+ QCOMPARE(manager.m_token.isValid(), true);
764+}
765+
766+void TestClickManager::testDownloadNotCreated()
767+{
768+ ClickManager manager;
769+ manager.checkUpdates();
770+ manager.m_token = Token();
771+ Application* app = manager.m_model[0].value<Application*>();
772+ manager.startDownload(app->getPackageName());
773+ QCOMPARE(app->updateState(), false);
774+ QCOMPARE(app->dbusPath(), QString(""));
775+ QCOMPARE(app->getError(), QString("Invalid User Token"));
776+}
777+
778+}
779
780=== modified file 'tests/testclickmanager.h'
781--- tests/testclickmanager.h 2013-09-13 11:00:52 +0000
782+++ tests/testclickmanager.h 2013-09-26 16:47:31 +0000
783@@ -23,6 +23,8 @@
784
785 #include <QtTest/QtTest>
786
787+namespace ClickPlugin {
788+
789 class TestClickManager : public QObject
790 {
791 Q_OBJECT
792@@ -35,9 +37,13 @@
793
794 void testCheckUpdates();
795 void testStartDownload();
796+ void testTokenObtained();
797+ void testDownloadNotCreated();
798
799 private:
800 int m_signal_counter;
801 };
802
803+}
804+
805 #endif // TESTCLICKMANAGER_H
806
807=== modified file 'tests/tests.pro'
808--- tests/tests.pro 2013-09-13 15:34:29 +0000
809+++ tests/tests.pro 2013-09-26 16:47:31 +0000
810@@ -1,4 +1,4 @@
811-QT += core qml quick network testlib dbus
812+QT += core qml quick network testlib dbus xml
813
814 QT -= gui
815
816@@ -25,7 +25,8 @@
817 fakeprocess.cpp \
818 ../src/download/download_struct.cpp \
819 ../src/download/group_download_struct.cpp \
820- ../src/download/hash_algorithm.cpp
821+ ../src/download/hash_algorithm.cpp \
822+ fakessoservice.cpp
823
824 HEADERS += \
825 ../src/clickmanager_plugin.h \
826@@ -44,9 +45,11 @@
827 fakeprocess.h \
828 ../src/download/download_struct.h \
829 ../src/download/group_download_struct.h \
830- ../src/download/hash_algorithm.h
831+ ../src/download/hash_algorithm.h \
832+ fakessoservice.h
833
834-LIBS += -lapt-pkg
835+QMAKE_CXXFLAGS += -I /usr/include/ubuntuoneauth-2.0 -I /usr/include/signon-qt5 -I /usr/include/accounts-qt5
836+LIBS += -lapt-pkg -lubuntuoneauth-2.0 -lsignon-qt5 -laccounts-qt5
837 INCLUDEPATH += ../src/
838
839 DEFINES += SRCDIR=\\\"$$PWD/\\\"

Subscribers

People subscribed via source and target branches