<commit_before>import pytest
import re


testinfra_hosts = ["app-staging"]
sdvars = pytest.securedrop_test_vars


@pytest.mark.parametrize('tor_service', sdvars.tor_services)
def test_tor_service_directories(host, tor_service):
    """
    Check mode and ownership on Tor service directories.
    """
    with host.sudo():
        f = host.file("/var/lib/tor/services/{}".format(tor_service['name']))
        assert f.is_directory
        assert f.mode == 0o700
        assert f.user == "debian-tor"
        assert f.group == "debian-tor"


@pytest.mark.parametrize('tor_service', sdvars.tor_services)
def test_tor_service_hostnames(host, tor_service):
    """
    Check contents of tor service hostname file. For normal Hidden Services,
    the file should contain only hostname (.onion URL). For Authenticated
    Hidden Services, it should also contain the HidServAuth cookie.
    """
    # Declare regex only for THS; we'll build regex for ATHS only if
    # necessary, since we won't have the required values otherwise.
    ths_hostname_regex = r"[a-z0-9]{16}\.onion"

    with host.sudo():
        f = host.file("/var/lib/tor/services/{}/hostname".format(
            tor_service['name']))
        assert f.is_file
        assert f.mode == 0o600
        assert f.user == "debian-tor"
        assert f.group == "debian-tor"

        # All hostnames should contain at *least* the hostname.<commit_msg>'s/Hidden Services/Onion Services/g' on test_tor_hidden_services.py<commit_after>import pytest
import re


testinfra_hosts = ["app-staging"]
sdvars = pytest.securedrop_test_vars


@pytest.mark.parametrize('tor_service', sdvars.tor_services)
def test_tor_service_directories(host, tor_service):
    """
    Check mode and ownership on Tor service directories.
    """
    with host.sudo():
        f = host.file("/var/lib/tor/services/{}".format(tor_service['name']))
        assert f.is_directory
        assert f.mode == 0o700
        assert f.user == "debian-tor"
        assert f.group == "debian-tor"


@pytest.mark.parametrize('tor_service', sdvars.tor_services)
def test_tor_service_hostnames(host, tor_service):
    """
    Check contents of tor service hostname file. For normal Onion Services,
    the file should contain only hostname (.onion URL). For Authenticated
    Onion Services, it should also contain the HidServAuth cookie.
    """
    # Declare regex only for THS; we'll build regex for ATHS only if
    # necessary, since we won't have the required values otherwise.
    ths_hostname_regex = r"[a-z0-9]{16}\.onion"

    with host.sudo():
        f = host.file("/var/lib/tor/services/{}/hostname".format(
            tor_service['name']))
        assert f.is_file
        assert f.mode == 0o600
        assert f.user == "debian-tor"
        assert f.group == "debian-tor"

        # All hostnames should contain at *least* the hostname.
{'fraction_non_alphanumeric': 0.1146051712089448, 'fraction_numerical': 0.008385744234800839, 'mean_word_length': 3.1194244604316546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7389201', 'n_tokens_mistral': 926, 'n_tokens_neox': 879, 'n_words': 239}