Update bridge related settings in Settings, and use those new settings in Onion

This commit is contained in:
Micah Lee 2021-10-26 21:06:05 -07:00
parent 54f4f2a53f
commit 2b3b6d7635
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 46 additions and 50 deletions

View file

@ -319,40 +319,39 @@ class Onion(object):
f.write(torrc_template) f.write(torrc_template)
# Bridge support # Bridge support
if self.settings.get("tor_bridges_use_obfs4"): if self.settings.get("bridges_enabled"):
with open( if self.settings.get("bridges_type") == "built-in":
self.common.get_resource_path("torrc_template-obfs4") if self.settings.get("bridges_builtin_pt") == "obfs4":
) as o: with open(
for line in o: self.common.get_resource_path("torrc_template-obfs4")
f.write(line) ) as o:
elif self.settings.get("tor_bridges_use_meek_lite_azure"): f.write(o.read())
with open( elif self.settings.get("bridges_builtin_pt") == "meek-azure":
self.common.get_resource_path("torrc_template-meek_lite_azure") with open(
) as o: self.common.get_resource_path(
for line in o: "torrc_template-meek_lite_azure"
f.write(line) )
elif self.settings.get("tor_bridges_use_snowflake"): ) as o:
with open( f.write(o.read())
self.common.get_resource_path("torrc_template-snowflake") elif self.settings.get("bridges_builtin_pt") == "snowflake":
) as o: with open(
for line in o: self.common.get_resource_path(
f.write(line) "torrc_template-snowflake"
)
) as o:
f.write(o.read())
elif self.settings.get("tor_bridges_use_moat"): elif self.settings.get("bridges_type") == "moat":
for line in self.settings.get("tor_bridges_use_moat_bridges").split( for line in self.settings.get("bridges_moat").split("\n"):
"\n" if line.strip() != "":
): f.write(f"Bridge {line}\n")
if line.strip() != "": f.write("\nUseBridges 1\n")
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
elif self.settings.get("tor_bridges_use_custom_bridges"): elif self.settings.get("bridges_type") == "custom":
for line in self.settings.get( for line in self.settings.get("bridges_custom").split("\n"):
"tor_bridges_use_custom_bridges" if line.strip() != "":
).split("\n"): f.write(f"Bridge {line}\n")
if line.strip() != "": f.write("\nUseBridges 1\n")
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
# Execute a tor subprocess # Execute a tor subprocess
start_ts = time.time() start_ts = time.time()

View file

@ -105,13 +105,11 @@ class Settings(object):
"auth_password": "", "auth_password": "",
"use_autoupdate": True, "use_autoupdate": True,
"autoupdate_timestamp": None, "autoupdate_timestamp": None,
"no_bridges": True, "bridges_enabled": False,
"tor_bridges_use_obfs4": False, "bridges_type": "built-in", # "built-in", "moat", or "custom"
"tor_bridges_use_meek_lite_azure": False, "bridges_builtin_pt": "obfs4", # "obfs4", "meek-azure", or "snowflake"
"tor_bridges_use_snowflake": False, "bridges_moat": "",
"tor_bridges_use_moat": False, "bridges_custom": "",
"tor_bridges_use_moat_bridges": "",
"tor_bridges_use_custom_bridges": "",
"persistent_tabs": [], "persistent_tabs": [],
"locale": None, # this gets defined in fill_in_defaults() "locale": None, # this gets defined in fill_in_defaults()
"theme": 0, "theme": 0,

View file

@ -29,13 +29,11 @@ class TestSettings:
"auth_password": "", "auth_password": "",
"use_autoupdate": True, "use_autoupdate": True,
"autoupdate_timestamp": None, "autoupdate_timestamp": None,
"no_bridges": True, "bridges_enabled": False,
"tor_bridges_use_obfs4": False, "bridges_type": "built-in",
"tor_bridges_use_meek_lite_azure": False, "bridges_builtin_pt": "obfs4",
"tor_bridges_use_snowflake": False, "bridges_moat": "",
"tor_bridges_use_moat": False, "bridges_custom": "",
"tor_bridges_use_moat_bridges": "",
"tor_bridges_use_custom_bridges": "",
"persistent_tabs": [], "persistent_tabs": [],
"theme": 0, "theme": 0,
} }
@ -96,10 +94,11 @@ class TestSettings:
assert settings_obj.get("use_autoupdate") is True assert settings_obj.get("use_autoupdate") is True
assert settings_obj.get("autoupdate_timestamp") is None assert settings_obj.get("autoupdate_timestamp") is None
assert settings_obj.get("autoupdate_timestamp") is None assert settings_obj.get("autoupdate_timestamp") is None
assert settings_obj.get("no_bridges") is True assert settings_obj.get("bridges_enabled") is False
assert settings_obj.get("tor_bridges_use_obfs4") is False assert settings_obj.get("bridges_type") == "built-in"
assert settings_obj.get("tor_bridges_use_meek_lite_azure") is False assert settings_obj.get("bridges_builtin_pt") == "obfs4"
assert settings_obj.get("tor_bridges_use_custom_bridges") == "" assert settings_obj.get("bridges_moat") == ""
assert settings_obj.get("bridges_custom") == ""
def test_set_version(self, settings_obj): def test_set_version(self, settings_obj):
settings_obj.set("version", "CUSTOM_VERSION") settings_obj.set("version", "CUSTOM_VERSION")