openscap/SOURCES/openscap-1.3.4-export-profi...

108 lines
4.4 KiB
Diff

From cca0af9f2260a34aa4c2e57a7a418ce2b4732e16 Mon Sep 17 00:00:00 2001
From: Watson Sato <wsato@redhat.com>
Date: Mon, 28 Sep 2020 12:40:16 +0200
Subject: [PATCH 1/2] Test resolving a Profile with platform
---
tests/API/XCCDF/unittests/CMakeLists.txt | 1 +
.../test_xccdf_resolve_profile_platform.sh | 31 +++++++++++++++++++
...t_xccdf_resolve_profile_platform.xccdf.xml | 13 ++++++++
3 files changed, 45 insertions(+)
create mode 100755 tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.sh
create mode 100644 tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.xccdf.xml
diff --git a/tests/API/XCCDF/unittests/CMakeLists.txt b/tests/API/XCCDF/unittests/CMakeLists.txt
index 05ddea219..153a1c321 100644
--- a/tests/API/XCCDF/unittests/CMakeLists.txt
+++ b/tests/API/XCCDF/unittests/CMakeLists.txt
@@ -62,6 +62,7 @@ add_oscap_test("test_default_selector.sh")
add_oscap_test("test_inherit_selector.sh")
add_oscap_test("test_xccdf_refine_value_bad.sh")
add_oscap_test("test_xccdf_resolve.sh")
+add_oscap_test("test_xccdf_resolve_profile_platform.sh")
add_oscap_test("test_xccdf_results_arf_no_oval.sh")
add_oscap_test("test_xccdf_sub_title.sh")
add_oscap_test("test_xccdf_test_system.sh")
diff --git a/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.sh b/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.sh
new file mode 100755
index 000000000..95f8ce4b4
--- /dev/null
+++ b/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+. $builddir/tests/test_common.sh
+
+########################################################################
+### Test "oscap xccdf resolve" command on a Profile with platform
+########################################################################
+
+set -e
+set -o pipefail
+
+name=$(basename $0 .sh)
+
+result=$(mktemp -t ${name}.res.XXXXXX)
+stderr=$(mktemp -t ${name}.out.XXXXXX)
+stdout=$(mktemp -t ${name}.out.XXXXXX)
+
+
+echo "Stderr file = $stderr"
+echo "Result file = $result"
+
+$OSCAP xccdf resolve --output $result $srcdir/${name}.xccdf.xml > $stdout
+$OSCAP xccdf validate $result >> $stdout
+
+assert_exists 1 '//Benchmark[@resolved="1"]'
+
+# Resolve Profile Platform
+assert_exists 2 '//Profile[@id="xccdf_resolve_profile_platform"]/select'
+assert_exists 1 '//Profile[@id="xccdf_resolve_profile_platform"]/platform[@idref="cpe:/a:open-scap:oscap"]'
+
+[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
+rm $result
diff --git a/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.xccdf.xml b/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.xccdf.xml
new file mode 100644
index 000000000..f4773bef7
--- /dev/null
+++ b/tests/API/XCCDF/unittests/test_xccdf_resolve_profile_platform.xccdf.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_resolve_benchmark_1" resolved="false">
+ <status>incomplete</status>
+ <version>1.0</version>
+
+ <Profile id="xccdf_resolve_profile_platform">
+ <title>Profile with platform</title>
+ <platform idref="cpe:/a:open-scap:oscap"/>
+ <select idref="xccdf_test_rule_inherited" selected="true" />
+ <select idref="xccdf_test_rule_overridden" selected="true" />
+ </Profile>
+</Benchmark>
+
From 46b78146db6ba1fa57926068c4400d876423126b Mon Sep 17 00:00:00 2001
From: Watson Sato <wsato@redhat.com>
Date: Mon, 28 Sep 2020 13:03:46 +0200
Subject: [PATCH 2/2] Fix export of platform profile to DOM
The xccdf:platform should reference the ID of a CPE name or a CPE
applicability language expression.
---
src/XCCDF/profile.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/XCCDF/profile.c b/src/XCCDF/profile.c
index 776ef616a..b8a3f4749 100644
--- a/src/XCCDF/profile.c
+++ b/src/XCCDF/profile.c
@@ -319,7 +319,8 @@ void xccdf_profile_to_dom(struct xccdf_profile *profile, xmlNode *profile_node,
struct oscap_string_iterator *platforms = xccdf_profile_get_platforms(profile);
while (oscap_string_iterator_has_more(platforms)) {
const char *platform = oscap_string_iterator_next(platforms);
- xmlNewTextChild(profile_node, ns_xccdf, BAD_CAST "platform", BAD_CAST platform);
+ xmlNode *platform_node = xmlNewTextChild(profile_node, ns_xccdf, BAD_CAST "platform", NULL);
+ xmlNewProp(platform_node, BAD_CAST "idref", BAD_CAST platform);
}
oscap_string_iterator_free(platforms);