Blame SOURCES/openscap-1.2.17-filehash58_probe_test.patch

7c0ddc
diff --git a/tests/probes/filehash58/check_filehash_simple.xml b/tests/probes/filehash58/check_filehash_simple.xml
7c0ddc
new file mode 100644
7c0ddc
index 000000000..2f6fa877e
7c0ddc
--- /dev/null
7c0ddc
+++ b/tests/probes/filehash58/check_filehash_simple.xml
7c0ddc
@@ -0,0 +1,40 @@
7c0ddc
+<ns0:oval_definitions xmlns:ns0="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:ns2="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:ns3="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:ns4="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:ns5="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd">
7c0ddc
+  <ns0:generator>
7c0ddc
+    <ns2:product_name>combine_ovals.py from SCAP Security Guide</ns2:product_name>
7c0ddc
+    <ns2:product_version>ssg: [0, 1, 40], python: 3.6.5</ns2:product_version>
7c0ddc
+    <ns2:schema_version>5.11</ns2:schema_version>
7c0ddc
+    <ns2:timestamp>2018-07-20T09:33:24</ns2:timestamp>
7c0ddc
+  </ns0:generator>
7c0ddc
+  <ns0:definitions>
7c0ddc
+    <ns0:definition class="compliance" id="oval:ssg-oval_test_has_hash:def:1" version="1">
7c0ddc
+      <ns0:metadata>
7c0ddc
+        <ns0:title>Verify that hash of a file that should contain just "foo\n".</ns0:title>
7c0ddc
+        <ns0:affected family="unix">
7c0ddc
+          <ns0:platform>Red Hat Enterprise Linux 7</ns0:platform>
7c0ddc
+        </ns0:affected>
7c0ddc
+        <ns0:description>This description in OVALs is mandatory, but the most important is to have description in XCCDF.</ns0:description>
7c0ddc
+      <reference ref_id="oval_test_has_hash" source="ssg" /></ns0:metadata>
7c0ddc
+      <ns0:criteria>
7c0ddc
+        <ns0:criterion comment="Check file hash of /oval-test" test_ref="oval:ssg-oval_test_hash_matches:tst:1" />
7c0ddc
+      </ns0:criteria>
7c0ddc
+    </ns0:definition>
7c0ddc
+  </ns0:definitions>
7c0ddc
+  <ns0:tests>
7c0ddc
+    <ns3:filehash58_test check="all" comment="-" id="oval:ssg-oval_test_hash_matches:tst:1" version="1">
7c0ddc
+      <ns3:object object_ref="oval:ssg-concerned_file:obj:1" />
7c0ddc
+      <ns3:state state_ref="oval:ssg-hash_value:ste:1" />
7c0ddc
+    </ns3:filehash58_test>
7c0ddc
+  </ns0:tests>
7c0ddc
+  <ns0:objects>
7c0ddc
+    <ns3:filehash58_object id="oval:ssg-concerned_file:obj:1" version="1">
7c0ddc
+      <ns3:filepath>/oval-test</ns3:filepath>
7c0ddc
+      <ns3:hash_type>SHA-1</ns3:hash_type>
7c0ddc
+    </ns3:filehash58_object>
7c0ddc
+  </ns0:objects>
7c0ddc
+  <ns0:states>
7c0ddc
+    <ns3:filehash58_state id="oval:ssg-hash_value:ste:1" version="1">
7c0ddc
+      <ns3:hash_type>SHA-1</ns3:hash_type>
7c0ddc
+      <ns3:hash>f1d2d2f924e986ac86fdf7b36c94bcdf32beec15</ns3:hash>
7c0ddc
+    </ns3:filehash58_state>
7c0ddc
+  </ns0:states>
7c0ddc
+</ns0:oval_definitions>
7c0ddc
diff -r -U3 op0/tests/probes/filehash58/Makefile.in op1/tests/probes/filehash58/Makefile.in
7c0ddc
--- op0/tests/probes/filehash58/Makefile.in	2018-08-14 10:45:06.065438575 +0200
7c0ddc
+++ op1/tests/probes/filehash58/Makefile.in	2018-08-14 10:53:57.248937836 +0200
7c0ddc
@@ -1106,7 +1106,7 @@
7c0ddc
 		$(top_builddir)/run
