예제 #1
0
void TestQPrefProxy::test_oldPreferences()
{
	auto proxy = qPrefProxy::instance();

	proxy->set_proxy_type(2);
	proxy->set_proxy_port(80);
	proxy->set_proxy_auth(true);
	proxy->set_proxy_host("localhost");
	proxy->set_proxy_user("unknown");
	proxy->set_proxy_pass("secret");

	TEST(proxy->proxy_type(), 2);
	TEST(proxy->proxy_port(), 80);
	TEST(proxy->proxy_auth(), true);
	TEST(proxy->proxy_host(), QStringLiteral("localhost"));
	TEST(proxy->proxy_user(), QStringLiteral("unknown"));
	TEST(proxy->proxy_pass(), QStringLiteral("secret"));

	proxy->set_proxy_type(3);
	proxy->set_proxy_port(8080);
	proxy->set_proxy_auth(false);
	proxy->set_proxy_host("127.0.0.1");
	proxy->set_proxy_user("unknown_1");
	proxy->set_proxy_pass("secret_1");

	TEST(proxy->proxy_type(), 3);
	TEST(proxy->proxy_port(), 8080);
	TEST(proxy->proxy_auth(), false);
	TEST(proxy->proxy_host(), QStringLiteral("127.0.0.1"));
	TEST(proxy->proxy_user(), QStringLiteral("unknown_1"));
	TEST(proxy->proxy_pass(), QStringLiteral("secret_1"));
}
예제 #2
0
void TestQPrefProxy::test_set_load_struct()
{
	// test set func -> load -> struct pref

	auto tst = qPrefProxy::instance();

	tst->set_proxy_auth(true);
	tst->set_proxy_host("t3 host");
	tst->set_proxy_pass("t3 pass");
	tst->set_proxy_port(532);
	tst->set_proxy_type(1);
	tst->set_proxy_user("t3 user");

	tst->sync();
	prefs.proxy_auth = false;
	prefs.proxy_host = copy_qstring("error1");
	prefs.proxy_pass = copy_qstring("error1");
	prefs.proxy_port = 128;
	prefs.proxy_type = 0;
	prefs.proxy_user = copy_qstring("error1");

	tst->load();
	QCOMPARE(prefs.proxy_auth, true);
	QCOMPARE(QString(prefs.proxy_host), QString("t3 host"));
	QCOMPARE(QString(prefs.proxy_pass), QString("t3 pass"));
	QCOMPARE(prefs.proxy_port, 532);
	QCOMPARE(prefs.proxy_type, 1);
	QCOMPARE(QString(prefs.proxy_user), QString("t3 user"));
}
예제 #3
0
void proxy_init(void)
{
    GError *gconf_error = NULL;
    gboolean use_proxy;
    gboolean use_proxy_auth;

    gl_client = gconf_client_get_default();
    gl_mutex = g_mutex_new();

    gconf_client_add_dir(gl_client, PATH_GCONF_GNOME_VFS,
			 GCONF_CLIENT_PRELOAD_ONELEVEL, &gconf_error);
    if (gconf_error) {
	DEBUG_HTTP(("GConf error during client_add_dir '%s'",
		    gconf_error->message));
	g_error_free(gconf_error);
	gconf_error = NULL;
    }

    gconf_client_notify_add(gl_client, PATH_GCONF_GNOME_VFS,
			    notify_gconf_value_changed, NULL, NULL,
			    &gconf_error);
    if (gconf_error) {
	DEBUG_HTTP(("GConf error during notify_error '%s'",
		    gconf_error->message));
	g_error_free(gconf_error);
	gconf_error = NULL;
    }

    /* Load the http proxy setting */
    use_proxy =
	gconf_client_get_bool(gl_client, KEY_GCONF_USE_HTTP_PROXY,
			      &gconf_error);

    if (gconf_error != NULL) {
	DEBUG_HTTP(("GConf error during client_get_bool '%s'",
		    gconf_error->message));
	g_error_free(gconf_error);
	gconf_error = NULL;
    } else {
	construct_gl_http_proxy(use_proxy);
    }

    use_proxy_auth =
	gconf_client_get_bool(gl_client, KEY_GCONF_HTTP_USE_AUTH,
			      &gconf_error);

    if (gconf_error != NULL) {
	DEBUG_HTTP(("GConf error during client_get_bool '%s'",
		    gconf_error->message));
	g_error_free(gconf_error);
	gconf_error = NULL;
    } else {
	set_proxy_auth(use_proxy_auth);
    }
}
예제 #4
0
void TestQPrefProxy::test_set_struct()
{
	// Test set func -> struct pref

	auto tst = qPrefProxy::instance();

	tst->set_proxy_auth(false);
	tst->set_proxy_host("t2 host");
	tst->set_proxy_pass("t2 pass");
	tst->set_proxy_port(524);
	tst->set_proxy_type(2);
	tst->set_proxy_user("t2 user");

	QCOMPARE(prefs.proxy_auth, false);
	QCOMPARE(QString(prefs.proxy_host), QString("t2 host"));
	QCOMPARE(QString(prefs.proxy_pass), QString("t2 pass"));
	QCOMPARE(prefs.proxy_port, 524);
	QCOMPARE(prefs.proxy_type, 2);
	QCOMPARE(QString(prefs.proxy_user), QString("t2 user"));
}
예제 #5
0
/**
 * sig_gconf_value_changed 
 * GGconf notify function for when HTTP proxy GConf key has changed.
 */
static void
notify_gconf_value_changed(GConfClient * client,
			   guint cnxn_id, GConfEntry * entry,
			   gpointer data)
{
    const char *key;

    key = gconf_entry_get_key(entry);

    if (strcmp(key, KEY_GCONF_USE_HTTP_PROXY) == 0
	|| strcmp(key, KEY_GCONF_HTTP_PROXY_IGNORE_HOSTS) == 0
	|| strcmp(key, KEY_GCONF_HTTP_PROXY_HOST) == 0
	|| strcmp(key, KEY_GCONF_HTTP_PROXY_PORT) == 0) {
	gboolean use_proxy_value;

	g_mutex_lock(gl_mutex);

	/* Check and see if we are using the proxy */
	use_proxy_value =
	    gconf_client_get_bool(gl_client,
				  KEY_GCONF_USE_HTTP_PROXY, NULL);
	construct_gl_http_proxy(use_proxy_value);

	g_mutex_unlock(gl_mutex);
    } else if (strcmp(key, KEY_GCONF_HTTP_AUTH_USER) == 0
	       || strcmp(key, KEY_GCONF_HTTP_AUTH_PW) == 0
	       || strcmp(key, KEY_GCONF_HTTP_USE_AUTH) == 0) {
	gboolean use_proxy_auth;

	g_mutex_lock(gl_mutex);

	use_proxy_auth =
	    gconf_client_get_bool(gl_client,
				  KEY_GCONF_HTTP_USE_AUTH, NULL);
	set_proxy_auth(use_proxy_auth);

	g_mutex_unlock(gl_mutex);
    }
}
예제 #6
0
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);
}