-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(tests): make user_groups integration tests distro-aware #6889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| IS_UBUNTU, | ||
| JAMMY, | ||
| NOBLE, | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
@@ -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 [] | ||
| ) | ||
|
|
||
|
mmummigatti marked this conversation as resolved.
|
||
| verify_clean_boot( | ||
| class_client, | ||
| require_warnings=warnings, | ||
|
|
@@ -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 | ||
|
|
@@ -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() | ||
|
|
||
|
mmummigatti marked this conversation as resolved.
|
||
| warnings = ( | ||
| [ | ||
| EXISTING_USER_EMPTY_PASSWD_WARNING.format( | ||
|
|
@@ -152,18 +163,19 @@ def test_nopassword_unlock_warnings(self, class_client): | |
| if CURRENT_RELEASE > NOBLE | ||
| else [] | ||
| ) | ||
|
|
||
| verify_clean_boot( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
| ) | ||
|
|
||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
| ) | ||
|
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. | ||
|
|
||
|
|
@@ -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:] | ||
|
|
||
|
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 | ||
|
|
@@ -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 | ||
Uh oh!
There was an error while loading. Please reload this page.