-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Integration test for #783 #832
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
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 |
|---|---|---|
| @@ -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 @@ | |
| @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 @@ 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. | ||
|
|
||
| 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
Collaborator
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'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
Collaborator
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. 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() | ||
|
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 | ||
Uh oh!
There was an error while loading. Please reload this page.