| 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 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_smokescip-shell shell shell-project 0.0.0 test_api_cpe_lang_smoke(). { |
| 16 | ./test_api_cpe_lang --smoke-test |
| 17 | } |
| 18 | |
| 19 | function test_api_cpe_lang_importscip-shell shell shell-project 0.0.0 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_damagedscip-shell shell shell-project 0.0.0 test_api_cpe_lang_import_damaged(). { |
| 24 | ./test_api_cpe_lang --get-all $srcdir/lang-damaged.xml "UTF-8" |
| 25 | [scip-shell system . . `[`. "$?" == "1" ] |
| 26 | } |
| 27 | |
| 28 | function test_api_cpe_lang_import_keyscip-shell shell shell-project 0.0.0 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 | echoscip-shell system . . echo. "" > get-all.out |
| 35 | echoscip-shell system . . echo. $KEY_123 >> get-all.out |
| 36 | echoscip-shell system . . echo. $KEY_456 >> get-all.out |
| 37 | echoscip-shell system . . echo. $KEY_789 >> get-all.out |
| 38 | echoscip-shell system . . echo. $KEY_1011 >> get-all.out |
| 39 | |
| 40 | for K in "$KEY_123" "$KEY_456" "$KEY_789" "$KEY_1011"; do |
| 41 | N=`echoscip-shell system . . echo. $K | awkscip-shell system . . awk. -F':' '{print $1}'` |
| 42 | ./test_api_cpe_lang --get-key $srcdir/lang.xml "UTF-8" $N > get-key.out |
| 43 | if [scip-shell system . . `[`. $? -eq 0 ]; then |
| 44 | if [scip-shell system . . `[`. "`catscip-shell system . . cat. get-key.out`X" != "${K}X" ]; then |
| 45 | echoscip-shell system . . echo. "`catscip-shell system . . cat. get-key.out`X != ${K}X" |
| 46 | return 1 |
| 47 | fi |
| 48 | else |
| 49 | echoscip-shell system . . 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_emptyscip-shell shell shell-project 0.0.0 test_api_cpe_lang_export_empty(). { |
| 57 | local ret_val=0; |
| 58 | |
| 59 | echoscip-shell system . . echo. '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.1.0 |
| 60 | echoscip-shell system . . 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 [scip-shell system . . `[`. $? -eq 0 ] && [scip-shell system . . `[`. -f export.xml.out.1 ]; then |
| 64 | if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then |
| 65 | echoscip-shell system . . echo. "Exported file differs from what is expected!" |
| 66 | ret_val=1 |
| 67 | fi |
| 68 | else |
| 69 | echoscip-shell system . . echo. "Cannot export!" |
| 70 | ret_val=1 |
| 71 | fi |
| 72 | return $ret_val |
| 73 | } |
| 74 | |
| 75 | function test_cpelang_export_new_modelscip-shell shell shell-project 0.0.0 test_cpelang_export_new_model(). { |
| 76 | local ret_val=0; |
| 77 | |
| 78 | echoscip-shell system . . echo. '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.0 |
| 79 | echoscip-shell system . . echo. '<platform-specification xmlns="http://cpe.mitre.org/language/2.0">' >> export.xml.out.0 |
| 80 | echoscip-shell system . . echo. '<platform id="1"/>' >> export.xml.out.0 |
| 81 | echoscip-shell system . . echo. '<platform id="10"/>' >> export.xml.out.0 |
| 82 | echoscip-shell system . . 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 [scip-shell system . . `[`. $? -eq 0 ] && [scip-shell system . . `[`. -f export.xml.out.1 ]; then |
| 86 | if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then |
| 87 | echoscip-shell system . . echo. "Exported file differs from what is expected!" |
| 88 | ret_val=1 |
| 89 | fi |
| 90 | else |
| 91 | echoscip-shell system . . echo. "Cannot export!" |
| 92 | ret_val=1 |
| 93 | fi |
| 94 | return $ret_val |
| 95 | } |
| 96 | |
| 97 | function test_api_cpe_lang_export_encodingscip-shell shell shell-project 0.0.0 test_api_cpe_lang_export_encoding(). { |
| 98 | local ret_val=0; |
| 99 | |
| 100 | echoscip-shell system . . echo. '<?xml version="1.0"?>' > export.xml.out.0 |
| 101 | echoscip-shell system . . 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 [scip-shell system . . `[`. $? -eq 0 ] && [scip-shell system . . `[`. -f export.xml.out.1 ]; then |
| 105 | if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then |
| 106 | echoscip-shell system . . echo. "Exported file differs from what is expected!" |
| 107 | ret_val=1 |
| 108 | fi |
| 109 | else |
| 110 | echoscip-shell system . . echo. "Cannot export!" |
| 111 | ret_val=1 |
| 112 | fi |
| 113 | return $ret_val |
| 114 | } |
| 115 | |
| 116 | function test_api_cpe_lang_export_namespacescip-shell shell shell-project 0.0.0 test_api_cpe_lang_export_namespace(). { |
| 117 | local ret_val=0; |
| 118 | |
| 119 | echoscip-shell system . . echo. '<?xml version="1.0" encoding="UTF-8"?>' > export.xml.out.0 |
| 120 | echoscip-shell system . . 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 [scip-shell system . . `[`. $? -eq 0 ] && [scip-shell system . . `[`. -f export.xml.out.1 ]; then |
| 124 | if ! $XMLDIFF export.xml.out.0 export.xml.out.1; then |
| 125 | echoscip-shell system . . echo. "Exported file differs from what is expected!" |
| 126 | ret_val=1 |
| 127 | fi |
| 128 | else |
| 129 | echoscip-shell system . . echo. "Cannot export!" |
| 130 | ret_val=1 |
| 131 | fi |
| 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_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 |