From 71d8346d4a4d1fc497256c2df3bf1204b0adb446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= Date: Tue, 29 Jun 2021 18:03:10 +0200 Subject: [PATCH] Fix failing tests - fix test tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh from upstream test suite (runs as a part of smoke test) - oval/yamlfilecontent: Add 'null' values handling Resolves: RHBZ#1952789 --- openscap-1.3.6-fix-failing-test-pr-1775.patch | 40 +++++ openscap-1.3.6-yamlfile-null-pr-1756.patch | 150 ++++++++++++++++++ openscap.spec | 8 +- 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 openscap-1.3.6-fix-failing-test-pr-1775.patch create mode 100644 openscap-1.3.6-yamlfile-null-pr-1756.patch diff --git a/openscap-1.3.6-fix-failing-test-pr-1775.patch b/openscap-1.3.6-fix-failing-test-pr-1775.patch new file mode 100644 index 0000000..70f9798 --- /dev/null +++ b/openscap-1.3.6-fix-failing-test-pr-1775.patch @@ -0,0 +1,40 @@ +From 11e5d42d279f39c13a9bdea7df6da7728b85a0b5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= +Date: Tue, 29 Jun 2021 09:12:34 +0200 +Subject: [PATCH] Fix failing test + +The test fails becuse the OVAL content in +`test_remediation_simple.oval.xml` used in rule +`xccdf_moc.elpmaxe.www_rule_1` in +`test_profile_selection_by_suffix.xccdf.xml` expects that a file named +`test_file` exists in the current working directory. + +This test doesn't fail when executed as a part of complete test suite +run. I guess that it's because some other test creates the `test_file` +file and doesn't delete it. Unfortunately, I can't find which test +creates it. There are many test cases that use a file `test_file` +and it is also created often by remediation executed in some tests. +--- + .../API/XCCDF/unittests/test_profile_selection_by_suffix.sh | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh b/tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh +index 910264626a..9b0852df37 100755 +--- a/tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh ++++ b/tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh +@@ -13,6 +13,9 @@ echo "Stderr file = $stderr" + echo "Result file = $result" + ret=0 + ++touch test_file ++[ -f test_file ] ++ + # Multiple matches should result in failure + $OSCAP xccdf eval --profile common $benchmark 2> $stderr || ret=$? + [ $ret -eq 1 ] +@@ -55,3 +58,5 @@ grep -Fq "No profile matching suffix \"another\" was found" $stderr + + [ -f $stderr ]; rm $stderr + rm $result ++ ++rm -f test_file diff --git a/openscap-1.3.6-yamlfile-null-pr-1756.patch b/openscap-1.3.6-yamlfile-null-pr-1756.patch new file mode 100644 index 0000000..9489211 --- /dev/null +++ b/openscap-1.3.6-yamlfile-null-pr-1756.patch @@ -0,0 +1,150 @@ +From 89f99834ba183284a7d75835932a0c0ea4eb9007 Mon Sep 17 00:00:00 2001 +From: Evgeny Kolesnikov +Date: Mon, 17 May 2021 08:40:17 +0200 +Subject: [PATCH] oval/yamlfilecontent: Add 'null' values handling + +For now null values would be represented as string '(null)' as +record's field could not be attributed as nil="true" yet. +--- + .../independent/yamlfilecontent_probe.c | 9 ++++ + .../test_probes_yamlfilecontent_types.sh | 5 ++ + .../test_probes_yamlfilecontent_types.xml | 52 +++++++++++++++++++ + tests/probes/yamlfilecontent/types.yaml | 4 ++ + 4 files changed, 70 insertions(+) + +diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c +index 62a8f4ff29..2d0cac6991 100644 +--- a/src/OVAL/probes/independent/yamlfilecontent_probe.c ++++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c +@@ -41,6 +41,7 @@ + #define OSCAP_YAML_BOOL_TAG "tag:yaml.org,2002:bool" + #define OSCAP_YAML_FLOAT_TAG "tag:yaml.org,2002:float" + #define OSCAP_YAML_INT_TAG "tag:yaml.org,2002:int" ++#define OSCAP_YAML_NULL_TAG "tag:yaml.org,2002:null" + + #define OVECCOUNT 30 /* should be a multiple of 3 */ + +@@ -135,6 +136,14 @@ static SEXP_t *yaml_scalar_event_to_sexp(yaml_event_t *event) + return NULL; + } + } ++ if (question || !strcmp(tag, OSCAP_YAML_NULL_TAG)) { ++ if (match_regex("^(null|Null|NULL|~|)$", value)) { ++ // TODO: Return real NULL when record's field will support nil="true" ++ return SEXP_string_new("(null)", strlen("(null)")); ++ } else if (!question) { ++ return NULL; ++ } ++ } + + return SEXP_string_new(value, strlen(value)); + } +diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh +index 4f110f6eb7..e445771d03 100755 +--- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh ++++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh +@@ -60,6 +60,11 @@ function test_probes_yamlfilecontent_types { + assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and @datatype!="boolean" and text()="true"]' + # string_number + assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and @datatype!="int" and text()="81"]' ++ # string_null ++ assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and text()="null"]' ++ ++ # null_1_2_3 ++ assert_exists 3 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and text()="(null)"]' + + # bool_error_cast, int_error_cast, float_error_cast + co='/oval_results/results/system/oval_system_characteristics/collected_objects' +diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml +index adf96571b8..503ec2d4a4 100644 +--- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml ++++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml +@@ -262,6 +262,19 @@ + + + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +@@ -364,6 +377,21 @@ + + + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +@@ -517,6 +545,30 @@ + types.yaml + .float_error_cast + ++ ++ ++ /tmp ++ types.yaml ++ .null_1 ++ ++ ++ ++ /tmp ++ types.yaml ++ .null_2 ++ ++ ++ ++ /tmp ++ types.yaml ++ .null_3 ++ ++ ++ ++ /tmp ++ types.yaml ++ .string_null ++ + + + +diff --git a/tests/probes/yamlfilecontent/types.yaml b/tests/probes/yamlfilecontent/types.yaml +index f05fa3a967..fb26eab5f0 100644 +--- a/tests/probes/yamlfilecontent/types.yaml ++++ b/tests/probes/yamlfilecontent/types.yaml +@@ -19,7 +19,11 @@ bool_false_cast: !!bool "false" + int_cast: !!int "369" + float_cast: !!float "978.65" + string_true: "true" ++string_null: "null" + string_number: "81" + bool_error_cast: !!bool "falsee" + int_error_cast: !!int "50%" + float_error_cast: !!float "58.41$" ++null_1: null ++null_2: ++null_3: !!null "null" diff --git a/openscap.spec b/openscap.spec index 6198c35..7402a02 100644 --- a/openscap.spec +++ b/openscap.spec @@ -1,6 +1,6 @@ Name: openscap Version: 1.3.5 -Release: 3%{?dist} +Release: 4%{?dist} Epoch: 1 Summary: Set of open source libraries enabling integration of the SCAP line of standards License: LGPLv2+ @@ -11,6 +11,8 @@ Patch2: openscap-1.3.6-replace-getlogin-pr-1753.patch Patch3: openscap-1.3.6-rpath-pr-1765.patch Patch4: openscap-1.3.6-ubi9-pr-1772.patch Patch5: openscap-1.3.6-rpminspect-xml-pr-1773.patch +Patch6: openscap-1.3.6-fix-failing-test-pr-1775.patch +Patch7: openscap-1.3.6-yamlfile-null-pr-1756.patch BuildRequires: cmake >= 2.6 BuildRequires: gcc BuildRequires: gcc-c++ @@ -196,6 +198,10 @@ pathfix.py -i %{__python3} -p -n $RPM_BUILD_ROOT%{_bindir}/scap-as-rpm %{_bindir}/oscap-run-sce-script %changelog +* Tue Jun 29 2021 Jan Černý - 1:1.3.5-4 +- Fix failing test tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh +- Add 'null' yamlfilecontent values handling + * Mon Jun 28 2021 Jan Černý - 1:1.3.5-3 - Do not set RPATH on built binaries - Fix UBI9 scan (rhbz#1953610)