URL: https://github.com/freeipa/freeipa/pull/4996 Author: rcritten Title: #4996: ipatests: CLI validation of ipa-healthcheck command Action: opened
PR body: """ Test for illegal input values. There is one xfail, BZ reported. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/4996/head:pr4996 git checkout pr4996
From e2d8bfabdaa318c79f7c1c6479177d90c82f1831 Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Wed, 5 Aug 2020 17:58:18 -0400 Subject: [PATCH 1/2] ipatests: CLI validation of ipa-healthcheck command Test for illegal input values. --- .../test_integration/test_ipahealthcheck.py | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py index cf406f56c0..1bf7384514 100644 --- a/ipatests/test_integration/test_ipahealthcheck.py +++ b/ipatests/test_integration/test_ipahealthcheck.py @@ -20,6 +20,7 @@ from ipapython.certdb import NSS_SQL_FILES from ipatests.pytest_ipa.integration import tasks from ipaplatform.paths import paths +from ipaplatform.osinfo import osinfo from ipatests.test_integration.base import IntegrationTest from ipatests.test_integration.test_cert import get_certmonger_fs_id @@ -1450,3 +1451,139 @@ def test_ipa_filesystemspace_check(self, create_jumbo_file): # Make sure we found the two errors we expected assert errors_found == 2 + + +class TestIpaHealthCLI(IntegrationTest): + """ + Validate the command-line options + + An attempt is made to not overlap tests done in other classes. + Run as a separate class so there is a "clean" system to test + against. + """ + + # In freeipa-healtcheck >= 0.6 the default tty output is + # --failures-only. To show all output use --all. This will + # tell us whether --all is available. + all_option = osinfo.id in ['fedora',] + if all_option: + base_cmd = ["ipa-healthcheck", "--all"] + else: + base_cmd = ["ipa-healthcheck"] + + @classmethod + def install(cls, mh): + tasks.install_master(cls.master, setup_dns=True) + tasks.install_packages(cls.master, HEALTHCHECK_PKG) + + def test_indent(self): + """ + Use illegal values for indent + """ + for option in ('a', '9.0'): + cmd = self.base_cmd + ["--indent", option] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 2 + assert 'invalid int value' in result.stderr_text + + # unusual success, arguably odd but not invalid :-) + for option in ('-1', '5000'): + cmd = self.base_cmd + ["--indent", option] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 0 + + def test_severity(self): + """ + Valid and invalid --severity + """ + # Baseline, there should be no errors + cmd = ["ipa-healthcheck", "--severity", "SUCCESS"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 0 + data = json.loads(result.stdout_text) + for check in data: + assert check["result"] == "SUCCESS" + + # All the other's should return nothing + for severity in ('WARNING', 'ERROR', 'CRITICAL'): + cmd = ["ipa-healthcheck", "--severity", severity] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 0 + data = json.loads(result.stdout_text) + assert len(data) == 0 + + # An unknown severity + cmd = ["ipa-healthcheck", "--severity", "BAD"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 2 + assert 'invalid choice' in result.stderr_text + + @pytest.mark.xfail(reason='BZ 1866558', strict=False) + def test_input_file(self): + """ + Verify the --input-file option + """ + # ipa-healthcheck overwrites output file, no need to generate + # a randomized name. + outfile = "/tmp/healthcheck.out" + + # create our output file + cmd = ["ipa-healthcheck", "--output-file", outfile] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 0 + + # load the file + cmd = ["ipa-healthcheck", "--failures-only", "--input-file", outfile] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 0 + data = json.loads(result.stdout_text) + for check in data: + assert check["result"] == "SUCCESS" + + # input file doesn't exist + cmd = self.base_cmd + ["--input-file", "/tmp/enoent"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 1 + assert 'No such file or directory' in result.stderr_text + + # Invalid input file + cmd = ["ipa-healthcheck", "--input-file", paths.IPA_CA_CRT] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 1 + assert 'Expecting value' in result.stderr_text + + def test_output_type(self): + """ + Check invalid output types. + + The supported json and human types are checked in other classes. + """ + cmd = self.base_cmd + ["--output-type", "hooman"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 2 + assert 'invalid choice' in result.stderr_text + + def test_source_and_check(self): + """ + Verify that invalid --source and/or --check are handled. + """ + cmd = self.base_cmd + ["--source", "nonexist"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 1 + assert "Source 'nonexist' not found" in result.stdout_text + + cmd = self.base_cmd + ["--source", "ipahealthcheck.ipa.certs", + "--check", "nonexist"] + result = self.master.run_command(cmd, raiseonerr=False) + assert result.returncode == 1 + assert "Check 'nonexist' not found in Source" in result.stdout_text + + def test_pki_healthcheck(self): + """ + Ensure compatibility with pki-healthcheck + + Running on a clean system should produce no errors. This will + ensure ABI compatibility. + """ + result = self.master.run_command(["pki-healthcheck"], raiseonerr=False) + assert result.returncode == 0 From 5607271d34ca95d942869a2888e4f474af5d16e3 Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Wed, 5 Aug 2020 17:59:35 -0400 Subject: [PATCH 2/2] Temp commit --- .freeipa-pr-ci.yaml | 2 +- ipatests/prci_definitions/temp_commit.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.freeipa-pr-ci.yaml b/.freeipa-pr-ci.yaml index abcf8c5b63..8065669008 120000 --- a/.freeipa-pr-ci.yaml +++ b/.freeipa-pr-ci.yaml @@ -1 +1 @@ -ipatests/prci_definitions/gating.yaml \ No newline at end of file +ipatests/prci_definitions/temp_commit.yaml \ No newline at end of file diff --git a/ipatests/prci_definitions/temp_commit.yaml b/ipatests/prci_definitions/temp_commit.yaml index e337068145..89a0dc21e0 100644 --- a/ipatests/prci_definitions/temp_commit.yaml +++ b/ipatests/prci_definitions/temp_commit.yaml @@ -68,7 +68,7 @@ jobs: class: RunPytest args: build_url: '{fedora-latest/build_url}' - test_suite: test_integration/test_REPLACEME.py + test_suite: test_integration/test_ipahealthcheck.py::TestIpaHealthCLI template: *ci-master-latest timeout: 3600 topology: *master_1repl_1client
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org