|
|
e8ee32 |
From 89f99834ba183284a7d75835932a0c0ea4eb9007 Mon Sep 17 00:00:00 2001
|
|
|
e8ee32 |
From: Evgeny Kolesnikov <ekolesni@redhat.com>
|
|
|
e8ee32 |
Date: Mon, 17 May 2021 08:40:17 +0200
|
|
|
e8ee32 |
Subject: [PATCH] oval/yamlfilecontent: Add 'null' values handling
|
|
|
e8ee32 |
|
|
|
e8ee32 |
For now null values would be represented as string '(null)' as
|
|
|
e8ee32 |
record's field could not be attributed as nil="true" yet.
|
|
|
e8ee32 |
---
|
|
|
e8ee32 |
.../independent/yamlfilecontent_probe.c | 9 ++++
|
|
|
e8ee32 |
.../test_probes_yamlfilecontent_types.sh | 5 ++
|
|
|
e8ee32 |
.../test_probes_yamlfilecontent_types.xml | 52 +++++++++++++++++++
|
|
|
e8ee32 |
tests/probes/yamlfilecontent/types.yaml | 4 ++
|
|
|
e8ee32 |
4 files changed, 70 insertions(+)
|
|
|
e8ee32 |
|
|
|
e8ee32 |
diff --git a/src/OVAL/probes/independent/yamlfilecontent_probe.c b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
e8ee32 |
index 62a8f4ff29..2d0cac6991 100644
|
|
|
e8ee32 |
--- a/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
e8ee32 |
+++ b/src/OVAL/probes/independent/yamlfilecontent_probe.c
|
|
|
e8ee32 |
@@ -41,6 +41,7 @@
|
|
|
e8ee32 |
#define OSCAP_YAML_BOOL_TAG "tag:yaml.org,2002:bool"
|
|
|
e8ee32 |
#define OSCAP_YAML_FLOAT_TAG "tag:yaml.org,2002:float"
|
|
|
e8ee32 |
#define OSCAP_YAML_INT_TAG "tag:yaml.org,2002:int"
|
|
|
e8ee32 |
+#define OSCAP_YAML_NULL_TAG "tag:yaml.org,2002:null"
|
|
|
e8ee32 |
|
|
|
e8ee32 |
#define OVECCOUNT 30 /* should be a multiple of 3 */
|
|
|
e8ee32 |
|
|
|
e8ee32 |
@@ -135,6 +136,14 @@ static SEXP_t *yaml_scalar_event_to_sexp(yaml_event_t *event)
|
|
|
e8ee32 |
return NULL;
|
|
|
e8ee32 |
}
|
|
|
e8ee32 |
}
|
|
|
e8ee32 |
+ if (question || !strcmp(tag, OSCAP_YAML_NULL_TAG)) {
|
|
|
e8ee32 |
+ if (match_regex("^(null|Null|NULL|~|)$", value)) {
|
|
|
e8ee32 |
+ // TODO: Return real NULL when record's field will support nil="true"
|
|
|
e8ee32 |
+ return SEXP_string_new("(null)", strlen("(null)"));
|
|
|
e8ee32 |
+ } else if (!question) {
|
|
|
e8ee32 |
+ return NULL;
|
|
|
e8ee32 |
+ }
|
|
|
e8ee32 |
+ }
|
|
|
e8ee32 |
|
|
|
e8ee32 |
return SEXP_string_new(value, strlen(value));
|
|
|
e8ee32 |
}
|
|
|
e8ee32 |
diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh
|
|
|
e8ee32 |
index 4f110f6eb7..e445771d03 100755
|
|
|
e8ee32 |
--- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh
|
|
|
e8ee32 |
+++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.sh
|
|
|
e8ee32 |
@@ -60,6 +60,11 @@ function test_probes_yamlfilecontent_types {
|
|
|
e8ee32 |
assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and @datatype!="boolean" and text()="true"]'
|
|
|
e8ee32 |
# string_number
|
|
|
e8ee32 |
assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and @datatype!="int" and text()="81"]'
|
|
|
e8ee32 |
+ # string_null
|
|
|
e8ee32 |
+ assert_exists 1 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and text()="null"]'
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ # null_1_2_3
|
|
|
e8ee32 |
+ assert_exists 3 $sd'/ind-sys:yamlfilecontent_item/ind-sys:value/field[@name="#" and text()="(null)"]'
|
|
|
e8ee32 |
|
|
|
e8ee32 |
# bool_error_cast, int_error_cast, float_error_cast
|
|
|
e8ee32 |
co='/oval_results/results/system/oval_system_characteristics/collected_objects'
|
|
|
e8ee32 |
diff --git a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml
|
|
|
e8ee32 |
index adf96571b8..503ec2d4a4 100644
|
|
|
e8ee32 |
--- a/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml
|
|
|
e8ee32 |
+++ b/tests/probes/yamlfilecontent/test_probes_yamlfilecontent_types.xml
|
|
|
e8ee32 |
@@ -262,6 +262,19 @@
|
|
|
e8ee32 |
</criteria>
|
|
|
e8ee32 |
</definition>
|
|
|
e8ee32 |
|
|
|
e8ee32 |
+ <definition class="compliance" version="1" id="oval:0:def:26">
|
|
|
e8ee32 |
+ <metadata>
|
|
|
e8ee32 |
+ <title></title>
|
|
|
e8ee32 |
+ <description></description>
|
|
|
e8ee32 |
+ </metadata>
|
|
|
e8ee32 |
+ <criteria operator="AND">
|
|
|
e8ee32 |
+ <criterion comment="comment" test_ref="oval:0:tst:26"/>
|
|
|
e8ee32 |
+ <criterion comment="comment" test_ref="oval:0:tst:27"/>
|
|
|
e8ee32 |
+ <criterion comment="comment" test_ref="oval:0:tst:28"/>
|
|
|
e8ee32 |
+ <criterion comment="comment" test_ref="oval:0:tst:29"/>
|
|
|
e8ee32 |
+ </criteria>
|
|
|
e8ee32 |
+ </definition>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
</definitions>
|
|
|
e8ee32 |
|
|
|
e8ee32 |
<tests>
|
|
|
e8ee32 |
@@ -364,6 +377,21 @@
|
|
|
e8ee32 |
<ind-def:object object_ref="oval:0:obj:25"/>
|
|
|
e8ee32 |
</ind-def:yamlfilecontent_test>
|
|
|
e8ee32 |
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_test version="1" id="oval:0:tst:26" check="all" comment="true">
|
|
|
e8ee32 |
+ <ind-def:object object_ref="oval:0:obj:26"/>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_test>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_test version="1" id="oval:0:tst:27" check="all" comment="true">
|
|
|
e8ee32 |
+ <ind-def:object object_ref="oval:0:obj:27"/>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_test>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_test version="1" id="oval:0:tst:28" check="all" comment="true">
|
|
|
e8ee32 |
+ <ind-def:object object_ref="oval:0:obj:28"/>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_test>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_test version="1" id="oval:0:tst:29" check="all" comment="true">
|
|
|
e8ee32 |
+ <ind-def:object object_ref="oval:0:obj:29"/>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_test>
|
|
|
e8ee32 |
</tests>
|
|
|
e8ee32 |
|
|
|
e8ee32 |
<objects>
|
|
|
e8ee32 |
@@ -517,6 +545,30 @@
|
|
|
e8ee32 |
<ind-def:filename>types.yaml</ind-def:filename>
|
|
|
e8ee32 |
<ind-def:yamlpath>.float_error_cast</ind-def:yamlpath>
|
|
|
e8ee32 |
</ind-def:yamlfilecontent_object>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_object version="1" id="oval:0:obj:26">
|
|
|
e8ee32 |
+ <ind-def:path>/tmp</ind-def:path>
|
|
|
e8ee32 |
+ <ind-def:filename>types.yaml</ind-def:filename>
|
|
|
e8ee32 |
+ <ind-def:yamlpath>.null_1</ind-def:yamlpath>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_object>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_object version="1" id="oval:0:obj:27">
|
|
|
e8ee32 |
+ <ind-def:path>/tmp</ind-def:path>
|
|
|
e8ee32 |
+ <ind-def:filename>types.yaml</ind-def:filename>
|
|
|
e8ee32 |
+ <ind-def:yamlpath>.null_2</ind-def:yamlpath>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_object>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_object version="1" id="oval:0:obj:28">
|
|
|
e8ee32 |
+ <ind-def:path>/tmp</ind-def:path>
|
|
|
e8ee32 |
+ <ind-def:filename>types.yaml</ind-def:filename>
|
|
|
e8ee32 |
+ <ind-def:yamlpath>.null_3</ind-def:yamlpath>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_object>
|
|
|
e8ee32 |
+
|
|
|
e8ee32 |
+ <ind-def:yamlfilecontent_object version="1" id="oval:0:obj:29">
|
|
|
e8ee32 |
+ <ind-def:path>/tmp</ind-def:path>
|
|
|
e8ee32 |
+ <ind-def:filename>types.yaml</ind-def:filename>
|
|
|
e8ee32 |
+ <ind-def:yamlpath>.string_null</ind-def:yamlpath>
|
|
|
e8ee32 |
+ </ind-def:yamlfilecontent_object>
|
|
|
e8ee32 |
</objects>
|
|
|
e8ee32 |
|
|
|
e8ee32 |
</oval_definitions>
|
|
|
e8ee32 |
diff --git a/tests/probes/yamlfilecontent/types.yaml b/tests/probes/yamlfilecontent/types.yaml
|
|
|
e8ee32 |
index f05fa3a967..fb26eab5f0 100644
|
|
|
e8ee32 |
--- a/tests/probes/yamlfilecontent/types.yaml
|
|
|
e8ee32 |
+++ b/tests/probes/yamlfilecontent/types.yaml
|
|
|
e8ee32 |
@@ -19,7 +19,11 @@ bool_false_cast: !!bool "false"
|
|
|
e8ee32 |
int_cast: !!int "369"
|
|
|
e8ee32 |
float_cast: !!float "978.65"
|
|
|
e8ee32 |
string_true: "true"
|
|
|
e8ee32 |
+string_null: "null"
|
|
|
e8ee32 |
string_number: "81"
|
|
|
e8ee32 |
bool_error_cast: !!bool "falsee"
|
|
|
e8ee32 |
int_error_cast: !!int "50%"
|
|
|
e8ee32 |
float_error_cast: !!float "58.41$"
|
|
|
e8ee32 |
+null_1: null
|
|
|
e8ee32 |
+null_2:
|
|
|
e8ee32 |
+null_3: !!null "null"
|