summaryrefslogtreecommitdiff
path: root/tests/unittests/test_distros
diff options
context:
space:
mode:
authorJordi Massaguer Pla <jmassaguerpla@suse.de>2021-01-29 15:43:56 +0100
committerGitHub <noreply@github.com>2021-01-29 08:43:56 -0600
commit36ddf1ebed3f264fa86ef4f657dce29244c2e068 (patch)
treeacce33b73b3a123366720b9e0bf6ade151538b04 /tests/unittests/test_distros
parent71564dce3b6fa3e6aa398b0dd7415b21dca70701 (diff)
downloadvyos-cloud-init-36ddf1ebed3f264fa86ef4f657dce29244c2e068.tar.gz
vyos-cloud-init-36ddf1ebed3f264fa86ef4f657dce29244c2e068.zip
includedir in suoders can be prefixed by "arroba" (#783)
Since version 1.9.1, @includedir can be used in the sudoers files instead of #includedir: https://github.com/sudo-project/sudo/releases/tag/SUDO_1_9_1 Actually "@includedir" is the modern syntax, and "#includedir" the historic syntax. It has been considered that "#includedir" was too puzzling because it started with a "#" that otherwise denotes comments. This happens to be the default in SUSE Linux enterprise sudoer package, so cloudinit should take this into account. Otherwise, cloudinit was adding an extra #includedir, which was resulting on the files under /etc/sudoers.d being included twice, one by @includedir from the SUSE package, one by the @includedir from cloudinit. The consequence of this, was that if you were defining an Cmnd_Alias inside any of those files, this was being defined twice and creating an error when using sudo.
Diffstat (limited to 'tests/unittests/test_distros')
-rw-r--r--tests/unittests/test_distros/test_generic.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_generic.py b/tests/unittests/test_distros/test_generic.py
index 44607489..336150bc 100644
--- a/tests/unittests/test_distros/test_generic.py
+++ b/tests/unittests/test_distros/test_generic.py
@@ -119,6 +119,19 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase):
self.assertIn("josh", contents)
self.assertEqual(2, contents.count("josh"))
+ def test_sudoers_ensure_only_one_includedir(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ for char in ['#', '@']:
+ util.write_file("/etc/sudoers", "{}includedir /b".format(char))
+ d.ensure_sudo_dir("/b")
+ contents = util.load_file("/etc/sudoers")
+ self.assertIn("includedir /b", contents)
+ self.assertTrue(os.path.isdir("/b"))
+ self.assertEqual(1, contents.count("includedir /b"))
+
def test_arch_package_mirror_info_unknown(self):
"""for an unknown arch, we should get back that with arch 'default'."""
arch_mirrors = gapmi(package_mirrors, arch="unknown")