Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #! /bin/bash |
michael@0 | 2 | # |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | ######################################################################## |
michael@0 | 8 | # |
michael@0 | 9 | # mozilla/security/nss/tests/dbtest/dbtest.sh |
michael@0 | 10 | # |
michael@0 | 11 | # Certificate generating and handeling for NSS QA, can be included |
michael@0 | 12 | # multiple times from all.sh and the individual scripts |
michael@0 | 13 | # |
michael@0 | 14 | # needs to work on all Unix and Windows platforms |
michael@0 | 15 | # |
michael@0 | 16 | # included from (don't expect this to be up to date) |
michael@0 | 17 | # -------------------------------------------------- |
michael@0 | 18 | # all.sh |
michael@0 | 19 | # ssl.sh |
michael@0 | 20 | # smime.sh |
michael@0 | 21 | # tools.sh |
michael@0 | 22 | # |
michael@0 | 23 | # special strings |
michael@0 | 24 | # --------------- |
michael@0 | 25 | # FIXME ... known problems, search for this string |
michael@0 | 26 | # NOTE .... unexpected behavior |
michael@0 | 27 | # |
michael@0 | 28 | # FIXME - Netscape - NSS |
michael@0 | 29 | ######################################################################## |
michael@0 | 30 | |
michael@0 | 31 | ############################## dbtest_init ############################### |
michael@0 | 32 | # local shell function to initialize this script |
michael@0 | 33 | ######################################################################## |
michael@0 | 34 | dbtest_init() |
michael@0 | 35 | { |
michael@0 | 36 | SCRIPTNAME="dbtests.sh" |
michael@0 | 37 | if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for |
michael@0 | 38 | CLEANUP="${SCRIPTNAME}" # cleaning this script will do it |
michael@0 | 39 | fi |
michael@0 | 40 | if [ -z "${INIT_SOURCED}" ] ; then |
michael@0 | 41 | cd ../common |
michael@0 | 42 | . ./init.sh |
michael@0 | 43 | fi |
michael@0 | 44 | if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here |
michael@0 | 45 | cd ../cert |
michael@0 | 46 | . ./cert.sh |
michael@0 | 47 | fi |
michael@0 | 48 | |
michael@0 | 49 | SCRIPTNAME="dbtests.sh" |
michael@0 | 50 | RONLY_DIR=${HOSTDIR}/ronlydir |
michael@0 | 51 | EMPTY_DIR=${HOSTDIR}/emptydir |
michael@0 | 52 | CONFLICT_DIR=${HOSTDIR}/conflictdir |
michael@0 | 53 | |
michael@0 | 54 | html_head "CERT and Key DB Tests" |
michael@0 | 55 | |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | ############################## dbtest_cleanup ############################ |
michael@0 | 59 | # local shell function to finish this script (no exit since it might be |
michael@0 | 60 | # sourced) |
michael@0 | 61 | ######################################################################## |
michael@0 | 62 | dbtest_cleanup() |
michael@0 | 63 | { |
michael@0 | 64 | html "</TABLE><BR>" |
michael@0 | 65 | cd ${QADIR} |
michael@0 | 66 | chmod a+rw $RONLY_DIR |
michael@0 | 67 | . common/cleanup.sh |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | Echo() |
michael@0 | 71 | { |
michael@0 | 72 | echo |
michael@0 | 73 | echo "---------------------------------------------------------------" |
michael@0 | 74 | echo "| $*" |
michael@0 | 75 | echo "---------------------------------------------------------------" |
michael@0 | 76 | } |
michael@0 | 77 | dbtest_main() |
michael@0 | 78 | { |
michael@0 | 79 | cd ${HOSTDIR} |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | Echo "test opening the database read/write in a nonexisting directory" |
michael@0 | 83 | ${BINDIR}/certutil -L -X -d ./non_existent_dir |
michael@0 | 84 | ret=$? |
michael@0 | 85 | if [ $ret -ne 255 ]; then |
michael@0 | 86 | html_failed "Certutil succeeded in a nonexisting directory $ret" |
michael@0 | 87 | else |
michael@0 | 88 | html_passed "Certutil didn't work in a nonexisting dir $ret" |
michael@0 | 89 | fi |
michael@0 | 90 | ${BINDIR}/dbtest -r -d ./non_existent_dir |
michael@0 | 91 | ret=$? |
michael@0 | 92 | if [ $ret -ne 46 ]; then |
michael@0 | 93 | html_failed "Dbtest readonly succeeded in a nonexisting directory $ret" |
michael@0 | 94 | else |
michael@0 | 95 | html_passed "Dbtest readonly didn't work in a nonexisting dir $ret" |
michael@0 | 96 | fi |
michael@0 | 97 | |
michael@0 | 98 | Echo "test force opening the database in a nonexisting directory" |
michael@0 | 99 | ${BINDIR}/dbtest -f -d ./non_existent_dir |
michael@0 | 100 | ret=$? |
michael@0 | 101 | if [ $ret -ne 0 ]; then |
michael@0 | 102 | html_failed "Dbtest force failed in a nonexisting directory $ret" |
michael@0 | 103 | else |
michael@0 | 104 | html_passed "Dbtest force succeeded in a nonexisting dir $ret" |
michael@0 | 105 | fi |
michael@0 | 106 | |
michael@0 | 107 | Echo "test opening the database readonly in an empty directory" |
michael@0 | 108 | mkdir $EMPTY_DIR |
michael@0 | 109 | ${BINDIR}/tstclnt -h ${HOST} -d $EMPTY_DIR |
michael@0 | 110 | ret=$? |
michael@0 | 111 | if [ $ret -ne 1 ]; then |
michael@0 | 112 | html_failed "Tstclnt succeded in an empty directory $ret" |
michael@0 | 113 | else |
michael@0 | 114 | html_passed "Tstclnt didn't work in an empty dir $ret" |
michael@0 | 115 | fi |
michael@0 | 116 | ${BINDIR}/dbtest -r -d $EMPTY_DIR |
michael@0 | 117 | ret=$? |
michael@0 | 118 | if [ $ret -ne 46 ]; then |
michael@0 | 119 | html_failed "Dbtest readonly succeeded in an empty directory $ret" |
michael@0 | 120 | else |
michael@0 | 121 | html_passed "Dbtest readonly didn't work in an empty dir $ret" |
michael@0 | 122 | fi |
michael@0 | 123 | rm -rf $EMPTY_DIR/* 2>/dev/null |
michael@0 | 124 | ${BINDIR}/dbtest -i -d $EMPTY_DIR |
michael@0 | 125 | ret=$? |
michael@0 | 126 | if [ $ret -ne 0 ]; then |
michael@0 | 127 | html_failed "Dbtest logout after empty DB Init loses key $ret" |
michael@0 | 128 | else |
michael@0 | 129 | html_passed "Dbtest logout after empty DB Init has key" |
michael@0 | 130 | fi |
michael@0 | 131 | rm -rf $EMPTY_DIR/* 2>/dev/null |
michael@0 | 132 | ${BINDIR}/dbtest -i -p pass -d $EMPTY_DIR |
michael@0 | 133 | ret=$? |
michael@0 | 134 | if [ $ret -ne 0 ]; then |
michael@0 | 135 | html_failed "Dbtest password DB Init loses needlogin state $ret" |
michael@0 | 136 | else |
michael@0 | 137 | html_passed "Dbtest password DB Init maintains needlogin state" |
michael@0 | 138 | fi |
michael@0 | 139 | rm -rf $EMPTY_DIR/* 2>/dev/null |
michael@0 | 140 | ${BINDIR}/certutil -D -n xxxx -d $EMPTY_DIR #created DB |
michael@0 | 141 | ret=$? |
michael@0 | 142 | if [ $ret -ne 255 ]; then |
michael@0 | 143 | html_failed "Certutil succeeded in deleting a cert in an empty directory $ret" |
michael@0 | 144 | else |
michael@0 | 145 | html_passed "Certutil didn't work in an empty dir $ret" |
michael@0 | 146 | fi |
michael@0 | 147 | rm -rf $EMPTY_DIR/* 2>/dev/null |
michael@0 | 148 | Echo "test force opening the database readonly in a empty directory" |
michael@0 | 149 | ${BINDIR}/dbtest -r -f -d $EMPTY_DIR |
michael@0 | 150 | ret=$? |
michael@0 | 151 | if [ $ret -ne 0 ]; then |
michael@0 | 152 | html_failed "Dbtest force readonly failed in an empty directory $ret" |
michael@0 | 153 | else |
michael@0 | 154 | html_passed "Dbtest force readonly succeeded in an empty dir $ret" |
michael@0 | 155 | fi |
michael@0 | 156 | |
michael@0 | 157 | Echo "test opening the database r/w in a readonly directory" |
michael@0 | 158 | mkdir $RONLY_DIR |
michael@0 | 159 | cp -r ${CLIENTDIR}/* $RONLY_DIR |
michael@0 | 160 | chmod -w $RONLY_DIR $RONLY_DIR/* |
michael@0 | 161 | |
michael@0 | 162 | # On Mac OS X 10.1, if we do a "chmod -w" on files in an |
michael@0 | 163 | # NFS-mounted directory, it takes several seconds for the |
michael@0 | 164 | # first open to see the files are readonly, but subsequent |
michael@0 | 165 | # opens immediately see the files are readonly. As a |
michael@0 | 166 | # workaround we open the files once first. (Bug 185074) |
michael@0 | 167 | if [ "${OS_ARCH}" = "Darwin" ]; then |
michael@0 | 168 | cat $RONLY_DIR/* > /dev/null |
michael@0 | 169 | fi |
michael@0 | 170 | |
michael@0 | 171 | ${BINDIR}/dbtest -d $RONLY_DIR |
michael@0 | 172 | ret=$? |
michael@0 | 173 | if [ $ret -ne 46 ]; then |
michael@0 | 174 | html_failed "Dbtest r/w succeeded in an readonly directory $ret" |
michael@0 | 175 | else |
michael@0 | 176 | html_passed "Dbtest r/w didn't work in an readonly dir $ret" |
michael@0 | 177 | fi |
michael@0 | 178 | ${BINDIR}/certutil -D -n "TestUser" -d . |
michael@0 | 179 | ret=$? |
michael@0 | 180 | if [ $ret -ne 255 ]; then |
michael@0 | 181 | html_failed "Certutil succeeded in deleting a cert in an readonly directory $ret" |
michael@0 | 182 | else |
michael@0 | 183 | html_passed "Certutil didn't work in an readonly dir $ret" |
michael@0 | 184 | fi |
michael@0 | 185 | |
michael@0 | 186 | Echo "test opening the database ronly in a readonly directory" |
michael@0 | 187 | |
michael@0 | 188 | ${BINDIR}/dbtest -d $RONLY_DIR -r |
michael@0 | 189 | ret=$? |
michael@0 | 190 | if [ $ret -ne 0 ]; then |
michael@0 | 191 | html_failed "Dbtest readonly failed in a readonly directory $ret" |
michael@0 | 192 | else |
michael@0 | 193 | html_passed "Dbtest readonly succeeded in a readonly dir $ret" |
michael@0 | 194 | fi |
michael@0 | 195 | |
michael@0 | 196 | Echo "test force opening the database r/w in a readonly directory" |
michael@0 | 197 | ${BINDIR}/dbtest -d $RONLY_DIR -f |
michael@0 | 198 | ret=$? |
michael@0 | 199 | if [ $ret -ne 0 ]; then |
michael@0 | 200 | html_failed "Dbtest force failed in a readonly directory $ret" |
michael@0 | 201 | else |
michael@0 | 202 | html_passed "Dbtest force succeeded in a readonly dir $ret" |
michael@0 | 203 | fi |
michael@0 | 204 | |
michael@0 | 205 | Echo "ls -l $RONLY_DIR" |
michael@0 | 206 | ls -ld $RONLY_DIR $RONLY_DIR/* |
michael@0 | 207 | |
michael@0 | 208 | mkdir ${CONFLICT_DIR} |
michael@0 | 209 | Echo "test creating a new cert with a conflicting nickname" |
michael@0 | 210 | cd ${CONFLICT_DIR} |
michael@0 | 211 | pwd |
michael@0 | 212 | ${BINDIR}/certutil -N -d ${CONFLICT_DIR} -f ${R_PWFILE} |
michael@0 | 213 | ret=$? |
michael@0 | 214 | if [ $ret -ne 0 ]; then |
michael@0 | 215 | html_failed "Nicknane conflict test failed, couldn't create database $ret" |
michael@0 | 216 | else |
michael@0 | 217 | ${BINDIR}/certutil -A -n alice -t ,, -i ${R_ALICEDIR}/Alice.cert -d ${CONFLICT_DIR} |
michael@0 | 218 | ret=$? |
michael@0 | 219 | if [ $ret -ne 0 ]; then |
michael@0 | 220 | html_failed "Nicknane conflict test failed, couldn't import alice cert $ret" |
michael@0 | 221 | else |
michael@0 | 222 | ${BINDIR}/certutil -A -n alice -t ,, -i ${R_BOBDIR}/Bob.cert -d ${CONFLICT_DIR} |
michael@0 | 223 | ret=$? |
michael@0 | 224 | if [ $ret -eq 0 ]; then |
michael@0 | 225 | html_failed "Nicknane conflict test failed, could import conflict nickname $ret" |
michael@0 | 226 | else |
michael@0 | 227 | html_passed "Nicknane conflict test, could not import conflict nickname $ret" |
michael@0 | 228 | fi |
michael@0 | 229 | fi |
michael@0 | 230 | fi |
michael@0 | 231 | |
michael@0 | 232 | Echo "test importing an old cert to a conflicting nickname" |
michael@0 | 233 | # first, import the certificate |
michael@0 | 234 | ${BINDIR}/certutil -A -n bob -t ,, -i ${R_BOBDIR}/Bob.cert -d ${CONFLICT_DIR} |
michael@0 | 235 | # now import with a different nickname |
michael@0 | 236 | ${BINDIR}/certutil -A -n alice -t ,, -i ${R_BOBDIR}/Bob.cert -d ${CONFLICT_DIR} |
michael@0 | 237 | # the old one should still be there... |
michael@0 | 238 | ${BINDIR}/certutil -L -n bob -d ${CONFLICT_DIR} |
michael@0 | 239 | ret=$? |
michael@0 | 240 | if [ $ret -ne 0 ]; then |
michael@0 | 241 | html_failed "Nicknane conflict test-setting nickname conflict incorrectly worked" |
michael@0 | 242 | else |
michael@0 | 243 | html_passed "Nicknane conflict test-setting nickname conflict was correctly rejected" |
michael@0 | 244 | fi |
michael@0 | 245 | |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | ################## main ################################################# |
michael@0 | 249 | |
michael@0 | 250 | dbtest_init |
michael@0 | 251 | dbtest_main 2>&1 |
michael@0 | 252 | dbtest_cleanup |