File: test_api_cpe_uri.sh

package info (click to toggle)
openscap 1.0.9-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 129,588 kB
  • ctags: 26,325
  • sloc: xml: 611,156; ansic: 90,367; sh: 26,693; makefile: 2,463; python: 804; perl: 445; cpp: 123
file content (135 lines) | stat: -rwxr-xr-x 3,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash

# Copyright 2009 Red Hat Inc., Durham, North Carolina.
# All Rights Reserved.
#
# OpenScap CPE URI Module Test Suite.
#
# Authors:
#      Ondrej Moris <omoris@redhat.com>

. $srcdir/../../../test_common.sh

CPE_URIS=(`grep "cpe:" $srcdir/dict.xml | \
    sed 's/^.*cpe:/cpe:/g' | sed 's/".*$//g' | tr '\n' ' '`)

# Test cases.

function test_api_cpe_uri_smoke {
    ./test_api_cpe_uri --smoke-test
}

function test_api_cpe_uri_parse {
    require "grep" || return 255
    local ret_val=0
    for URI in ${CPE_URIS[@]}; do
	./test_api_cpe_uri --parsing  $URI parsing.out >/dev/null
	if [ $? -eq 0 ]; then
	    if [ ! "`cat  parsing.out`X" == "${URI}X" ]; then
		echo "`cat  parsing.out`X != ${URI}X"
		ret_val=1
	    fi
	else
	    echo "Parsing failed!"
	    ret_val=1
	fi	
    done
    return $ret_val
}

function test_api_cpe_uri_create {
    require "grep" || return 255
    local ret_val=0
    for URI in ${CPE_URIS[@]}; do
	./test_api_cpe_uri --parsing  $URI parsing.out > parsing.out.1
	if [ $? -eq 0 ]; then
	    if [ "`cat  parsing.out`X" == "${URI}X" ]; then
		sed 's/^\s*//g' parsing.out.1 > parsing.out.sed-tmp ; mv parsing.out.sed-tmp parsing.out.1
		sed 's/(null)//g' parsing.out.1 > parsing.out.sed-tmp ; mv parsing.out.sed-tmp parsing.out.1
		cat parsing.out.1 | xargs -d '\n' ./test_api_cpe_uri --creation > creation.out
 		if [ ! $? -eq 0 ] || [ "${URI}X" != "`cat creation.out`X" ]; then
		    echo "${URI}X != `cat creation.out`X"
		    ret_val=1; 
		fi
	    else
		echo "`cat  parsing.out`X != ${URI}X"
		ret_val=1
	    fi
	else
	    echo "Parsing failed!"
	    ret_val=1
	fi
    done
    return $ret_val
}

function test_api_cpe_uri_match {
    require "grep" || return 255
    local ret_val=0
    for URI in ${CPE_URIS[@]}; do
	./test_api_cpe_uri --parsing $URI parsing.out
	if [ $? -eq 0 ]; then
	    if [ "`cat parsing.out`X" == "${URI}X" ]; then
		CPE=(`cat parsing.out | sed 's/(null)//g' | \
		    sed 's/^\s*//g' | tr '\n' ' '`)
		./test_api_cpe_uri --matching $URI " " >matching.out
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI "cpe:/:::::::" > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI "cpe:/:foo" > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI "cpe:/foo" > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi

		OTHER_URIS=(`echo ${CPE_URIS[@]} | tr ' ' '\n' | grep -v $URI | \
		    tr '\n' ' '`)

		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI ${OTHER_URIS[@]} > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI $URI > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
		if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
		./test_api_cpe_uri --matching $URI ${CPE_URIS[@]} > matching.out
		    echo "Cannot match URI \"$URI\"!"
		    ret_val=1;		
		fi
	    else
		ret_val=1
		echo "Parsing failed!"
	    fi
	else
	    ret_val=1
	    echo "Parsing failed!"
	fi
    done
    return $ret_val
}

# Testing.

test_init "test_api_cpe_uri.log"

test_run "test_api_cpe_uri_smoke"  test_api_cpe_uri_smoke
test_run "test_api_cpe_uri_parse"  test_api_cpe_uri_parse
test_run "test_api_cpe_uri_create" test_api_cpe_uri_create
test_run "test_api_cpe_uri_match"  test_api_cpe_uri_match

test_exit