Skip to content

Commit

Permalink
Adds config tests for v2 services in torrc
Browse files Browse the repository at this point in the history
Each hidden service declaration provided by the test vars must have
"HiddenServiceVersion 2" immediately after the dir in the torrc.
At a later date we may want to templatize these values, but for now we
only support v2 Onion URLs for SD, so hardcoding is fine.
  • Loading branch information
Conor Schaefer committed Feb 2, 2019
1 parent 35c4185 commit 17a8fa3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions molecule/testinfra/staging/app/test_tor_hidden_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_tor_service_hostnames(File, Sudo, tor_service):


@pytest.mark.parametrize('tor_service', sdvars.tor_services)
def test_tor_services_config(File, tor_service):
def test_tor_services_config(host, tor_service):
"""
Ensure torrc file contains relevant lines for Hidden Service declarations.
All hidden services must include:
Expand All @@ -68,7 +68,7 @@ def test_tor_services_config(File, tor_service):
Check for each as appropriate.
"""
f = File("/etc/tor/torrc")
f = host.file("/etc/tor/torrc")
dir_regex = "HiddenServiceDir /var/lib/tor/services/{}".format(
tor_service['name'])
# We need at least one port, but it may be used for both config values.
Expand All @@ -80,13 +80,23 @@ def test_tor_services_config(File, tor_service):
except IndexError:
local_port = remote_port

# Ensure that service is hardcoded to v2, for compatibility
# with newer versions of Tor, which default to v3.
version_string = "HiddenServiceVersion 2"

port_regex = "HiddenServicePort {} 127.0.0.1:{}".format(
remote_port, local_port)

assert f.contains("^{}$".format(dir_regex))
assert f.contains("^{}$".format(port_regex))

service_regex = "\n".join([dir_regex, version_string, port_regex])

if tor_service['authenticated']:
auth_regex = "HiddenServiceAuthorizeClient stealth {}".format(
tor_service['client'])
assert f.contains("^{}$".format(auth_regex))
service_regex += "\n{}".format(auth_regex)

# Check for block in file, to ensure declaration order
assert service_regex in f.content_string

0 comments on commit 17a8fa3

Please sign in to comment.