Debian Codegraph @

tests/API/CPE/lang/test_api_cpe_lang.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5 #
6 # OpenScap CPE Lang Module Test Suite.
7 #
8 # Authors:
9 # Ondrej Moris <[email protected]>
10
11 . $builddir/tests/test_common.sh
12
13 # Test cases.
14
15 function test_api_cpe_lang_smoke {
16 ./test_api_cpe_lang --smoke-test
17 }
18
19 function test_api_cpe_lang_import {
20 ./test_api_cpe_lang --get-all $srcdir/lang.xml "UTF-8"
21 }
22
23 function test_api_cpe_lang_import_damaged {
24 ./test_api_cpe_lang --get-all $srcdir/lang-damaged.xml "UTF-8"
25 [ "$?" == "1" ]
26 }
27
28 function test_api_cpe_lang_import_key {
29 KEY_123="123::Microsoft Windows XP with Adobe Reader.en,:(AND(cpe:/o:microsoft:windows_xp)(cpe:/a:adobe:reader))"
30 KEY_456="456::Sun Solaris 5.8 or 5.9 or 5.10.,ľščťžýýáíéúôä.,:(OR(cpe:/o:sun:solaris:5.8)(cpe:/o:sun:solaris:5.9)(cpe:/o:sun:solaris:5.10))"
31 KEY_789="789:Foolish Remark:Microsoft Windows XP with Office 2003 or 2007.,:(AND(cpe:/o:microsoft:windows_xp)(OR(cpe:/a:microsoft:office:2003)(cpe:/a:microsoft:office:2007)))"
32 KEY_1011="1011:Foolish Remark:NOT Microsoft Windows XP and Sun Solaris 5.8.,:(!AND(cpe:/o:microsoft:windows_xp)(cpe:/o:sun:solaris:5.8))"
33
34 echo "" > get-all.out
35 echo $KEY_123 >> get-all.out
36 echo $KEY_456 >> get-all.out
37 echo $KEY_789 >> get-all.out
38 echo $KEY_1011 >> get-all.out
39
40 for K in "$KEY_123" "$KEY_456" "$KEY_789" "$KEY_1011"; do
41 N=`echo $K | awk -F':' '{print $1}'`
42 ./test_api_cpe_lang --get-key $srcdir/lang.xml "UTF-8" $N > get-key.out
43 if [ $? -eq 0 ]; then
44 if [ "`cat get-key.out`X" != "${K}X" ]; then
45 echo "`cat get-key.out`X != ${K}X"
46 return 1
47 fi
48 else
49 echo "Cannot get key $K from lang.xml!"
50 return 1
51 fi
52 done
53 return 0
54 }
55
56 function test_api_cpe_lang_export_empty {
57 local ret_val=0;
58
59 echo '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.1.0
60 echo '<Foo:platform-specification xmlns:Foo="Bar"/>' >> export.xml.out.0
61
62 ./test_api_cpe_lang --set-new export.xml.out.1 "UTF-8" "Foo" "Bar"
63 if [ $? -eq 0 ] && [ -f export.xml.out.1 ]; then
64 if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then
65 echo "Exported file differs from what is expected!"
66 ret_val=1
67 fi
68 else
69 echo "Cannot export!"
70 ret_val=1
71 fi
72 return $ret_val
73 }
74
75 function test_cpelang_export_new_model {
76 local ret_val=0;
77
78 echo '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.0
79 echo '<platform-specification xmlns="http://cpe.mitre.org/language/2.0">' >> export.xml.out.0
80 echo '<platform id="1"/>' >> export.xml.out.0
81 echo '<platform id="10"/>' >> export.xml.out.0
82 echo '</platform-specification>' >> export.xml.out.0
83
84 ./test_api_cpe_lang --set-new export.xml.out.1 "UTF-8" "Foo" "Bar" 1 10
85 if [ $? -eq 0 ] && [ -f export.xml.out.1 ]; then
86 if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then
87 echo "Exported file differs from what is expected!"
88 ret_val=1
89 fi
90 else
91 echo "Cannot export!"
92 ret_val=1
93 fi
94 return $ret_val
95 }
96
97 function test_api_cpe_lang_export_encoding {
98 local ret_val=0;
99
100 echo '<?xml version="1.0"?>' > export.xml.out.0
101 echo '<Foo:platform-specification xmlns:Foo="Bar"/>' >> export.xml.out.0
102
103 ./test_api_cpe_lang --set-new export.xml.out.1 "UnknownEncoding" "Foo" "Bar"
104 if [ $? -eq 0 ] && [ -f export.xml.out.1 ]; then
105 if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then
106 echo "Exported file differs from what is expected!"
107 ret_val=1
108 fi
109 else
110 echo "Cannot export!"
111 ret_val=1
112 fi
113 return $ret_val
114 }
115
116 function test_api_cpe_lang_export_namespace {
117 local ret_val=0;
118
119 echo '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.0
120 echo '<foo:platform-specification xmlns:foo="Bar" xmlns:bla="Bla"/>' >> export.xml.out.0
121
122 ./test_api_cpe_lang --export-all export.xml.out.0 "UTF-8" export.xml.out.1 "UTF-8"
123 if [ $? -eq 0 ] && [ -f export.xml.out.1 ]; then
124 if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then
125 echo "Exported file differs from what is expected!"
126 ret_val=1
127 fi
128 else
129 echo "Cannot export!"
130 ret_val=1
131 fi
132 return $ret_val
133 }
134
135 # Testing.
136
137 test_init
138
139 if [ -z ${CUSTOM_OSCAP+x} ] ; then
140 test_run "test_api_cpe_lang_smoke" test_api_cpe_lang_smoke
141 test_run "test_api_cpe_lang_import" test_api_cpe_lang_import
142 test_run "test_api_cpe_lang_import_damaged" test_api_cpe_lang_import_damaged
143 test_run "test_api_cpe_lang_import_key" test_api_cpe_lang_import_key
144 # test_run "test_api_cpe_lang_export_empty" test_api_cpe_lang_export_empty
145 # test_run "test_api_cpe_lang_export_ecoding" test_api_cpe_lang_export_encoding
146 # test_run "test_api_cpe_lang_export_namespace" test_api_cpe_lang_export_namespace
147 fi
148
149 test_exit