summaryrefslogtreecommitdiff
path: root/tests/integration_tests/datasources/test_tmp_noexec.py
blob: a060e20fa45952dffaae46c6e15b6a5f3642b474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pytest

from tests.integration_tests.instances import IntegrationInstance
from tests.integration_tests.util import verify_clean_log


def customize_client(client: IntegrationInstance):
    assert client.execute(
        "echo '/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0'"
        " | sudo tee -a /etc/fstab"
    ).ok
    client.execute("cloud-init clean --logs")
    client.restart()


@pytest.mark.adhoc
@pytest.mark.azure
@pytest.mark.ec2
@pytest.mark.gce
@pytest.mark.oci
@pytest.mark.openstack
def test_dhcp_tmp_noexec(client: IntegrationInstance):
    customize_client(client)
    assert (
        "noexec" in client.execute('grep "/var/tmp" /proc/mounts').stdout
    ), "Precondition error: /var/tmp is not mounted as noexec"
    log = client.read_from_file("/var/log/cloud-init.log")
    assert (
        "dhclient did not produce expected files: dhcp.leases, dhclient.pid"
        not in log
    )
    verify_clean_log(log)