2021-05-11 17:34:35 +00:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
2016-10-06 05:03:35 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2021-05-11 17:34:35 +00:00
|
|
|
from future.utils import PY2
|
|
|
|
if PY2:
|
|
|
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
|
|
|
|
2016-10-06 05:03:35 +00:00
|
|
|
import sys
|
2020-10-27 13:49:58 +00:00
|
|
|
from os.path import join
|
2020-06-23 00:16:19 +00:00
|
|
|
|
|
|
|
import pytest
|
2019-02-05 16:03:35 +00:00
|
|
|
import pytest_twisted
|
2016-10-06 05:03:35 +00:00
|
|
|
|
2021-05-11 15:56:21 +00:00
|
|
|
from . import util
|
2016-10-06 05:03:35 +00:00
|
|
|
|
2020-11-27 02:46:57 +00:00
|
|
|
from twisted.python.filepath import (
|
|
|
|
FilePath,
|
|
|
|
)
|
|
|
|
|
2020-11-16 20:02:29 +00:00
|
|
|
from allmydata.test.common import (
|
|
|
|
write_introducer,
|
|
|
|
)
|
|
|
|
|
2020-02-13 15:26:57 +00:00
|
|
|
# see "conftest.py" for the fixtures (e.g. "tor_network")
|
2016-10-06 05:03:35 +00:00
|
|
|
|
2020-07-21 18:56:55 +00:00
|
|
|
# XXX: Integration tests that involve Tor do not run reliably on
|
|
|
|
# Windows. They are skipped for now, in order to reduce CI noise.
|
|
|
|
#
|
|
|
|
# https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3347
|
2020-06-23 00:16:19 +00:00
|
|
|
if sys.platform.startswith('win'):
|
|
|
|
pytest.skip('Skipping Tor tests on Windows', allow_module_level=True)
|
|
|
|
|
2021-11-03 13:55:16 +00:00
|
|
|
if PY2:
|
|
|
|
pytest.skip('Skipping Tor tests on Python 2 because dependencies are hard to come by', allow_module_level=True)
|
|
|
|
|
2019-02-05 16:03:35 +00:00
|
|
|
@pytest_twisted.inlineCallbacks
|
2016-10-06 05:03:35 +00:00
|
|
|
def test_onion_service_storage(reactor, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl):
|
|
|
|
yield _create_anonymous_node(reactor, 'carol', 8008, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl)
|
|
|
|
yield _create_anonymous_node(reactor, 'dave', 8009, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl)
|
|
|
|
# ensure both nodes are connected to "a grid" by uploading
|
|
|
|
# something via carol, and retrieve it using dave.
|
|
|
|
gold_path = join(temp_dir, "gold")
|
|
|
|
with open(gold_path, "w") as f:
|
|
|
|
f.write(
|
|
|
|
"The object-capability model is a computer security model. A "
|
|
|
|
"capability describes a transferable right to perform one (or "
|
|
|
|
"more) operations on a given object."
|
|
|
|
)
|
|
|
|
# XXX could use treq or similar to POST these to their respective
|
|
|
|
# WUIs instead ...
|
|
|
|
|
|
|
|
proto = util._CollectOutputProtocol()
|
|
|
|
reactor.spawnProcess(
|
|
|
|
proto,
|
|
|
|
sys.executable,
|
|
|
|
(
|
2021-04-16 15:58:37 +00:00
|
|
|
sys.executable, '-b', '-m', 'allmydata.scripts.runner',
|
2016-10-06 05:03:35 +00:00
|
|
|
'-d', join(temp_dir, 'carol'),
|
|
|
|
'put', gold_path,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
yield proto.done
|
|
|
|
cap = proto.output.getvalue().strip().split()[-1]
|
|
|
|
print("TEH CAP!", cap)
|
|
|
|
|
2021-05-11 15:56:21 +00:00
|
|
|
proto = util._CollectOutputProtocol(capture_stderr=False)
|
2016-10-06 05:03:35 +00:00
|
|
|
reactor.spawnProcess(
|
|
|
|
proto,
|
|
|
|
sys.executable,
|
|
|
|
(
|
2021-04-16 15:58:37 +00:00
|
|
|
sys.executable, '-b', '-m', 'allmydata.scripts.runner',
|
2016-10-06 05:03:35 +00:00
|
|
|
'-d', join(temp_dir, 'dave'),
|
|
|
|
'get', cap,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
yield proto.done
|
|
|
|
|
|
|
|
dave_got = proto.output.getvalue().strip()
|
2021-05-11 15:56:21 +00:00
|
|
|
assert dave_got == open(gold_path, 'rb').read().strip()
|
2016-10-06 05:03:35 +00:00
|
|
|
|
|
|
|
|
2019-02-05 16:03:35 +00:00
|
|
|
@pytest_twisted.inlineCallbacks
|
2016-10-06 05:03:35 +00:00
|
|
|
def _create_anonymous_node(reactor, name, control_port, request, temp_dir, flog_gatherer, tor_network, introducer_furl):
|
2020-11-27 02:46:57 +00:00
|
|
|
node_dir = FilePath(temp_dir).child(name)
|
2016-10-06 05:03:35 +00:00
|
|
|
web_port = "tcp:{}:interface=localhost".format(control_port + 2000)
|
|
|
|
|
|
|
|
if True:
|
2020-11-27 02:46:57 +00:00
|
|
|
print("creating", node_dir.path)
|
|
|
|
node_dir.makedirs()
|
2016-10-06 05:03:35 +00:00
|
|
|
proto = util._DumpOutputProtocol(None)
|
|
|
|
reactor.spawnProcess(
|
|
|
|
proto,
|
|
|
|
sys.executable,
|
|
|
|
(
|
2021-04-16 15:58:37 +00:00
|
|
|
sys.executable, '-b', '-m', 'allmydata.scripts.runner',
|
2016-10-06 05:03:35 +00:00
|
|
|
'create-node',
|
|
|
|
'--nickname', name,
|
|
|
|
'--introducer', introducer_furl,
|
|
|
|
'--hide-ip',
|
|
|
|
'--tor-control-port', 'tcp:localhost:{}'.format(control_port),
|
|
|
|
'--listen', 'tor',
|
2020-11-27 02:46:57 +00:00
|
|
|
node_dir.path,
|
2016-10-06 05:03:35 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
yield proto.done
|
|
|
|
|
2020-11-16 20:02:29 +00:00
|
|
|
|
|
|
|
# Which services should this client connect to?
|
|
|
|
write_introducer(node_dir, "default", introducer_furl)
|
2020-11-27 02:46:57 +00:00
|
|
|
with node_dir.child('tahoe.cfg').open('w') as f:
|
2021-05-11 15:56:21 +00:00
|
|
|
node_config = '''
|
2016-10-06 05:03:35 +00:00
|
|
|
[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]
|
|
|
|
shares.needed = 1
|
|
|
|
shares.happy = 1
|
|
|
|
shares.total = 2
|
|
|
|
|
|
|
|
''' % {
|
|
|
|
'name': name,
|
|
|
|
'web_port': web_port,
|
|
|
|
'log_furl': flog_gatherer,
|
|
|
|
'control_port': control_port,
|
|
|
|
'local_port': control_port + 1000,
|
2021-05-11 15:56:21 +00:00
|
|
|
}
|
|
|
|
node_config = node_config.encode("utf-8")
|
|
|
|
f.write(node_config)
|
2016-10-06 05:03:35 +00:00
|
|
|
|
|
|
|
print("running")
|
2020-11-27 02:46:57 +00:00
|
|
|
yield util._run_node(reactor, node_dir.path, request, None)
|
2016-10-06 05:03:35 +00:00
|
|
|
print("okay, launched")
|