Debian Codegraph @

tests/API/XCCDF/unittests/test_xccdf_results_arf_asset.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . $builddir/tests/test_common.sh
4
5 set -e
6 set -o pipefail
7
8 function test_xccdf_results_arf_asset {
9 local DS="${srcdir}/test_xccdf_results_arf_no_oval.xccdf.xml"
10 local result="results.xml"
11 local stderr="error.log"
12
13 [ -f $result ] && rm -f $result
14
15 $OSCAP xccdf eval --results-arf $result $DS 2> $stderr
16
17 [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
18
19 [ -f $result ]
20
21 local asset='/arf:asset-report-collection/arf:assets/arf:asset[@id="asset0"]/ai:computing-device'
22
23 case $(uname) in
24 FreeBSD)
25 local name=`hostname`
26 local domain=`grep search /etc/resolv.conf | cut -d " " -f 2`
27 local fqdn=$name.$domain
28 ;;
29 *)
30 local fqdn=`hostname --fqdn`
31 ;;
32 esac
33
34 echo $asset'/ai:fqdn[text()="'$fqdn'"]'
35 assert_exists 1 $asset'/ai:fqdn[text()="'$fqdn'"]'
36
37 local hostname=`hostname`
38 echo $asset'/ai:hostname[text()="'$hostname'"]'
39 assert_exists 1 $asset'/ai:hostname[text()="'$hostname'"]'
40
41 local macs=`ifconfig -a | grep ether | uniq | awk -F ' ' '{print toupper($2);}'`
42 for mac in $macs; do
43 echo $asset'/ai:connections/ai:connection/ai:mac-address[text()="'${mac}'"]'
44 assert_exists 1 $asset'/ai:connections/ai:connection/ai:mac-address[text()="'$mac'"]'
45 done
46
47 local ip4s=`ifconfig -a | grep 'inet ' | uniq | awk -F ' ' '{print $2;}'`
48 for ip in $ip4s; do
49 echo $asset'/ai:connections/ai:connection/ai:ip-address/ai:ip-v4[text()="'$ip'"]'
50 assert_exists 1 $asset'/ai:connections/ai:connection/ai:ip-address/ai:ip-v4[text()="'$ip'"]'
51 done
52
53 if require ipcalc; then
54 local ip6s=`ifconfig -a | grep 'inet6' | uniq | awk -F ' ' '{print $2;}'`
55 for ip in $ip6s; do
56 local ipf=`ipcalc $ip | grep Full | awk -F ' ' '{print gensub(/(^|:)0+([0-9a-f])/,"\\\1\\\2","g",$3);}'`
57 echo $asset'/ai:connections/ai:connection/ai:ip-address/ai:ip-v6[text()="'$ipf'"]'
58 assert_exists 1 $asset'/ai:connections/ai:connection/ai:ip-address/ai:ip-v6[text()="'$ipf'"]'
59 done
60 fi
61
62 rm $result
63 }
64
65 test_xccdf_results_arf_asset