def chutney(reactor, temp_dir): chutney_dir = join(temp_dir, 'chutney') mkdir(chutney_dir) # TODO: # check for 'tor' binary explicitly and emit a "skip" if we can't # find it # XXX yuck! should add a setup.py to chutney so we can at least # "pip install <path to tarball>" and/or depend on chutney in "pip # install -e .[dev]" (i.e. in the 'dev' extra) # # https://trac.torproject.org/projects/tor/ticket/20343 proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, 'git', ( 'git', 'clone', '--depth=1', 'https://git.torproject.org/chutney.git', chutney_dir, ), env=environ, ) pytest_twisted.blockon(proto.done) return chutney_dir
def chutney(reactor, temp_dir): chutney_dir = join(temp_dir, 'chutney') mkdir(chutney_dir) # TODO: # check for 'tor' binary explicitly and emit a "skip" if we can't # find it # XXX yuck! should add a setup.py to chutney so we can at least # "pip install <path to tarball>" and/or depend on chutney in "pip # install -e .[dev]" (i.e. in the 'dev' extra) # # https://trac.torproject.org/projects/tor/ticket/20343 proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, '/usr/bin/git', ( '/usr/bin/git', 'clone', '--depth=1', 'https://git.torproject.org/chutney.git', chutney_dir, ) ) pytest_twisted.blockon(proto.done) return chutney_dir
def chutney(reactor, temp_dir): chutney_dir = join(temp_dir, 'chutney') mkdir(chutney_dir) # TODO: # check for 'tor' binary explicitly and emit a "skip" if we can't # find it # XXX yuck! should add a setup.py to chutney so we can at least # "pip install <path to tarball>" and/or depend on chutney in "pip # install -e .[dev]" (i.e. in the 'dev' extra) # # https://trac.torproject.org/projects/tor/ticket/20343 proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, 'git', ( 'git', 'clone', 'https://git.torproject.org/chutney.git', chutney_dir, ), env=environ, ) pytest_twisted.blockon(proto.done) # XXX: Here we reset Chutney to the last revision known to work # with Python 2, as a workaround for Chutney moving to Python 3. # When this is no longer necessary, we will have to drop this and # add '--depth=1' back to the above 'git clone' subprocess. proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, 'git', ( 'git', '-C', chutney_dir, 'reset', '--hard', '99bd06c7554b9113af8c0877b6eca4ceb95dcbaa' ), env=environ, ) pytest_twisted.blockon(proto.done) return chutney_dir
def _create_anonymous_node(reactor, name, control_port, request, temp_dir, flog_gatherer, tor_network, introducer_furl): node_dir = join(temp_dir, name) web_port = "tcp:{}:interface=localhost".format(control_port + 2000) if True: print("creating", node_dir) mkdir(node_dir) proto = util._DumpOutputProtocol(None) reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'allmydata.scripts.runner', 'create-node', '--nickname', name, '--introducer', introducer_furl, '--hide-ip', '--tor-control-port', 'tcp:localhost:{}'.format(control_port), '--listen', 'tor', node_dir, ) ) yield proto.done with open(join(node_dir, 'tahoe.cfg'), 'w') as f: f.write(''' [node] nickname = %(name)s web.port = %(web_port)s web.static = public_html log_gatherer.furl = %(log_furl)s [tor] control.port = tcp:localhost:%(control_port)d onion.external_port = 3457 onion.local_port = %(local_port)d onion = true onion.private_key_file = private/tor_onion.privkey [client] # Which services should this client connect to? introducer.furl = %(furl)s shares.needed = 1 shares.happy = 1 shares.total = 2 ''' % { 'name': name, 'furl': introducer_furl, 'web_port': web_port, 'log_furl': flog_gatherer, 'control_port': control_port, 'local_port': control_port + 1000, }) print("running") yield util._run_node(reactor, node_dir, request, None) print("okay, launched")
def test_daemon_migrate(request, reactor, alice, temp_dir): """ 'magic-folder migrate' happy-path works """ node_dir = join(temp_dir, "test-daemon-migrate") # if we're depending on a "new" tahoe (which we should) then # there's no "tahoe magic-folder" to create "legacy" config for us # to migrate. So, we create an (empty) config. with open(join(alice.node_directory, "private", "magic_folders.yaml"), "w") as f: f.write("magic-folders: {}\n") proto = util._DumpOutputProtocol(None) util._magic_folder_runner( proto, reactor, request, [ "--config", node_dir, "migrate", "--listen-endpoint", "tcp:1234", "--node-directory", alice.node_directory, "--author", "test", ], ) yield proto.done proto = util._CollectOutputProtocol() util._magic_folder_runner( proto, reactor, request, [ "--config", node_dir, "show-config", ], ) output = yield proto.done config = loads(output) assert config["api_endpoint"] == "tcp:1234" assert config["magic_folders"] == dict() # the API token should at least be base64-decodable and result in 32 bytes of entropy assert len(base64.urlsafe_b64decode( config["api_token"].encode("utf8"))) == 32
def cleanup(): try: twistd_process.signalProcess('TERM') pytest.blockon(twistd_protocol.exited) except ProcessExitedAlready: pass flog_file = mktemp('.flog_dump') flog_protocol = _DumpOutputProtocol(open(flog_file, 'w')) flog_dir = join(temp_dir, 'flog_gather') flogs = [x for x in listdir(flog_dir) if x.endswith('.flog')] print("Dumping {} flogtool logfiles to '{}'".format( len(flogs), flog_file)) reactor.spawnProcess( flog_protocol, flog_binary, ('flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0])), ) pytest.blockon(flog_protocol.done)
def cleanup(): _cleanup_tahoe_process(twistd_process, twistd_protocol.exited) flog_file = mktemp('.flog_dump') flog_protocol = _DumpOutputProtocol(open(flog_file, 'w')) flog_dir = join(temp_dir, 'flog_gather') flogs = [x for x in listdir(flog_dir) if x.endswith('.flog')] print("Dumping {} flogtool logfiles to '{}'".format( len(flogs), flog_file)) reactor.spawnProcess( flog_protocol, flog_binary, ('flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0])), ) print("Waiting for flogtool to complete") try: pytest_twisted.blockon(flog_protocol.done) except ProcessTerminated as e: print("flogtool exited unexpectedly: {}".format(str(e))) print("Flogtool completed")
def cleanup(): try: twistd_process.signalProcess('TERM') pytest.blockon(twistd_protocol.exited) except ProcessExitedAlready: pass flog_file = mktemp('.flog_dump') flog_protocol = _DumpOutputProtocol(open(flog_file, 'w')) flog_dir = join(temp_dir, 'flog_gather') flogs = [x for x in listdir(flog_dir) if x.endswith('.flog')] print("Dumping {} flogtool logfiles to '{}'".format(len(flogs), flog_file)) reactor.spawnProcess( flog_protocol, flog_binary, ( 'flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0]) ), ) pytest.blockon(flog_protocol.done)
def cleanup(): _cleanup_twistd_process(twistd_process, twistd_protocol.exited) flog_file = mktemp('.flog_dump') flog_protocol = _DumpOutputProtocol(open(flog_file, 'w')) flog_dir = join(temp_dir, 'flog_gather') flogs = [x for x in listdir(flog_dir) if x.endswith('.flog')] print("Dumping {} flogtool logfiles to '{}'".format(len(flogs), flog_file)) reactor.spawnProcess( flog_protocol, flog_binary, ( 'flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0]) ), ) print("Waiting for flogtool to complete") try: pytest_twisted.blockon(flog_protocol.done) except ProcessTerminated as e: print("flogtool exited unexpectedly: {}".format(str(e))) print("Flogtool completed")
def tor_network(reactor, temp_dir, chutney, request): # this is the actual "chutney" script at the root of a chutney checkout chutney_dir = chutney chut = join(chutney_dir, 'chutney') # now, as per Chutney's README, we have to create the network # ./chutney configure networks/basic # ./chutney start networks/basic env = environ.copy() env.update({"PYTHONPATH": join(chutney_dir, "lib")}) proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'configure', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env=env, ) pytest_twisted.blockon(proto.done) proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'start', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env=env, ) pytest_twisted.blockon(proto.done) # print some useful stuff proto = _CollectOutputProtocol() reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'status', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env=env, ) try: pytest_twisted.blockon(proto.done) except ProcessTerminated: print("Chutney.TorNet status failed (continuing):") print(proto.output.getvalue()) def cleanup(): print("Tearing down Chutney Tor network") proto = _CollectOutputProtocol() reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'stop', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env=env, ) pytest_twisted.blockon(proto.done) request.addfinalizer(cleanup) return chut
def tor_network(reactor, temp_dir, chutney, request): # this is the actual "chutney" script at the root of a chutney checkout chutney_dir = chutney chut = join(chutney_dir, 'chutney') # now, as per Chutney's README, we have to create the network # ./chutney configure networks/basic # ./chutney start networks/basic proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'configure', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) pytest.blockon(proto.done) proto = _DumpOutputProtocol(None) reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'start', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) pytest.blockon(proto.done) # print some useful stuff proto = _CollectOutputProtocol() reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'status', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) pytest.blockon(proto.done) def cleanup(): print("Tearing down Chutney Tor network") proto = _CollectOutputProtocol() reactor.spawnProcess( proto, sys.executable, ( sys.executable, '-m', 'chutney.TorNet', 'stop', join(chutney_dir, 'networks', 'basic'), ), path=join(chutney_dir), env={"PYTHONPATH": join(chutney_dir, "lib")}, ) pytest.blockon(proto.done) request.addfinalizer(cleanup) return chut
def _create_anonymous_node(reactor, name, control_port, request, temp_dir, flog_gatherer, tor_network, introducer_furl): node_dir = join(temp_dir, name) web_port = "tcp:{}:interface=localhost".format(control_port + 2000) if True: print("creating", node_dir) mkdir(node_dir) proto = util._DumpOutputProtocol(None) reactor.spawnProcess(proto, sys.executable, ( sys.executable, '-m', 'allmydata.scripts.runner', 'create-node', '--nickname', name, '--introducer', introducer_furl, '--hide-ip', '--tor-control-port', 'tcp:localhost:{}'.format(control_port), '--listen', 'tor', node_dir, )) yield proto.done with open(join(node_dir, 'tahoe.cfg'), 'w') as f: f.write( ''' [node] nickname = %(name)s web.port = %(web_port)s web.static = public_html log_gatherer.furl = %(log_furl)s [tor] control.port = tcp:localhost:%(control_port)d onion.external_port = 3457 onion.local_port = %(local_port)d onion = true onion.private_key_file = private/tor_onion.privkey [client] # Which services should this client connect to? introducer.furl = %(furl)s shares.needed = 1 shares.happy = 1 shares.total = 2 ''' % { 'name': name, 'furl': introducer_furl, 'web_port': web_port, 'log_furl': flog_gatherer, 'control_port': control_port, 'local_port': control_port + 1000, }) print("running") yield util._run_node(reactor, node_dir, request, None) print("okay, launched")