Beispiel #1
0
def test_vanguards_configuration_ip(fs, monkeypatch):

    env = {
        "TOR_ENABLE_VANGUARDS": "true",
        "TOR_CONTROL_PORT": "127.0.0.1:7864",
        "TOR_CONTROL_PASSWORD": "******",
    }

    monkeypatch.setattr(os, "environ", env)
    monkeypatch.setattr(os, "fchmod", lambda x, y: None)

    torrc_tpl = get_vanguards_template()

    fs.create_file("/var/local/tor/vanguards.conf.tpl", contents=torrc_tpl)
    fs.create_file("/etc/tor/vanguards.conf")

    onion = Onions()
    onion.resolve_control_port()
    onion._setup_vanguards()
    onion._write_vanguards_conf()

    vanguard_conf = configparser.ConfigParser()

    with open("/etc/tor/vanguards.conf", "r") as f:
        print(f.read())

    vanguard_conf.read("/etc/tor/vanguards.conf")

    assert vanguard_conf["Global"]
    assert vanguard_conf["Global"]["control_ip"] == "127.0.0.1"
    assert vanguard_conf["Global"]["control_port"] == "7864"
    assert not vanguard_conf["Global"]["control_socket"]
    assert vanguard_conf["Global"]["control_pass"] == "secret"
    assert (vanguard_conf["Global"]["state_file"] ==
            "/run/tor/data/vanguards.state")
Beispiel #2
0
def test_vanguards_configuration_sock(fs, monkeypatch):
    extra_options = """
[Global]
enable_cbtverify = True
loglevel = DEBUG

[Rendguard]
rend_use_max_use_to_bw_ratio = 4.0
    """.strip()

    env = {
        "TOR_ENABLE_VANGUARDS": "true",
        "TOR_CONTROL_PORT": "unix:/path/to/sock",
        "VANGUARDS_EXTRA_OPTIONS": extra_options,
    }

    monkeypatch.setattr(os, "environ", env)
    monkeypatch.setattr(os, "fchmod", lambda x, y: None)

    torrc_tpl = get_vanguards_template()

    fs.create_file("/var/local/tor/vanguards.conf.tpl", contents=torrc_tpl)
    fs.create_file("/etc/tor/vanguards.conf")

    onion = Onions()
    onion.resolve_control_port()
    onion._setup_vanguards()
    onion._write_vanguards_conf()

    vanguard_conf = configparser.ConfigParser()

    with open("/etc/tor/vanguards.conf", "r") as f:
        print(f.read())

    vanguard_conf.read("/etc/tor/vanguards.conf")

    assert vanguard_conf["Global"]
    assert not vanguard_conf["Global"]["control_ip"]
    assert vanguard_conf["Global"]["control_port"] == "9051"
    assert vanguard_conf["Global"]["control_socket"] == "/path/to/sock"
    assert not vanguard_conf["Global"]["control_pass"]
    assert (vanguard_conf["Global"]["state_file"] ==
            "/run/tor/data/vanguards.state")
    assert vanguard_conf["Global"]["enable_cbtverify"]
    assert vanguard_conf["Global"]["loglevel"] == "DEBUG"
    assert vanguard_conf["Rendguard"]["rend_use_max_use_to_bw_ratio"] == "4.0"