Debian Codegraph @

tests/API/CPE/name/test_api_cpe_uri.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5 #
6 # OpenScap CPE URI Module Test Suite.
7 #
8 # Authors:
9 # Ondrej Moris <[email protected]>
10
11 . $builddir/tests/test_common.sh
12
13 CPE_URIS=(`grepscip-shell system . . grep. "cpe:" $srcdir/dict.xml | \
14 xsed 's/^.*cpe:/cpe:/g' | xsed 's/".*$//g' | trscip-shell system . . tr. '\n' ' '`)
15
16 # Test cases.
17
18 function test_api_cpe_uri_smokescip-shell shell shell-project 0.0.0 test_api_cpe_uri_smoke(). {
19 ./test_api_cpe_uri --smoke-test
20 }
21
22 function test_api_cpe_uri_parsescip-shell shell shell-project 0.0.0 test_api_cpe_uri_parse(). {
23 require "grep" || return 255
24 local ret_val=0
25 for URI in ${CPE_URIS[@]}; do
26 ./test_api_cpe_uri --parsing $URI parsing.out >/dev/nullscip-shell filesystem . . `/dev/null`.
27 if [scip-shell system . . `[`. $? -eq 0 ]; then
28 if [scip-shell system . . `[`. ! "`catscip-shell system . . cat. parsing.out`X" == "${URI}X" ]; then
29 echoscip-shell system . . echo. "`catscip-shell system . . cat. parsing.out`X != ${URI}X"
30 ret_val=1
31 fi
32 else
33 echoscip-shell system . . echo. "Parsing failed!"
34 ret_val=1
35 fi
36 done
37 return $ret_val
38 }
39
40 function test_api_cpe_uri_createscip-shell shell shell-project 0.0.0 test_api_cpe_uri_create(). {
41 require "grep" || return 255
42 local ret_val=0
43 for URI in ${CPE_URIS[@]}; do
44 ./test_api_cpe_uri --parsing $URI parsing.out > parsing.out.1
45 if [scip-shell system . . `[`. $? -eq 0 ]; then
46 if [scip-shell system . . `[`. "`catscip-shell system . . cat. parsing.out`X" == "${URI}X" ]; then
47 xsed 's/^\s*//g' parsing.out.1 > parsing.out.sed-tmp ; mvscip-shell system . . mv. parsing.out.sed-tmp parsing.out.1
48 xsed 's/(null)//g' parsing.out.1 > parsing.out.sed-tmp ; mvscip-shell system . . mv. parsing.out.sed-tmp parsing.out.1
49
50 case $(unamescip-shell system . . uname.) in
51 FreeBSD)
52 catscip-shell system . . cat. parsing.out.1 | gxargs -d '\n' ./test_api_cpe_uri --creation > creation.out
53 ;;
54 *)
55 catscip-shell system . . cat. parsing.out.1 | xargsscip-shell system . . xargs. -d '\n' ./test_api_cpe_uri --creation > creation.out
56 ;;
57 esac
58
59 if [scip-shell system . . `[`. ! $? -eq 0 ] || [scip-shell system . . `[`. "${URI}X" != "`catscip-shell system . . cat. creation.out`X" ]; then
60 echoscip-shell system . . echo. "${URI}X != `catscip-shell system . . cat. creation.out`X"
61 ret_val=1;
62 fi
63 else
64 echoscip-shell system . . echo. "`catscip-shell system . . cat. parsing.out`X != ${URI}X"
65 ret_val=1
66 fi
67 else
68 echoscip-shell system . . echo. "Parsing failed!"
69 ret_val=1
70 fi
71 done
72 return $ret_val
73 }
74
75 function test_api_cpe_uri_matchscip-shell shell shell-project 0.0.0 test_api_cpe_uri_match(). {
76 require "grep" || return 255
77 local ret_val=0
78 for URI in ${CPE_URIS[@]}; do
79 ./test_api_cpe_uri --parsing $URI parsing.out
80 if [scip-shell system . . `[`. $? -eq 0 ]; then
81 if [scip-shell system . . `[`. "`catscip-shell system . . cat. parsing.out`X" == "${URI}X" ]; then
82 CPE=(`catscip-shell system . . cat. parsing.out | xsed 's/(null)//g' | \
83 xsed 's/^\s*//g' | trscip-shell system . . tr. '\n' ' '`)
84 ./test_api_cpe_uri --matching $URI " " >matching.out
85 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
86 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
87 ret_val=1;
88 fi
89 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
90 ./test_api_cpe_uri --matching $URI "cpe:/:::::::" > matching.out
91 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
92 ret_val=1;
93 fi
94 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
95 ./test_api_cpe_uri --matching $URI "cpe:/:foo" > matching.out
96 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
97 ret_val=1;
98 fi
99 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
100 ./test_api_cpe_uri --matching $URI "cpe:/foo" > matching.out
101 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
102 ret_val=1;
103 fi
104
105 OTHER_URIS=(`echoscip-shell system . . echo. ${CPE_URIS[@]} | trscip-shell system . . tr. ' ' '\n' | grepscip-shell system . . grep. -v $URI | \
106 tr '\n' ' '`)
107
108 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
109 ./test_api_cpe_uri --matching $URI ${OTHER_URIS[@]} > matching.out
110 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
111 ret_val=1;
112 fi
113 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
114 ./test_api_cpe_uri --matching $URI $URI > matching.out
115 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
116 ret_val=1;
117 fi
118 if [scip-shell system . . `[`. ! $? -eq 0 ] || ! grepscip-shell system . . grep. "Mismatch" matching.out > /dev/nullscip-shell filesystem . . `/dev/null`.; then
119 ./test_api_cpe_uri --matching $URI ${CPE_URIS[@]} > matching.out
120 echoscip-shell system . . echo. "Cannot match URI \"$URI\"!"
121 ret_val=1;
122 fi
123 else
124 ret_val=1
125 echoscip-shell system . . echo. "Parsing failed!"
126 fi
127 else
128 ret_val=1
129 echoscip-shell system . . echo. "Parsing failed!"
130 fi
131 done
132 return $ret_val
133 }
134
135 # Testing.
136
137 test_init
138
139 if [scip-shell system . . `[`. -z ${CUSTOM_OSCAP+x} ] ; then
140 test_run "test_api_cpe_uri_smoke" test_api_cpe_uri_smoke
141 test_run "test_api_cpe_uri_parse" test_api_cpe_uri_parse
142 test_run "test_api_cpe_uri_create" test_api_cpe_uri_create
143 test_run "test_api_cpe_uri_match" test_api_cpe_uri_match
144 fi
145
146 test_exit