mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Apply only when env vars are set.
This commit is contained in:
@@ -2122,12 +2122,11 @@ def load_config(config_path):
|
|||||||
def save_config(config_path, settings, add_options: bool = True) -> None:
|
def save_config(config_path, settings, add_options: bool = True) -> None:
|
||||||
|
|
||||||
if add_options is True:
|
if add_options is True:
|
||||||
if os.getenv("BSX_DOCKER_MODE") or "docker_mode" not in settings:
|
# Add to config file only if manually set
|
||||||
|
if os.getenv("BSX_DOCKER_MODE"):
|
||||||
settings["setup_docker_mode"] = BSX_DOCKER_MODE
|
settings["setup_docker_mode"] = BSX_DOCKER_MODE
|
||||||
if os.getenv("BSX_LOCAL_TOR") or "local_tor" not in settings:
|
if os.getenv("BSX_LOCAL_TOR"):
|
||||||
settings["setup_local_tor"] = BSX_LOCAL_TOR
|
settings["setup_local_tor"] = BSX_LOCAL_TOR
|
||||||
|
|
||||||
# Add to settings only if manually set
|
|
||||||
if os.getenv("TOR_CONTROL_LISTEN_INTERFACE"):
|
if os.getenv("TOR_CONTROL_LISTEN_INTERFACE"):
|
||||||
settings["setup_tor_control_listen_interface"] = (
|
settings["setup_tor_control_listen_interface"] = (
|
||||||
TOR_CONTROL_LISTEN_INTERFACE
|
TOR_CONTROL_LISTEN_INTERFACE
|
||||||
@@ -2810,6 +2809,8 @@ def main():
|
|||||||
if disable_tor:
|
if disable_tor:
|
||||||
logger.info("Disabling TOR")
|
logger.info("Disabling TOR")
|
||||||
settings = load_config(config_path)
|
settings = load_config(config_path)
|
||||||
|
if not settings.get("use_tor", False):
|
||||||
|
logger.info("TOR is not enabled.") # Continue anyway to clear any config
|
||||||
settings["use_tor"] = False
|
settings["use_tor"] = False
|
||||||
for coin in settings["chainclients"]:
|
for coin in settings["chainclients"]:
|
||||||
modify_tor_config(
|
modify_tor_config(
|
||||||
|
|||||||
@@ -189,11 +189,24 @@ class Test(unittest.TestCase):
|
|||||||
with open(config_path) as fs:
|
with open(config_path) as fs:
|
||||||
settings = json.load(fs)
|
settings = json.load(fs)
|
||||||
assert settings.get("use_tor", False) is False
|
assert settings.get("use_tor", False) is False
|
||||||
assert settings["setup_docker_mode"] is False
|
assert "setup_docker_mode" not in settings
|
||||||
assert settings["setup_local_tor"] is False
|
assert "setup_local_tor" not in settings
|
||||||
assert "setup_tor_control_listen_interface" not in settings
|
assert "setup_tor_control_listen_interface" not in settings
|
||||||
assert "setup_torrc_dns_host" not in settings
|
assert "setup_torrc_dns_host" not in settings
|
||||||
|
|
||||||
|
# Set BSX_LOCAL_TOR to false
|
||||||
|
os.environ["BSX_LOCAL_TOR"] = "false"
|
||||||
|
# Reimport to reset globals and set env
|
||||||
|
importlib.reload(prepareSystem)
|
||||||
|
|
||||||
|
testargs = [
|
||||||
|
"basicswap-prepare",
|
||||||
|
"-datadir=" + test_path_plain,
|
||||||
|
"--disabletor",
|
||||||
|
]
|
||||||
|
with patch.object(sys, "argv", testargs):
|
||||||
|
prepareSystem.main()
|
||||||
|
|
||||||
os.environ["BSX_LOCAL_TOR"] = "true"
|
os.environ["BSX_LOCAL_TOR"] = "true"
|
||||||
# Reimport to reset globals and set env
|
# Reimport to reset globals and set env
|
||||||
importlib.reload(prepareSystem)
|
importlib.reload(prepareSystem)
|
||||||
@@ -224,7 +237,7 @@ class Test(unittest.TestCase):
|
|||||||
with open(config_path) as fs:
|
with open(config_path) as fs:
|
||||||
settings = json.load(fs)
|
settings = json.load(fs)
|
||||||
assert settings.get("use_tor", False) is True
|
assert settings.get("use_tor", False) is True
|
||||||
assert settings["setup_docker_mode"] is False
|
assert "setup_docker_mode" not in settings
|
||||||
assert settings["setup_local_tor"] is True
|
assert settings["setup_local_tor"] is True
|
||||||
assert settings["setup_tor_control_listen_interface"] == "127.1.1.1"
|
assert settings["setup_tor_control_listen_interface"] == "127.1.1.1"
|
||||||
assert "setup_torrc_dns_host" not in settings
|
assert "setup_torrc_dns_host" not in settings
|
||||||
|
|||||||
Reference in New Issue
Block a user