void TestQPrefCloudStorage::test_oldPreferences() { auto cloud = qPrefCloudStorage::instance(); cloud->set_cloud_base_url("test_one"); TEST(cloud->cloud_base_url(), QStringLiteral("test_one")); cloud->set_cloud_base_url("test_two"); TEST(cloud->cloud_base_url(), QStringLiteral("test_two")); cloud->set_cloud_storage_email("*****@*****.**"); TEST(cloud->cloud_storage_email(), QStringLiteral("*****@*****.**")); cloud->set_cloud_storage_email("*****@*****.**"); TEST(cloud->cloud_storage_email(), QStringLiteral("*****@*****.**")); cloud->set_cloud_storage_password("ABCDE"); TEST(cloud->cloud_storage_password(), QStringLiteral("ABCDE")); cloud->set_cloud_storage_password("ABCABC"); TEST(cloud->cloud_storage_password(), QStringLiteral("ABCABC")); cloud->set_cloud_auto_sync(true); TEST(cloud->cloud_auto_sync(), true); cloud->set_cloud_auto_sync(false); TEST(cloud->cloud_auto_sync(), false); cloud->set_save_password_local(true); TEST(cloud->save_password_local(), true); cloud->set_save_password_local(false); TEST(cloud->save_password_local(), false); cloud->set_cloud_verification_status(0); TEST(cloud->cloud_verification_status(), 0); cloud->set_cloud_verification_status(1); TEST(cloud->cloud_verification_status(), 1); }
void TestQPrefCloudStorage::test_set_struct() { // Test set func -> struct pref auto tst = qPrefCloudStorage::instance(); tst->set_cloud_auto_sync(false); tst->set_cloud_base_url("t2 base"); tst->set_cloud_storage_email("t2 email"); tst->set_cloud_storage_email_encoded("t2 email2"); tst->set_cloud_storage_password("t2 pass2"); tst->set_cloud_storage_pin("t2 pin"); tst->set_cloud_timeout(123); tst->set_cloud_verification_status(qPrefCloudStorage::CS_VERIFIED); tst->set_save_password_local(false); QCOMPARE(prefs.cloud_auto_sync, false); QCOMPARE(QString(prefs.cloud_base_url), QString("t2 base")); QCOMPARE(QString(prefs.cloud_storage_email), QString("t2 email")); QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t2 email2")); QCOMPARE(QString(prefs.cloud_storage_password), QString("t2 pass2")); QCOMPARE(QString(prefs.cloud_storage_pin), QString("t2 pin")); QCOMPARE((int)prefs.cloud_timeout, 123); QCOMPARE((int)prefs.cloud_verification_status, (int)qPrefCloudStorage::CS_VERIFIED); QCOMPARE(prefs.save_password_local, false); // remark is set with set_base_url QCOMPARE(QString(prefs.cloud_git_url), QString("t2 base/git")); }
void TestQPrefCloudStorage::test_set_load_struct() { // test set func -> load -> struct pref auto tst = qPrefCloudStorage::instance(); tst->set_cloud_base_url("t3 base"); tst->set_cloud_storage_email("t3 email"); tst->set_cloud_storage_email_encoded("t3 email2"); tst->set_save_password_local(true); tst->set_cloud_auto_sync(true); tst->set_cloud_storage_password("t3 pass2"); tst->set_cloud_storage_pin("t3 pin"); tst->set_cloud_timeout(321); tst->set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); prefs.cloud_auto_sync = false; prefs.cloud_base_url = copy_qstring("error1"); prefs.cloud_git_url = copy_qstring("error1"); prefs.cloud_storage_email = copy_qstring("error1"); prefs.cloud_storage_email_encoded = copy_qstring("error1"); prefs.cloud_storage_password = copy_qstring("error1"); prefs.cloud_storage_pin = copy_qstring("error1"); prefs.cloud_timeout = 324; prefs.cloud_verification_status = qPrefCloudStorage::CS_VERIFIED; prefs.save_password_local = false; tst->load(); QCOMPARE(prefs.cloud_auto_sync, true); QCOMPARE(QString(prefs.cloud_base_url), QString("t3 base")); QCOMPARE(QString(prefs.cloud_storage_email), QString("t3 email")); QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t3 email2")); QCOMPARE(QString(prefs.cloud_storage_password), QString("t3 pass2")); QCOMPARE(QString(prefs.cloud_storage_pin), QString("t3 pin")); QCOMPARE((int)prefs.cloud_timeout, 321); QCOMPARE((int)prefs.cloud_verification_status, (int)qPrefCloudStorage::CS_NOCLOUD); QCOMPARE(prefs.save_password_local, true); // remark is set with set_base_url QCOMPARE(QString(prefs.cloud_git_url), QString("t3 base/git")); }
void PreferencesNetwork::syncSettings() { auto cloud = qPrefCloudStorage::instance(); auto proxy = qPrefProxy::instance(); proxy->set_proxy_type(ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt()); proxy->set_proxy_host(ui->proxyHost->text()); proxy->set_proxy_port(ui->proxyPort->value()); proxy->set_proxy_auth(ui->proxyAuthRequired->isChecked()); proxy->set_proxy_user(ui->proxyUsername->text()); proxy->set_proxy_pass(ui->proxyPassword->text()); QString email = ui->cloud_storage_email->text(); QString password = ui->cloud_storage_password->text(); QString newpassword = ui->cloud_storage_new_passwd->text(); //TODO: Change this to the Cloud Storage Stuff, not preferences. if (prefs.cloud_verification_status == qPref::CS_VERIFIED && !newpassword.isEmpty()) { // deal with password change if (!email.isEmpty() && !password.isEmpty()) { // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { report_error(qPrintable(tr("Change ignored. Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); return; } if (!reg.match(email).hasMatch() || (!newpassword.isEmpty() && !reg.match(newpassword).hasMatch())) { report_error(qPrintable(tr("Change ignored. Cloud storage email and new password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); ui->cloud_storage_new_passwd->setText(""); return; } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState); connect(cloudAuth, &CloudStorageAuthenticate::passwordChangeSuccessful, this, &PreferencesNetwork::passwordUpdateSuccessful); cloudAuth->backend(email, password, "", newpassword); ui->cloud_storage_new_passwd->setText(""); } } else if (prefs.cloud_verification_status == qPref::CS_UNKNOWN || prefs.cloud_verification_status == qPref::CS_INCORRECT_USER_PASSWD || email != prefs.cloud_storage_email || password != prefs.cloud_storage_password) { // different credentials - reset verification status int oldVerificationStatus = cloud->cloud_verification_status(); cloud->set_cloud_verification_status(qPref::CS_UNKNOWN); if (!email.isEmpty() && !password.isEmpty()) { // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); cloud->set_cloud_verification_status(oldVerificationStatus); return; } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, &CloudStorageAuthenticate::finishedAuthenticate, this, &PreferencesNetwork::updateCloudAuthenticationState); cloudAuth->backend(email, password); } } else if (prefs.cloud_verification_status == qPref::CS_NEED_TO_VERIFY) { QString pin = ui->cloud_storage_pin->text(); if (!pin.isEmpty()) { // connect to backend server to check / create credentials QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); return; } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(updateCloudAuthenticationState())); cloudAuth->backend(email, password, pin); } } cloud->set_cloud_storage_email(email); cloud->set_save_password_local(ui->save_password_local->isChecked()); cloud->set_cloud_storage_password(password); cloud->set_cloud_verification_status(prefs.cloud_verification_status); cloud->set_cloud_base_url(prefs.cloud_base_url); }