Skip to content
Open
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
29 changes: 23 additions & 6 deletions tests/integration_tests/modules/test_users_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
IS_UBUNTU,
JAMMY,
Comment thread
mmummigatti marked this conversation as resolved.
NOBLE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this space required?

)
from tests.integration_tests.util import verify_clean_boot

Expand Down Expand Up @@ -115,13 +116,18 @@ def test_users_groups(self, regex, getent_args, class_client):
)
)

@pytest.mark.skipif(
not IS_UBUNTU,
reason="Warning expectations are Ubuntu-specific",
)
def test_initial_warnings(self, class_client):
"""Check for initial warnings."""
warnings = (
[NEW_USER_EMPTY_PASSWD_WARNING.format(username="nopassworduser")]
if CURRENT_RELEASE > NOBLE
else []
)

Comment thread
mmummigatti marked this conversation as resolved.
verify_clean_boot(
class_client,
require_warnings=warnings,
Expand All @@ -134,6 +140,10 @@ def test_user_root_in_secret(self, class_client):
groups = groups_str.split()
assert "secret" in groups

@pytest.mark.skipif(
not IS_UBUNTU,
reason="Password unlock warning behavior differs across distros",
)
def test_nopassword_unlock_warnings(self, class_client):
"""Verify warnings for empty passwords for new and existing users."""
# Fake admin clearing and unlocking and empty unlocked password foobar
Expand All @@ -142,6 +152,7 @@ def test_nopassword_unlock_warnings(self, class_client):
class_client.execute("passwd -d foobar")
class_client.instance.clean()
class_client.restart()

Comment thread
mmummigatti marked this conversation as resolved.
warnings = (
[
EXISTING_USER_EMPTY_PASSWD_WARNING.format(
Expand All @@ -152,18 +163,19 @@ def test_nopassword_unlock_warnings(self, class_client):
if CURRENT_RELEASE > NOBLE
else []
)

verify_clean_boot(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change does not make sense.

class_client,
ignore_warnings=True, # ignore warnings about existing groups
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why remove this comment? Its not related to the change.

ignore_warnings=True,
require_warnings=warnings,
)

)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is simply whitespace issues. There should be no changes here. Can you double check?


@pytest.mark.user_data(USER_DATA)
@pytest.mark.skipif(
CURRENT_RELEASE < JAMMY,
reason="Requires version of sudo not available in older releases",
)
Comment thread
mmummigatti marked this conversation as resolved.
IS_UBUNTU and CURRENT_RELEASE < JAMMY,
reason="Requires version of sudo not available in older Ubuntu releases",
)

def test_sudoers_includedir(client: IntegrationInstance):
"""Ensure we don't add additional #includedir to sudoers.

Expand All @@ -178,11 +190,15 @@ def test_sudoers_includedir(client: IntegrationInstance):
sudoers_content_before = client.read_from_file(
"/etc/sudoers.d/90-cloud-init-users"
).splitlines()[1:]

Comment thread
mmummigatti marked this conversation as resolved.
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
Expand All @@ -191,4 +207,5 @@ def test_sudoers_includedir(client: IntegrationInstance):
sudoers_content_after = client.read_from_file(
"/etc/sudoers.d/90-cloud-init-users"
).splitlines()[1:]

assert sudoers_content_before == sudoers_content_after