Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions tests/integration_tests/modules/test_users_groups.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,6 +45,12 @@
@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",
Expand Down Expand Up @@ -86,3 +92,32 @@ def test_user_root_in_secret(self, class_client):
_, 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.
Comment thread
OddBloke marked this conversation as resolved.

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'
)
Comment on lines +107 to +112
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running for the weekend, but I just realised doing this instead of marks means that we'll launch the instance before deciding that we don't want to run this test (because we're using client and not session_cloud as we do elsewhere with this pattern).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll address this in #839

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()
Comment thread
OddBloke marked this conversation as resolved.
sudoers = client.read_from_file('/etc/sudoers')

assert '#includedir' not in sudoers
assert sudoers.count('includedir /etc/sudoers.d') == 1