| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright 2013 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # This script is free software; you can redistribute it and/or |
| 7 | # modify it under the terms of the GNU Lesser General Public |
| 8 | # License as published by the Free Software Foundation; either |
| 9 | # version 2.1 of the License, or (at your option) any later version. |
| 10 | # |
| 11 | # This library is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | # Lesser General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU Lesser General Public |
| 17 | # License along with this library; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | |
| 20 | set -e -o pipefail |
| 21 | |
| 22 | . $builddir/tests/test_common.sh |
| 23 | |
| 24 | function ensure_oscap_version(){ |
| 25 | local name=$FUNCNAME |
| 26 | local stdout=$(mktemp -t ${name}.out.XXXXXX) |
| 27 | local stderr=$(mktemp -t ${name}.err.XXXXXX) |
| 28 | $OSCAP --version 2> $stderr > $stdout |
| 29 | [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr |
| 30 | grep "^Default CPE files: .*/cpe$" $stdout |
| 31 | grep " Inbuilt CPE names " $stdout |
| 32 | rm $stdout |
| 33 | } |
| 34 | |
| 35 | function _get_inbuilt_cpe_dir(){ |
| 36 | $OSCAP --version | awk -F: '/^Default CPE files: / {$1=""; print}' |
| 37 | } |
| 38 | |
| 39 | function _get_inbuilt_cpe_path(){ |
| 40 | echo "$(_get_inbuilt_cpe_dir)/openscap-cpe-dict.xml" |
| 41 | } |
| 42 | |
| 43 | function validate_inbuilt_dict(){ |
| 44 | local name=$FUNCNAME |
| 45 | local path=$(_get_inbuilt_cpe_path) |
| 46 | local output=$(mktemp -t ${name}.out.XXXXXX) |
| 47 | [ -f $path ] |
| 48 | $OSCAP cpe validate $path 2>&1 > $output |
| 49 | [ -f $output ]; [ ! -s $output ] |
| 50 | $OSCAP cpe validate $path 2>&1 > $output |
| 51 | [ -f $output ]; [ ! -s $output ] |
| 52 | rm $output |
| 53 | } |
| 54 | |
| 55 | function info_inbuilt_dict(){ |
| 56 | local name=$FUNCNAME |
| 57 | local path=$(_get_inbuilt_cpe_path) |
| 58 | local stderr=$(mktemp -t ${name}.err.XXXXXX) |
| 59 | [ -f $path ] |
| 60 | $OSCAP info $path 2> $stderr |
| 61 | [ -f $stderr ]; [ ! -s $stderr ]; |
| 62 | rm $stderr |
| 63 | } |
| 64 | |
| 65 | test_init test_api_cpe_inbuilt.log |
| 66 | |
| 67 | test_run "ensure_oscap_version" ensure_oscap_version |
| 68 | test_run "validate_inbuilt_dict" validate_inbuilt_dict |
| 69 | test_run "info_inbuilt_dict" info_inbuilt_dict |
| 70 | |
| 71 | test_exit |