@@ -17,6 +17,8 @@ private Q_SLOTS:
1717 void testAddAccount ();
1818 void testLiveSync ();
1919 void testPassiveSync ();
20+ void testRemoveAndResetAccount ();
21+ void testAddAccountTrusted ();
2022
2123Q_SIGNALS:
2224 void unlock ();
@@ -31,6 +33,8 @@ private Q_SLOTS:
3133 AccountManager *acc2;
3234 SyncManager *sync2;
3335 DataTypeStore<TestData> *store2;
36+
37+ QUuid dev2Id;
3438};
3539
3640void IntegrationTest::initTestCase ()
@@ -192,6 +196,7 @@ void IntegrationTest::testAddAccount()
192196
193197 // export from acc1
194198 acc1->exportAccount (false , [this ](QJsonObject exp) {
199+ QVERIFY (!AccountManager::isTrustedImport (exp));
195200 acc2->importAccount (exp, [](bool ok, QString e) {
196201 QVERIFY2 (ok, qUtf8Printable (e));
197202 }, true );
@@ -210,8 +215,8 @@ void IntegrationTest::testAddAccount()
210215 QVERIFY (!request.handled ());
211216 QCOMPARE (request.device ().name (), acc2->deviceName ());
212217 QCOMPARE (request.device ().fingerprint (), acc2->deviceFingerprint ());
213- auto pId = request.device ().deviceId ();
214- QVERIFY (!pId .isNull ());
218+ dev2Id = request.device ().deviceId ();
219+ QVERIFY (!dev2Id .isNull ());
215220 request.accept ();
216221 QVERIFY (request.handled ());
217222
@@ -224,7 +229,7 @@ void IntegrationTest::testAddAccount()
224229 if (grantSpy.isEmpty ())
225230 QVERIFY (grantSpy.wait ());
226231 QCOMPARE (grantSpy.size (), 1 );
227- QCOMPARE (grantSpy.takeFirst ()[0 ].toUuid (), pId );
232+ QCOMPARE (grantSpy.takeFirst ()[0 ].toUuid (), dev2Id );
228233
229234 // wait for sync
230235 sync1->runOnSynchronized ([this ](SyncManager::SyncState s) {
@@ -249,7 +254,7 @@ void IntegrationTest::testAddAccount()
249254 QCOMPARE (devices1Spy.size (), 1 );
250255 auto devices = devices1Spy.takeFirst ()[0 ].value <QList<DeviceInfo>>();
251256 QCOMPARE (devices.size (), 1 );
252- QCOMPARE (devices[0 ].deviceId (), pId );
257+ QCOMPARE (devices[0 ].deviceId (), dev2Id );
253258 QCOMPARE (devices[0 ].name (), acc2->deviceName ());
254259 QCOMPARE (devices[0 ].fingerprint (), acc2->deviceFingerprint ());
255260
@@ -289,8 +294,9 @@ void IntegrationTest::testLiveSync()
289294 QVERIFY (sync1Spy.size () > 0 );
290295 QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Uploading);
291296 QVERIFY (unlockSpy.wait ());
292- QCOMPARE (sync1Spy.size (), 1 );
293- QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Synchronized);
297+ QVERIFY (sync1Spy.size () > 0 );
298+ QCOMPARE (sync1Spy.last ()[0 ].toInt (), SyncManager::Synchronized);
299+ sync1Spy.clear ();
294300
295301 // sync data to 2
296302 sync2->runOnDownloaded ([this ](SyncManager::SyncState s) {
@@ -304,6 +310,7 @@ void IntegrationTest::testLiveSync()
304310 QVERIFY (unlockSpy.wait ());
305311 QVERIFY (sync2Spy.size () > 0 );
306312 QCOMPARE (sync2Spy.last ()[0 ].toInt (), SyncManager::Synchronized);
313+ sync2Spy.clear ();
307314
308315 // verify data changes
309316 QCOMPARE (dataSpy.size (), 20 );
@@ -442,6 +449,7 @@ void IntegrationTest::testPassiveSync()
442449 QVERIFY (unlockSpy.wait ());
443450 QVERIFY (sync2Spy.size () > 0 );
444451 QCOMPARE (sync2Spy.last ()[0 ].toInt (), SyncManager::Synchronized);
452+ sync2Spy.clear ();
445453
446454 // verify data changes on 1
447455 QCOMPARE (data1Spy.size (), 20 );
@@ -464,6 +472,147 @@ void IntegrationTest::testPassiveSync()
464472 }
465473}
466474
475+ void IntegrationTest::testRemoveAndResetAccount ()
476+ {
477+ try {
478+ QSignalSpy error1Spy (acc1, &AccountManager::lastErrorChanged);
479+ QSignalSpy error2Spy (acc2, &AccountManager::lastErrorChanged);
480+ QSignalSpy sync1Spy (sync1, &SyncManager::syncStateChanged);
481+ QSignalSpy sync2Spy (sync2, &SyncManager::syncStateChanged);
482+ QSignalSpy devices1Spy (acc1, &AccountManager::accountDevices);
483+ QSignalSpy data1Spy (store1, &DataTypeStoreBase::dataResetted);
484+
485+ // remove 2
486+ acc1->removeDevice (dev2Id);
487+ QVERIFY (sync2Spy.wait ());
488+ QCOMPARE (sync2Spy.size (), 1 );
489+ QCOMPARE (sync2Spy.takeFirst ()[0 ].toInt (), SyncManager::Disconnected);
490+
491+ // verify devices not there
492+ acc1->listDevices ();
493+ QVERIFY (devices1Spy.wait ());
494+ QCOMPARE (devices1Spy.size (), 1 );
495+ auto devices = devices1Spy.takeFirst ()[0 ].value <QList<DeviceInfo>>();
496+ QVERIFY (devices.isEmpty ());
497+
498+ // verify connect fails
499+ sync2->reconnect ();
500+ // wait for init
501+ if (sync2Spy.isEmpty ())
502+ QVERIFY (sync2Spy.wait ());
503+ QVERIFY (sync2Spy.size () > 0 );
504+ QCOMPARE (sync2Spy.takeFirst ()[0 ].toInt (), SyncManager::Initializing);
505+ // wait for error
506+ if (sync2Spy.isEmpty ())
507+ QVERIFY (sync2Spy.wait ());
508+ QVERIFY (sync2Spy.size () > 0 );
509+ QCOMPARE (sync2Spy.takeFirst ()[0 ].toInt (), SyncManager::Error);
510+ // on error
511+ sync2->runOnSynchronized ([this ](SyncManager::SyncState s) {
512+ emit unlock ();
513+ QCOMPARE (s, SyncManager::Error);
514+ }, false );
515+ if (error2Spy.isEmpty ())
516+ QVERIFY (error2Spy.wait ());
517+ QCOMPARE (error2Spy.size (), 1 );
518+ error2Spy.clear ();
519+
520+ // reset 1 to clear it
521+ acc1->resetAccount (false );
522+ // disconnect
523+ if (sync1Spy.isEmpty ())
524+ QVERIFY (sync1Spy.wait ());
525+ QVERIFY (sync1Spy.size () > 0 );
526+ QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Disconnected);
527+ // reconnect
528+ if (sync1Spy.isEmpty ())
529+ QVERIFY (sync1Spy.wait ());
530+ QVERIFY (sync1Spy.size () > 0 );
531+ QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Initializing);
532+ // uploading
533+ if (sync1Spy.isEmpty ())
534+ QVERIFY (sync1Spy.wait ());
535+ QVERIFY (sync1Spy.size () > 0 );
536+ QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Uploading);
537+ // synced
538+ if (sync1Spy.isEmpty ())
539+ QVERIFY (sync1Spy.wait ());
540+ QCOMPARE (sync1Spy.size (), 1 );
541+ QCOMPARE (sync1Spy.takeFirst ()[0 ].toInt (), SyncManager::Synchronized);
542+
543+ if (data1Spy.isEmpty ())
544+ QVERIFY (data1Spy.wait ());
545+
546+ QVERIFY (error1Spy.isEmpty ());
547+ QVERIFY (error2Spy.isEmpty ());
548+ } catch (std::exception &e) {
549+ QFAIL (e.what ());
550+ }
551+ }
552+
553+ void IntegrationTest::testAddAccountTrusted ()
554+ {
555+ try {
556+ QSignalSpy error1Spy (acc1, &AccountManager::lastErrorChanged);
557+ QSignalSpy error2Spy (acc2, &AccountManager::lastErrorChanged);
558+ QSignalSpy fprintSpy (acc2, &AccountManager::deviceFingerprintChanged);
559+ QSignalSpy requestSpy (acc1, &AccountManager::loginRequested);
560+ QSignalSpy acceptSpy (acc2, &AccountManager::importAccepted);
561+ QSignalSpy grantSpy (acc1, &AccountManager::accountAccessGranted);
562+ QSignalSpy unlockSpy (this , &IntegrationTest::unlock);
563+
564+ // export from acc1
565+ auto password = QStringLiteral (" password" );
566+ acc1->exportAccountTrusted (false , password, [&](QJsonObject exp) {
567+ QVERIFY (AccountManager::isTrustedImport (exp));
568+ acc2->importAccountTrusted (exp, password, [&](bool ok, QString e) {
569+ QVERIFY2 (ok, qUtf8Printable (e));
570+ if (error2Spy.wait ())
571+ error2Spy.clear ();
572+ }, false );
573+ }, [](QString e) {
574+ QFAIL (qUtf8Printable (e));
575+ });
576+
577+ // wait for acc2 fingerprint update
578+ QVERIFY (fprintSpy.wait ());
579+ QCOMPARE (fprintSpy.size (), 1 );
580+
581+ // wait for login request to not come...
582+ QVERIFY (!requestSpy.wait ());
583+
584+ // wait for accept
585+ if (acceptSpy.isEmpty ())
586+ QVERIFY (acceptSpy.wait ());
587+ QCOMPARE (acceptSpy.size (), 1 );
588+
589+ // wait for grant
590+ if (grantSpy.isEmpty ())
591+ QVERIFY (grantSpy.wait ());
592+ QCOMPARE (grantSpy.size (), 1 );
593+
594+ // wait for sync
595+ sync1->runOnSynchronized ([this ](SyncManager::SyncState s) {
596+ emit unlock ();
597+ QCOMPARE (s, SyncManager::Synchronized);
598+ }, true );
599+ unlockSpy.wait ();
600+ sync2->runOnSynchronized ([this ](SyncManager::SyncState s) {
601+ emit unlock ();
602+ QCOMPARE (s, SyncManager::Synchronized);
603+ });
604+ unlockSpy.wait ();
605+
606+ QCOMPARE (store1->count (), 0 );
607+ QCOMPARE (store2->count (), 0 );
608+
609+ QVERIFY (error1Spy.isEmpty ());
610+ QVERIFY (error2Spy.isEmpty ());
611+ } catch (std::exception &e) {
612+ QFAIL (e.what ());
613+ }
614+ }
615+
467616QTEST_MAIN (IntegrationTest)
468617
469618#include " tst_integration.moc"
0 commit comments