7c0ddc
 
7c0ddc
 TESTS = test_probes_filehash58.sh
7c0ddc
-EXTRA_DIST = test_probes_filehash58.sh test_probes_filehash58.xml.sh
7c0ddc
+EXTRA_DIST = test_probes_filehash58.sh test_probes_filehash58.xml.sh check_filehash_simple.xml
7c0ddc
 all: all-am
7c0ddc
 
7c0ddc
 .SUFFIXES:
7c0ddc
diff -r -U3 op0/tests/probes/filehash58/test_probes_filehash58.sh op1/tests/probes/filehash58/test_probes_filehash58.sh
7c0ddc
--- op0/tests/probes/filehash58/test_probes_filehash58.sh	2018-08-14 10:36:09.914512125 +0200
7c0ddc
+++ op1/tests/probes/filehash58/test_probes_filehash58.sh	2018-08-14 10:53:32.366536647 +0200
7c0ddc
@@ -38,15 +38,69 @@
7c0ddc
 	ret_val=1
7c0ddc
     fi
7c0ddc
 
7c0ddc
+    # The file was created as a side-effect of test_probes_filehash58.xml.sh
7c0ddc
     [ $ret_val -eq 0 ] && rm -f /tmp/test_probes_filehash58.tmp
7c0ddc
 
7c0ddc
     return $ret_val
7c0ddc
 }
7c0ddc
 
7c0ddc
+
7c0ddc
+# $1: The chroot directory
7c0ddc
+function test_probes_filehash58_chroot {
7c0ddc
+
7c0ddc
+    probecheck "filehash58" || return 255
7c0ddc
+    require "sha1sum" || return 255
7c0ddc
+
7c0ddc
+    local ret_val=0;
7c0ddc
+    local DF="$srcdir/check_filehash_simple.xml"
7c0ddc
+
7c0ddc
+    absolute_probe_root=$(cd "$1" && pwd)
7c0ddc
+
7c0ddc
+    # oscap-chroot is not readily available during test run, so we use oscap + env var setting.
7c0ddc
+    result_keyword=$(OSCAP_PROBE_ROOT="$absolute_probe_root" "$OSCAP" oval eval "$DF" | grep oval_test_has_hash | grep -o '\w*$')
7c0ddc
+    
7c0ddc
+    [ "$result_keyword" == "$2" ] && return 0
7c0ddc
+    # vvv This is more a test error than a failure or "warning" vvv
7c0ddc
+    [ "$result_keyword" == "" ] && return 2
7c0ddc
+    return 1
7c0ddc
+}
7c0ddc
+
7c0ddc
+
7c0ddc
+function test_probes_filehash58_chroot_pass {
7c0ddc
+	local ret_val=0
7c0ddc
+
7c0ddc
+	mkdir -p pass
7c0ddc
+	echo foo > pass/oval-test
7c0ddc
+
7c0ddc
+	test_probes_filehash58_chroot pass true
7c0ddc
+	ret_val=$?
7c0ddc
+	rm -rf pass
7c0ddc
+
7c0ddc
+	return $ret_val
7c0ddc
+}
7c0ddc
+
7c0ddc
+
7c0ddc
+function test_probes_filehash58_chroot_fail {
7c0ddc
+	local ret_val=0
7c0ddc
+
7c0ddc
+	mkdir -p fail
7c0ddc
+	echo bar > fail/oval-test
7c0ddc
+
7c0ddc
+	test_probes_filehash58_chroot fail false
7c0ddc
+	ret_val=$?
7c0ddc
+	rm -rf fail
7c0ddc
+
7c0ddc
+	return $ret_val
7c0ddc
+}
7c0ddc
+
7c0ddc
 # Testing.
7c0ddc
 
7c0ddc
 test_init "test_probes_filehash58.log"
7c0ddc
 
7c0ddc
 test_run "test_probes_filehash58" test_probes_filehash58
7c0ddc
 
7c0ddc
+test_run "test_probes_filehash58_chroot_fail" test_probes_filehash58_chroot_fail
7c0ddc
+
7c0ddc
+test_run "test_probes_filehash58_chroot_pass" test_probes_filehash58_chroot_pass
7c0ddc
+
7c0ddc
 test_exit