From e952fa88e097e75ad70a37c81ed0a635f5647225 Mon Sep 17 00:00:00 2001 From: Denis Karpelevich Date: Sat, 18 Jan 2025 18:56:08 +0100 Subject: [PATCH] Parametrize sssctl tests 1. - Combine various sssctl tests to the single parametrized tests. test_sssctl__check_invalid_option_name_in_snippet merges tests: test_sssctl__check_invalid_option_name test_sssctl__check_invalid_option_name_in_snippet test_sssctl__check_invalid_section_in_name_in_snippet Signed-off-by: Denis Karpelevich --- src/tests/system/tests/test_sssctl.py | 100 ++++++++------------------ 1 file changed, 28 insertions(+), 72 deletions(-) diff --git a/src/tests/system/tests/test_sssctl.py b/src/tests/system/tests/test_sssctl.py index e3481e23ef..d8622fb6fc 100644 --- a/src/tests/system/tests/test_sssctl.py +++ b/src/tests/system/tests/test_sssctl.py @@ -191,32 +191,6 @@ def test_sssctl__reset_cached_timestamps_to_reflect_changes(client: Client, ldap assert "user1" not in res1.members -@pytest.mark.importance("high") -@pytest.mark.tools -@pytest.mark.topology(KnownTopology.Client) -def test_sssctl__check_invalid_option_name(client: Client): - """ - :title: sssctl config-check detects mistyped option name - :setup: - 1. Add wrong_option to domain section - 2. Apply config - :steps: - 1. Call sssctl config-check - 2. Check error message - :expectedresults: - 1. config-check detects an error in config - 2. Error message is properly set - :customerscenario: False - """ - client.sssd.common.local() - client.sssd.dom("test")["wrong_option"] = "true" - client.sssd.config_apply(check_config=False) - - result = client.sssctl.config_check() - assert result.rc != 0, "Config-check did not detect misconfigured config, when SSSD is running" - assert "Attribute 'wrong_option' is not allowed" in result.stdout, "Wrong error message was returned" - - @pytest.mark.importance("high") @pytest.mark.tools @pytest.mark.topology(KnownTopology.Client) @@ -242,6 +216,34 @@ def test_sssctl__check_missing_domain_name(client: Client): assert ex.match(r"Section \[domain\/\] is not allowed. Check for typos.*"), "Wrong error message was returned" +@pytest.mark.tools +@pytest.mark.topology(KnownTopology.Client) +@pytest.mark.parametrize( + "contents,expected", + [ + ("[domain/local]\ninvalid_option = True", "Attribute 'invalid_option' is not allowed"), + ("[invalid/local]\ninvalid_option = True", "Section [invalid/local] is not allowed"), + ], +) +def test_sssctl__check_invalid_option_name_in_snippet(client: Client, contents: str, expected: str): + """ + :title: sssctl config-check validates configuration snippet + :setup: + 1. Create a config snippet with an invalid option + :steps: + 1. Check the configuration using sssctl + :expectedresults: + 1. The config check fails with the appropriate output + :customerscenario: True + """ + client.sssd.common.local() + client.fs.write("/etc/sssd/conf.d/01_snippet.conf", contents, mode="640") + + result = client.sssctl.config_check() + assert result.rc != 0, "Config-check did not detect misconfigured config snippet" + assert expected in result.stdout, "Wrong error message was returned" + + @pytest.mark.importance("high") @pytest.mark.tools @pytest.mark.topology(KnownTopology.Client) @@ -271,52 +273,6 @@ def test_sssctl__check_misplaced_option(client: Client): assert pattern.search(result.stdout), "Wrong error message was returned" -@pytest.mark.tools -@pytest.mark.topology(KnownTopology.Client) -def test_sssctl__check_invalid_option_name_in_snippet(client: Client): - """ - :title: sssctl config-check detects invalid option name in snippet - :setup: - 1. Create new conf snippet with invalid option name - :steps: - 1. Call sssctl config-check - 2. Check error message - :expectedresults: - 1. config-check detects an error in config snippet - 2. Error message is properly set - :customerscenario: False - """ - client.sssd.common.local() - client.fs.write("/etc/sssd/conf.d/01_snippet.conf", "[domain/local]\ninvalid_option = True", mode="600") - - result = client.sssctl.config_check() - assert result.rc != 0, "Config-check did not detect misconfigured config snippet" - assert "Attribute 'invalid_option' is not allowed" in result.stdout, "Wrong error message was returned" - - -@pytest.mark.tools -@pytest.mark.topology(KnownTopology.Client) -def test_sssctl__check_invalid_section_in_name_in_snippet(client: Client): - """ - :title: sssctl config-check detects invalid domain name in snippet - :setup: - 1. Create new conf snippet with invalid domain name - :steps: - 1. Call sssctl config-check - 2. Check error message - :expectedresults: - 1. config-check detects an error in config snippet - 2. Error message is properly set - :customerscenario: False - """ - client.sssd.common.local() - client.fs.write("/etc/sssd/conf.d/01_snippet.conf", "[invalid/local]\ninvalid_option = True", mode="600") - - result = client.sssctl.config_check() - assert result.rc != 0, "Config-check did not detect misconfigured config snippet" - assert "Section [invalid/local] is not allowed" in result.stdout, "Wrong error message was returned" - - @pytest.mark.tools @pytest.mark.topology(KnownTopology.Client) def test_sssctl__check_missing_equal_sign(client: Client):