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)
# Bridge support
if self.settings.get("tor_bridges_use_obfs4"):
with open(
self.common.get_resource_path("torrc_template-obfs4")
) as o:
for line in o:
f.write(line)
elif self.settings.get("tor_bridges_use_meek_lite_azure"):
with open(
self.common.get_resource_path("torrc_template-meek_lite_azure")
) as o:
for line in o:
f.write(line)
elif self.settings.get("tor_bridges_use_snowflake"):
with open(
self.common.get_resource_path("torrc_template-snowflake")
) as o:
for line in o:
f.write(line)
if self.settings.get("bridges_enabled"):
if self.settings.get("bridges_type") == "built-in":
if self.settings.get("bridges_builtin_pt") == "obfs4":
with open(
self.common.get_resource_path("torrc_template-obfs4")
) as o:
f.write(o.read())
elif self.settings.get("bridges_builtin_pt") == "meek-azure":
with open(
self.common.get_resource_path(
"torrc_template-meek_lite_azure"
)
) as o:
f.write(o.read())
elif self.settings.get("bridges_builtin_pt") == "snowflake":
with open(
self.common.get_resource_path(
"torrc_template-snowflake"
)
) as o:
f.write(o.read())
elif self.settings.get("tor_bridges_use_moat"):
for line in self.settings.get("tor_bridges_use_moat_bridges").split(
"\n"
):
if line.strip() != "":
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
elif self.settings.get("bridges_type") == "moat":
for line in self.settings.get("bridges_moat").split("\n"):
if line.strip() != "":
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
elif self.settings.get("tor_bridges_use_custom_bridges"):
for line in self.settings.get(
"tor_bridges_use_custom_bridges"
).split("\n"):
if line.strip() != "":
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
elif self.settings.get("bridges_type") == "custom":
for line in self.settings.get("bridges_custom").split("\n"):
if line.strip() != "":
f.write(f"Bridge {line}\n")
f.write("\nUseBridges 1\n")
# Execute a tor subprocess
start_ts = time.time()

View file

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

View file

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