2021-05-11 17:34:35 +00:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
|
2016-10-06 05:03:35 +00:00
|
|
|
import sys
|
2020-10-27 13:49:58 +00:00
|
|
|
from os.path import join
|
2023-03-27 18:06:16 +00:00
|
|
|
from os import environ
|
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,
|
|
|
|
)
|
2022-05-13 17:29:08 +00:00
|
|
|
|
2020-11-16 20:02:29 +00:00
|
|
|
from allmydata.test.common import (
|
|
|
|
write_introducer,
|
|
|
|
)
|
2023-03-27 17:41:51 +00:00
|
|
|
from allmydata.client import read_config
|
2023-05-19 17:59:43 +00:00
|
|
|
from allmydata.util.deferredutil import async_to_deferred
|
2020-11-16 20:02:29 +00:00
|
|
|
|
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)
|
|
|
|
|
2023-11-20 22:44:56 +00:00
|
|
|
@pytest.mark.skipif(sys.version_info[:2] > (3, 11), reason='Chutney still does not support 3.12')
|
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):
|
2023-05-19 17:59:43 +00:00
|
|
|
"""
|
|
|
|
Two nodes and an introducer all configured to use Tahoe.
|
|
|
|
|
|
|
|
The two nodes can talk to the introducer and each other: we upload to one
|
|
|
|
node, read from the other.
|
|
|
|
"""
|
2023-07-29 10:04:05 +00:00
|
|
|
carol = yield _create_anonymous_node(reactor, 'carol', 8100, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl, 2)
|
|
|
|
dave = yield _create_anonymous_node(reactor, 'dave', 8101, request, temp_dir, flog_gatherer, tor_network, tor_introducer_furl, 2)
|
2023-04-13 06:37:32 +00:00
|
|
|
yield util.await_client_ready(carol, minimum_number_of_servers=2, timeout=600)
|
|
|
|
yield util.await_client_ready(dave, minimum_number_of_servers=2, timeout=600)
|
2023-05-19 17:59:43 +00:00
|
|
|
yield upload_to_one_download_from_the_other(reactor, temp_dir, carol, dave)
|
|
|
|
|
|
|
|
|
|
|
|
@async_to_deferred
|
|
|
|
async def upload_to_one_download_from_the_other(reactor, temp_dir, upload_to: util.TahoeProcess, download_from: util.TahoeProcess):
|
|
|
|
"""
|
|
|
|
Ensure both nodes are connected to "a grid" by uploading something via one
|
|
|
|
node, and retrieve it using the other.
|
|
|
|
"""
|
2022-05-13 17:29:08 +00:00
|
|
|
|
2016-10-06 05:03:35 +00:00
|
|
|
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',
|
2023-05-19 17:59:43 +00:00
|
|
|
'-d', upload_to.node_dir,
|
2016-10-06 05:03:35 +00:00
|
|
|
'put', gold_path,
|
2023-03-27 18:06:16 +00:00
|
|
|
),
|
|
|
|
env=environ,
|
2016-10-06 05:03:35 +00:00
|
|
|
)
|
2023-05-19 17:59:43 +00:00
|
|
|
await proto.done
|
2016-10-06 05:03:35 +00:00
|
|
|
cap = proto.output.getvalue().strip().split()[-1]
|
2023-04-13 04:34:45 +00:00
|
|
|
print("capability: {}".format(cap))
|
2016-10-06 05:03:35 +00:00
|
|
|
|
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',
|
2023-05-19 17:59:43 +00:00
|
|
|
'-d', download_from.node_dir,
|
2016-10-06 05:03:35 +00:00
|
|
|
'get', cap,
|
2023-03-27 18:06:16 +00:00
|
|
|
),
|
|
|
|
env=environ,
|
2016-10-06 05:03:35 +00:00
|
|
|
)
|
2023-05-19 17:59:43 +00:00
|
|
|
await proto.done
|
|
|
|
download_got = proto.output.getvalue().strip()
|
|
|
|
assert download_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
|
2023-07-29 10:04:05 +00:00
|
|
|
def _create_anonymous_node(reactor, name, web_port, request, temp_dir, flog_gatherer, tor_network, introducer_furl, shares_total: int) -> util.TahoeProcess:
|
2020-11-27 02:46:57 +00:00
|
|
|
node_dir = FilePath(temp_dir).child(name)
|
2022-07-27 15:59:23 +00:00
|
|
|
if node_dir.exists():
|
2020-11-14 08:56:03 +00:00
|
|
|
raise RuntimeError(
|
|
|
|
"A node already exists in '{}'".format(node_dir)
|
2016-10-06 05:03:35 +00:00
|
|
|
)
|
2023-07-03 14:55:33 +00:00
|
|
|
print(f"creating {node_dir.path} with introducer {introducer_furl}")
|
2022-07-27 15:59:23 +00:00
|
|
|
node_dir.makedirs()
|
2020-11-14 08:56:03 +00:00
|
|
|
proto = util._DumpOutputProtocol(None)
|
|
|
|
reactor.spawnProcess(
|
|
|
|
proto,
|
|
|
|
sys.executable,
|
|
|
|
(
|
2023-07-03 14:55:33 +00:00
|
|
|
sys.executable, '-b', '-m', 'allmydata.scripts.runner',
|
2020-11-14 08:56:03 +00:00
|
|
|
'create-node',
|
|
|
|
'--nickname', name,
|
2023-07-29 10:04:05 +00:00
|
|
|
'--webport', str(web_port),
|
2020-11-14 08:56:03 +00:00
|
|
|
'--introducer', introducer_furl,
|
|
|
|
'--hide-ip',
|
2023-07-29 10:04:05 +00:00
|
|
|
'--tor-control-port', tor_network.client_control_endpoint,
|
2020-11-14 08:56:03 +00:00
|
|
|
'--listen', 'tor',
|
2023-07-03 14:55:33 +00:00
|
|
|
'--shares-needed', '1',
|
|
|
|
'--shares-happy', '1',
|
|
|
|
'--shares-total', str(shares_total),
|
2022-07-27 15:59:23 +00:00
|
|
|
node_dir.path,
|
2023-07-03 14:55:33 +00:00
|
|
|
),
|
|
|
|
env=environ,
|
2016-10-06 05:03:35 +00:00
|
|
|
)
|
2020-11-14 08:56:03 +00:00
|
|
|
yield proto.done
|
2016-10-06 05:03:35 +00:00
|
|
|
|
2020-11-16 20:02:29 +00:00
|
|
|
|
|
|
|
# Which services should this client connect to?
|
|
|
|
write_introducer(node_dir, "default", introducer_furl)
|
2023-07-03 15:05:29 +00:00
|
|
|
util.basic_node_configuration(request, flog_gatherer.furl, node_dir.path)
|
2023-03-27 17:41:51 +00:00
|
|
|
|
|
|
|
config = read_config(node_dir.path, "tub.port")
|
|
|
|
config.set_config("tor", "onion", "true")
|
|
|
|
config.set_config("tor", "onion.external_port", "3457")
|
2023-07-29 10:04:05 +00:00
|
|
|
config.set_config("tor", "control.port", tor_network.client_control_endpoint)
|
2023-03-27 17:41:51 +00:00
|
|
|
config.set_config("tor", "onion.private_key_file", "private/tor_onion.privkey")
|
2016-10-06 05:03:35 +00:00
|
|
|
|
|
|
|
print("running")
|
2022-05-13 17:29:08 +00:00
|
|
|
result = yield util._run_node(reactor, node_dir.path, request, None)
|
2016-10-06 05:03:35 +00:00
|
|
|
print("okay, launched")
|
2022-05-13 17:29:08 +00:00
|
|
|
return result
|
2023-05-19 17:59:43 +00:00
|
|
|
|
2023-11-20 22:44:56 +00:00
|
|
|
@pytest.mark.skipif(sys.version_info[:2] > (3, 11), reason='Chutney still does not support 3.12')
|
2023-06-12 17:22:45 +00:00
|
|
|
@pytest.mark.skipif(sys.platform.startswith('darwin'), reason='This test has issues on macOS')
|
2023-05-19 17:59:43 +00:00
|
|
|
@pytest_twisted.inlineCallbacks
|
2023-06-12 16:00:05 +00:00
|
|
|
def test_anonymous_client(reactor, request, temp_dir, flog_gatherer, tor_network, introducer_furl):
|
2023-05-19 17:59:43 +00:00
|
|
|
"""
|
2023-06-12 16:00:05 +00:00
|
|
|
A normal node (normie) and a normal introducer are configured, and one node
|
2023-05-22 15:42:13 +00:00
|
|
|
(anonymoose) which is configured to be anonymous by talking via Tor.
|
2023-05-19 17:59:43 +00:00
|
|
|
|
2023-06-12 16:00:05 +00:00
|
|
|
Anonymoose should be able to communicate with normie.
|
2023-05-19 17:59:43 +00:00
|
|
|
|
2023-05-22 15:42:13 +00:00
|
|
|
TODO how to ensure that anonymoose is actually using Tor?
|
2023-05-19 17:59:43 +00:00
|
|
|
"""
|
2023-06-12 16:00:05 +00:00
|
|
|
normie = yield util._create_node(
|
|
|
|
reactor, request, temp_dir, introducer_furl, flog_gatherer, "normie",
|
|
|
|
web_port="tcp:9989:interface=localhost",
|
|
|
|
storage=True, needed=1, happy=1, total=1,
|
|
|
|
)
|
|
|
|
yield util.await_client_ready(normie)
|
|
|
|
|
2023-07-29 10:04:05 +00:00
|
|
|
anonymoose = yield _create_anonymous_node(reactor, 'anonymoose', 8102, request, temp_dir, flog_gatherer, tor_network, introducer_furl, 1)
|
2024-12-03 18:59:48 +00:00
|
|
|
yield util.await_client_ready(anonymoose, minimum_number_of_servers=1, timeout=1200)
|
2023-05-19 17:59:43 +00:00
|
|
|
|
2023-06-12 16:00:05 +00:00
|
|
|
yield upload_to_one_download_from_the_other(reactor, temp_dir, normie, anonymoose)
|