summaryrefslogtreecommitdiff
path: root/tests/integration_tests/modules
diff options
context:
space:
mode:
authorJames Falcon <TheRealFalcon@users.noreply.github.com>2021-03-11 10:46:49 -0600
committerGitHub <noreply@github.com>2021-03-11 10:46:49 -0600
commitd95b448fe106146b7510f7b64f2e83c51943f04d (patch)
tree0cba16096f56ff802d6baf2ffde223c7518b22ab /tests/integration_tests/modules
parent74e1e50d4c3f1d3e3c6973ad74b06919b3738e34 (diff)
downloadvyos-cloud-init-d95b448fe106146b7510f7b64f2e83c51943f04d.tar.gz
vyos-cloud-init-d95b448fe106146b7510f7b64f2e83c51943f04d.zip
Integration test for #783 (#832)
Newer verisons of /etc/sudoers prefer @includedir over #includedir. Ensure we handle that properly and don't include an additional #includedir when one isn't warranted.
Diffstat (limited to 'tests/integration_tests/modules')
-rw-r--r--tests/integration_tests/modules/test_users_groups.py45
1 files changed, 40 insertions, 5 deletions
diff --git a/tests/integration_tests/modules/test_users_groups.py b/tests/integration_tests/modules/test_users_groups.py
index ee08d87b..bcb17b7f 100644
--- a/tests/integration_tests/modules/test_users_groups.py
+++ b/tests/integration_tests/modules/test_users_groups.py
@@ -1,16 +1,16 @@
-"""Integration test for the user_groups module.
-
-This test specifies a number of users and groups via user-data, and confirms
-that they have been configured correctly in the system under test.
+"""Integration tests for the user_groups module.
TODO:
-* This test assumes that the "ubuntu" user will be created when "default" is
+* This module assumes that the "ubuntu" user will be created when "default" is
specified; this will need modification to run on other OSes.
"""
import re
import pytest
+from tests.integration_tests.clouds import ImageSpecification
+from tests.integration_tests.instances import IntegrationInstance
+
USER_DATA = """\
#cloud-config
@@ -45,6 +45,12 @@ AHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
@pytest.mark.ci
@pytest.mark.user_data(USER_DATA)
class TestUsersGroups:
+ """Test users and groups.
+
+ This test specifies a number of users and groups via user-data, and
+ confirms that they have been configured correctly in the system under test.
+ """
+
@pytest.mark.ubuntu
@pytest.mark.parametrize(
"getent_args,regex",
@@ -86,3 +92,32 @@ class TestUsersGroups:
_, groups_str = output.split(":", maxsplit=1)
groups = groups_str.split()
assert "secret" in groups
+
+
+@pytest.mark.user_data(USER_DATA)
+def test_sudoers_includedir(client: IntegrationInstance):
+ """Ensure we don't add additional #includedir to sudoers.
+
+ Newer versions of /etc/sudoers will use @includedir rather than
+ #includedir. Ensure we handle that properly and don't include an
+ additional #includedir when one isn't warranted.
+
+ https://github.com/canonical/cloud-init/pull/783
+ """
+ if ImageSpecification.from_os_image().release in [
+ 'xenial', 'bionic', 'focal'
+ ]:
+ raise pytest.skip(
+ 'Test requires version of sudo installed on groovy and later'
+ )
+ client.execute("sed -i 's/#include/@include/g' /etc/sudoers")
+
+ sudoers = client.read_from_file('/etc/sudoers')
+ if '@includedir /etc/sudoers.d' not in sudoers:
+ client.execute("echo '@includedir /etc/sudoers.d' >> /etc/sudoers")
+ client.instance.clean()
+ client.restart()
+ sudoers = client.read_from_file('/etc/sudoers')
+
+ assert '#includedir' not in sudoers
+ assert sudoers.count('includedir /etc/sudoers.d') == 1