Esempio n. 1
0
def test_one_domain_rule():
    services = generate_config()["services"]
    for service in HOST_COMPONENTS:
        if services.get(service):
            assert services[service]["environment"]["ONE_DOMAIN_MODE"] == "true"
    check_one_domain_setting("REVERSEPROXY")
    check_one_domain_setting("ADMIN_HOST")
    check_one_domain_setting("STORE_HOST")
    check_one_domain_setting("ADMIN_API_URL")
    check_one_domain_setting("STORE_API_URL")
    # Check preferred service setting
    # Store preferred
    check_preferred(services, "store")
    check_root_path(services, "store", "/")
    check_root_path(services, "admin", "/admin")
    check_root_path(services, "backend", "/api")
    # Admin preferred
    set_env("INSTALL", "backend")
    set_env("ADDITIONAL_COMPONENTS", "admin")
    services = generate_config()["services"]
    check_preferred(services, "admin")
    check_root_path(services, "store", None)
    check_root_path(services, "admin", "/")
    check_root_path(services, "backend", "/api")
    # Backebd preferred
    delete_env("ADDITIONAL_COMPONENTS")
    set_env("INSTALL", "backend")
    services = generate_config()["services"]
    check_preferred(services, "backend")
    check_root_path(services, "store", None)
    check_root_path(services, "admin", None)
    check_root_path(services, "backend", "/")
    # Cleanup
    delete_env("INSTALL")
Esempio n. 2
0
def test_frontend_rule():
    # Backend, store, admin
    services = generate_config()["services"]
    assert services["admin"]["links"] == ["backend"]
    assert services["store"]["links"] == ["backend"]
    # Backend, admin
    set_env("INSTALL", "backend")
    set_env("ADDITIONAL_COMPONENTS", "admin")
    services = generate_config()["services"]
    assert services["admin"]["links"] == ["backend"]
    assert "store" not in services
    # Backend, store
    set_env("ADDITIONAL_COMPONENTS", "store")
    services = generate_config()["services"]
    assert services["store"]["links"] == ["backend"]
    assert "admin" not in services
    # Store, admin
    set_env("INSTALL", "frontend")
    delete_env("ADDITIONAL_COMPONENTS")
    set_env("ADMIN_API_URL", "test")
    services = generate_config()["services"]
    assert "links" not in services["admin"]
    assert "links" not in services["store"]
    # Nothing
    set_env("INSTALL", "none")
    delete_env("ADMIN_API_URL")
    services = generate_config()["services"]
    assert "store" not in services
    assert "admin" not in services
    # Cleanup
    delete_env("INSTALL")
Esempio n. 3
0
def test_frontend_pack():
    set_env("INSTALL", "frontend")
    with pytest.raises(ConfigError):
        generate_config()
    set_env("ADMIN_API_URL", "http://localhost:8000")
    set_env("STORE_API_URL", "http://localhost:8000")
    config = generate_config()
    check_service_list(config, ["admin", "store"])
    # Cleanup
    delete_env("INSTALL")
    delete_env("ADMIN_API_URL")
    delete_env("STORE_API_URL")
Esempio n. 4
0
def test_additional_components_basic():
    set_env("ADDITIONAL_COMPONENTS", "invalid")
    assert "invalid" not in generate_config()["services"]
    set_env("ADDITIONAL_COMPONENTS", "test1;test2")
    assert Settings().ADDITIONAL_COMPONENTS == ["test1;test2"]
    set_env("ADDITIONAL_COMPONENTS", "test1,test2")
    assert Settings().ADDITIONAL_COMPONENTS == ["test1", "test2"]
    # Cleanup
    delete_env("ADDITIONAL_COMPONENTS")
Esempio n. 5
0
def test_tor_rule():
    services = generate_config()["services"]
    assert "tor" not in services
    set_env("ADDITIONAL_COMPONENTS", "tor")
    services = generate_config()["services"]
    assert "tor" in services
    for env_name, service in TOR_CRYPTOS.items():
        if services.get(service["component"]):
            assert f"{env_name.upper()}_PROXY_URL" in services[service["component"]]["environment"]
    for service in services:
        if service in HOST_COMPONENTS:
            assert services[service]["environment"]["HIDDENSERVICE_REVERSEPROXY"] == "nginx"
    set_env("REVERSEPROXY", "none")
    services = generate_config()["services"]
    for service in services:
        if service in HOST_COMPONENTS:
            assert "HIDDENSERVICE_IP" in services[service]["environment"]
    # Cleanup
    delete_env("ADDITIONAL_COMPONENTS")
    delete_env("REVERSEPROXY")
Esempio n. 6
0
def test_no_reverseproxy_rule():
    ports_components = HOST_COMPONENTS + CRYPTO_COMPONENTS
    services = generate_config()["services"]
    check_no_ports(services, ports_components)
    set_env("REVERSEPROXY", "nginx")
    services = generate_config()["services"]
    check_no_ports(services, ports_components)
    set_env("REVERSEPROXY", "none")
    services = generate_config()["services"]
    for service in services:
        if service in ports_components:
            if service in HOST_COMPONENTS:
                assert "ports" in services[service]
            if service in CRYPTO_COMPONENTS:
                assert "ports" not in services[service]
    set_env("BITCOIN_EXPOSE", "true")
    services = generate_config()["services"]
    assert "ports" in services["bitcoin"]
    # Cleanup
    delete_env("REVERSEPROXY")
    delete_env("BITCOIN_EXPOSE")
Esempio n. 7
0
def test_additional_components(component, expected):
    set_env("ADDITIONAL_COMPONENTS", component)
    config = generate_config()
    check_service_list(config, expected, is_none=not component)
    # Cleanup
    delete_env("ADDITIONAL_COMPONENTS")
Esempio n. 8
0
def test_no_cryptos():
    set_env("CRYPTOS", "invalid")
    assert "bitcoin" in generate_config()["services"]
    # Cleanup
    delete_env("CRYPTOS")
Esempio n. 9
0
def test_reverse_proxy(proxy, expected):
    set_env("REVERSEPROXY", proxy)
    config = generate_config()
    check_service_list(config, expected, is_none=proxy == "none")
    # Cleanup
    delete_env("REVERSEPROXY")
Esempio n. 10
0
def test_installation_packs(pack, expected):
    set_env("INSTALL", pack)
    config = generate_config()
    check_service_list(config, expected, is_none=pack == "none")
    # Cleanup
    delete_env("INSTALL")
Esempio n. 11
0
def check_one_domain_setting(name):
    set_env(name, "something")
    assert "ONE_DOMAIN_MODE" not in generate_config()["services"]["store"]["environment"]
    # Cleanup
    delete_env(name)