def test_all_links():
    links = DockerLinks()
    all_links = links.links()
    print(links.to_json())

    assert len(all_links) == 4
    for _, item in all_links.items():
        assert len(set(item["names"]).intersection(LINKS))
def test_ports():
    links = DockerLinks()

    ports = links.links('test1', 'test2')

    for _, item in ports.items():
        if 'test1' in item["names"]:
            assert item["ports"]["800"]['protocol'] == 'tcp'
            assert item["ports"]["8001"]['protocol'] == 'udp'
        else:
            assert item["ports"]["800"]['protocol'] == 'udp'
            assert item["ports"]["8001"]['protocol'] == 'tcp'
def test_filtering():
    links = DockerLinks()
    test1 = links.links("test1")

    assert len(test1) == 1

    test2_and_3 = links.links("test2", "test3")

    assert len(test2_and_3) == 2

    test4_and_5 = links.links("test4", "notexist")
    assert len(test4_and_5) == 1

    test5 = links.links("notexist")
    assert len(test5) == 0
Beispiel #4
0
def set_conf():
    rtn = []
    links = DockerLinks()
    with open("/etc/tor/torrc", "a") as conf:
        for link in links.links():
            name = links.links()[link]['names'][1]
            path = "/var/lib/tor/hidden_service/{service}".format(service=name)
            if (name == 'bro' or name == 'bro-xinetd'):
                continue
            # Test if link has ports
            if len(links.links()[link]['ports']) == 0:
                print("{link} has no port")
                continue
            conf.write('HiddenServiceDir {path}\n'.format(path=path))
            rtn.append(name)
            for port in links.links()[link]['ports']:
                if links.links()[link]['ports'][port]['protocol'] == 'UDP':
                    continue
                service = '{port} {ip}:{port}'.format(port=port, ip=link)
                conf.write(
                    'HiddenServicePort {service}\n'.format(service=service))
        # set relay if enabled in env (not so secure)
        if 'RELAY' in os.environ:
            conf.write("ORPort 9001\n")
        # Disable local socket
        conf.write("SocksPort 0\n")
    return rtn
def set_conf():
    rtn = []
    links = DockerLinks()
    with open("/etc/tor/torrc", "a") as conf:
        for link in links.links():
            name=links.links()[link]['names'][1]
            path = "/var/lib/tor/hidden_service/{service}".format(service=name)
            if ( name == 'bro' or name == 'bro-xinetd' ):
               continue
            # Test if link has ports
            if len(links.links()[link]['ports']) == 0:
                print("{link} has no port")
                continue
            conf.write('HiddenServiceDir {path}\n'.format(path=path))
            rtn.append(name)
            for port in links.links()[link]['ports']:
                if links.links()[link]['ports'][port]['protocol'] == 'UDP':
                    continue
                service = '{port} {ip}:{port}'.format(
                    port=port, ip=link
                )
                conf.write('HiddenServicePort {service}\n'.format(
                    service=service
                ))
        # set relay if enabled in env (not so secure)
        if 'RELAY' in os.environ:
            conf.write("ORPort 9001\n")
        # Disable local socket
        conf.write("SocksPort 0\n")
    return rtn
def test_env():
    links = DockerLinks()
    env = links.links("test1", "test3")

    for _, item in env.items():
        assert item["environment"]["FOO"] == "bar"