1#! /bin/sh 2# 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7######################################################################## 8# 9# mozilla/security/nss/tests/multinit/multinit.sh 10# 11# Script to test NSS multinit 12# 13# needs to work on all Unix and Windows platforms 14# 15# special strings 16# --------------- 17# FIXME ... known problems, search for this string 18# NOTE .... unexpected behavior 19# 20######################################################################## 21 22############################## multinit_init ############################## 23# local shell function to initialize this script 24######################################################################## 25multinit_init() 26{ 27 SCRIPTNAME=multinit.sh # sourced - $0 would point to all.sh 28 29 if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for 30 CLEANUP="${SCRIPTNAME}" # cleaning this script will do it 31 fi 32 33 if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then 34 cd ../common 35 . ./init.sh 36 fi 37 if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here 38 cd ../cert 39 . ./cert.sh 40 fi 41 SCRIPTNAME=multinit.sh 42 43 html_head "MULTI Tests" 44 45 grep "SUCCESS: SMIME passed" $CERT_LOG_FILE >/dev/null || { 46 Exit 11 "Fatal - S/MIME of cert.sh needs to pass first" 47 } 48 49 # set up our directories 50 MULTINITDIR=${HOSTDIR}/multinit 51 MULTINITDIR_1=${MULTINITDIR}/dir1 52 MULTINITDIR_2=${MULTINITDIR}/dir2 53 MULTINITDIR_3=${MULTINITDIR}/dir3 54 R_MULINITDIR=../multinit 55 R_MULTINITDIR_1=${R_MULTINITDIR}/dir1 56 R_MULTINITDIR_2=${R_MULTINITDIR}/dir2 57 R_MULTINITDIR_3=${R_MULTINITDIR}/dir3 58 # first create them all 59 mkdir -p ${MULTINITDIR} 60 mkdir -p ${MULTINITDIR_1} 61 mkdir -p ${MULTINITDIR_2} 62 mkdir -p ${MULTINITDIR_3} 63 # now copy them fro alice, bob, and dave 64 cd ${MULTINITDIR} 65 cp ${P_R_ALICEDIR}/* ${MULTINITDIR_1}/ 66 cp ${P_R_BOBDIR}/* ${MULTINITDIR_2}/ 67 cp ${P_R_DAVEDIR}/* ${MULTINITDIR_3}/ 68 # finally delete the RootCerts module to keep the certificate noice in the 69 # summary lines down 70 echo | modutil -delete RootCerts -dbdir ${MULTINITDIR_1} 71 echo | modutil -delete RootCerts -dbdir ${MULTINITDIR_2} 72 echo | modutil -delete RootCerts -dbdir ${MULTINITDIR_3} 73 MULTINIT_TESTS=${QADIR}/multinit/multinit.txt 74} 75 76 77############################## multinit_main ############################## 78# local shell function to test basic signed and enveloped messages 79# from 1 --> 2" 80######################################################################## 81multinit_main() 82{ 83 html_head "Multi init interface testing" 84 exec < ${MULTINIT_TESTS} 85 while read order commands shutdown_type dirs readonly testname 86 do 87 if [ "$order" != "#" ]; then 88 read tag expected_result 89 90 # handle the case where we expect different results based on 91 # the database type. 92 if [ "$tag" != "all" ]; then 93 read tag2 expected_result2 94 if [ "$NSS_DEFAULT_DB_TYPE" == "$tag2" ]; then 95 expected_result=$expected_result2 96 fi 97 fi 98 99 # convert shutdown type to option flags 100 shutdown_command=""; 101 if [ "$shutdown_type" == "old" ]; then 102 shutdown_command="--oldStype" 103 fi 104 105 # convert read only to option flags 106 ro_command=""; 107 case $readonly in 108 all) ro_command="--main_readonly --lib1_readonly --lib2_readonly";; 109 libs) ro_command="--lib1_readonly --lib2_readonly";; 110 main) ro_command="--main_readonly";; 111 lib1) ro_command="--lib1_readonly";; 112 lib2) ro_command="--lib2_readonly";; 113 none) ;; 114 *) ;; 115 esac 116 117 # convert commands to option flags 118 main_command=`echo $commands | sed -e 's;,.*$;;'` 119 lib1_command=`echo $commands | sed -e 's;,.*,;+&+;' -e 's;^.*+,;;' -e 's;,+.*$;;'` 120 lib2_command=`echo $commands | sed -e 's;^.*,;;'` 121 122 # convert db's to option flags 123 main_db=`echo $dirs | sed -e 's;,.*$;;'` 124 lib1_db=`echo $dirs | sed -e 's;,.*,;+&+;' -e 's;^.*+,;;' -e 's;,+.*$;;'` 125 lib2_db=`echo $dirs | sed -e 's;^.*,;;'` 126 127 # show us the command we are executing 128 echo ${PROFILETOOL} ${BINDIR}/multinit --order $order --main_command $main_command --lib1_command $lib1_command --lib2_command $lib2_command $shutdown_command --main_db $main_db --lib1_db $lib1_db --lib2_db $lib2_db $ro_command --main_token_name "Main" --lib1_token_name "Lib1" --lib2_token_name "Lib2" --verbose --summary 129 130 # execute the command an collect the result. Most of the user 131 # visible output goes to stderr, so it's not captured by the pipe 132 actual_result=`${PROFILETOOL} ${BINDIR}/multinit --order $order --main_command $main_command --lib1_command $lib1_command --lib2_command $lib2_command $shutdown_command --main_db $main_db --lib1_db $lib1_db --lib2_db $lib2_db $ro_command --main_token_name "Main" --lib1_token_name "Lib1" --lib2_token_name "Lib2" --verbose --summary | grep "^result=" | sed -e 's;^result=;;'` 133 134 # show what we got and what we expected for diagnostic purposes 135 echo "actual = |$actual_result|" 136 echo "expected = |$expected_result|" 137 test "$actual_result" == "$expected_result" 138 html_msg $? 0 "$testname" 139 fi 140 done 141} 142 143############################## multinit_cleanup ########################### 144# local shell function to finish this script (no exit since it might be 145# sourced) 146######################################################################## 147multinit_cleanup() 148{ 149 html "</TABLE><BR>" 150 cd ${QADIR} 151 . common/cleanup.sh 152} 153 154################## main ################################################# 155 156multinit_init 157multinit_main 158multinit_cleanup 159