nss: import at 3.0.1 beta 1
[mozilla-nss.git] / security / nss / tests / dbtests / dbtests.sh
blob3db294fd5a9148b5d7cb326a119f608d179098f7
1 #! /bin/sh
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is the Netscape security libraries.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1994-2000
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
24 # Sonja Mirtitsch Sun Microsystems
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
40 ########################################################################
42 # mozilla/security/nss/tests/dbtest/dbtest.sh
44 # Certificate generating and handeling for NSS QA, can be included
45 # multiple times from all.sh and the individual scripts
47 # needs to work on all Unix and Windows platforms
49 # included from (don't expect this to be up to date)
50 # --------------------------------------------------
51 # all.sh
52 # ssl.sh
53 # smime.sh
54 # tools.sh
56 # special strings
57 # ---------------
58 # FIXME ... known problems, search for this string
59 # NOTE .... unexpected behavior
61 # FIXME - Netscape - NSS
62 ########################################################################
64 ############################## dbtest_init ###############################
65 # local shell function to initialize this script
66 ########################################################################
67 dbtest_init()
69 SCRIPTNAME="dbtests.sh"
70 if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for
71 CLEANUP="${SCRIPTNAME}" # cleaning this script will do it
73 if [ -z "${INIT_SOURCED}" ] ; then
74 cd ../common
75 . ./init.sh
77 if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here
78 cd ../cert
79 . ./cert.sh
82 SCRIPTNAME="dbtests.sh"
83 DBTEST_LOG=${HOSTDIR}/dbtest.log #we don't want all the errormessages
84 # in the output.log, otherwise we can't tell what's a real error
85 RONLY_DIR=${HOSTDIR}/ronlydir
86 EMPTY_DIR=${HOSTDIR}/emptydir
88 html_head "CERT and Key DB Tests"
92 ############################## dbtest_cleanup ############################
93 # local shell function to finish this script (no exit since it might be
94 # sourced)
95 ########################################################################
96 dbtest_cleanup()
98 html "</TABLE><BR>"
99 cd ${QADIR}
100 chmod a+rw $RONLY_DIR
101 . common/cleanup.sh
104 Echo()
106 echo
107 echo "---------------------------------------------------------------"
108 echo "| $*"
109 echo "---------------------------------------------------------------"
111 dbtest_main()
113 cd ${HOSTDIR}
116 Echo "test opening the database read/write in a nonexisting directory"
117 ${BINDIR}/certutil -L -X -d ./non_existant_dir
118 ret=$?
119 if [ $ret -ne 255 ]; then
120 html_failed "Certutil succeeded in a nonexisting directory $ret"
121 else
122 html_passed "Certutil didn't work in a nonexisting dir $ret"
124 ${BINDIR}/dbtest -r -d ./non_existant_dir
125 ret=$?
126 if [ $ret -ne 46 ]; then
127 html_failed "Dbtest readonly succeeded in a nonexisting directory $ret"
128 else
129 html_passed "Dbtest readonly didn't work in a nonexisting dir $ret"
132 Echo "test force opening the database in a nonexisting directory"
133 ${BINDIR}/dbtest -f -d ./non_existant_dir
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 html_failed "Dbtest force failed in a nonexisting directory $ret"
137 else
138 html_passed "Dbtest force succeeded in a nonexisting dir $ret"
141 Echo "test opening the database readonly in an empty directory"
142 mkdir $EMPTY_DIR
143 ${BINDIR}/tstclnt -h ${HOST} -d $EMPTY_DIR
144 ret=$?
145 if [ $ret -ne 1 ]; then
146 html_failed "Tstclnt succeded in an empty directory $ret"
147 else
148 html_passed "Tstclnt didn't work in an empty dir $ret"
150 ${BINDIR}/dbtest -r -d $EMPTY_DIR
151 ret=$?
152 if [ $ret -ne 46 ]; then
153 html_failed "Dbtest readonly succeeded in an empty directory $ret"
154 else
155 html_passed "Dbtest readonly didn't work in an empty dir $ret"
157 rm -rf $EMPTY_DIR/* 2>/dev/null
158 ${BINDIR}/dbtest -i -d $EMPTY_DIR
159 ret=$?
160 if [ $ret -ne 0 ]; then
161 html_failed "Dbtest logout after empty DB Init looses key $ret"
162 else
163 html_passed "Dbtest logout after empty DB Init has key"
165 rm -rf $EMPTY_DIR/* 2>/dev/null
166 ${BINDIR}/dbtest -i -p pass -d $EMPTY_DIR
167 ret=$?
168 if [ $ret -ne 0 ]; then
169 html_failed "Dbtest password DB Init looses needlogin state $ret"
170 else
171 html_passed "Dbtest password DB Init maintains needlogin state"
173 rm -rf $EMPTY_DIR/* 2>/dev/null
174 ${BINDIR}/certutil -D -n xxxx -d $EMPTY_DIR #created DB
175 ret=$?
176 if [ $ret -ne 255 ]; then
177 html_failed "Certutil succeeded in deleting a cert in an empty directory $ret"
178 else
179 html_passed "Certutil didn't work in an empty dir $ret"
181 rm -rf $EMPTY_DIR/* 2>/dev/null
182 Echo "test force opening the database readonly in a empty directory"
183 ${BINDIR}/dbtest -r -f -d $EMPTY_DIR
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 html_failed "Dbtest force readonly failed in an empty directory $ret"
187 else
188 html_passed "Dbtest force readonly succeeded in an empty dir $ret"
191 Echo "test opening the database r/w in a readonly directory"
192 mkdir $RONLY_DIR
193 cp -r ${CLIENTDIR}/* $RONLY_DIR
194 chmod -w $RONLY_DIR $RONLY_DIR/*
196 # On Mac OS X 10.1, if we do a "chmod -w" on files in an
197 # NFS-mounted directory, it takes several seconds for the
198 # first open to see the files are readonly, but subsequent
199 # opens immediately see the files are readonly. As a
200 # workaround we open the files once first. (Bug 185074)
201 if [ "${OS_ARCH}" = "Darwin" ]; then
202 cat $RONLY_DIR/* > /dev/null
205 ${BINDIR}/dbtest -d $RONLY_DIR
206 ret=$?
207 if [ $ret -ne 46 ]; then
208 html_failed "Dbtest r/w succeeded in an readonly directory $ret"
209 else
210 html_passed "Dbtest r/w didn't work in an readonly dir $ret"
212 ${BINDIR}/certutil -D -n "TestUser" -d .
213 ret=$?
214 if [ $ret -ne 255 ]; then
215 html_failed "Certutil succeeded in deleting a cert in an readonly directory $ret"
216 else
217 html_passed "Certutil didn't work in an readonly dir $ret"
220 Echo "test opening the database ronly in a readonly directory"
222 ${BINDIR}/dbtest -d $RONLY_DIR -r
223 ret=$?
224 if [ $ret -ne 0 ]; then
225 html_failed "Dbtest readonly failed in a readonly directory $ret"
226 else
227 html_passed "Dbtest readonly succeeded in a readonly dir $ret"
230 Echo "test force opening the database r/w in a readonly directory"
231 ${BINDIR}/dbtest -d $RONLY_DIR -f
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 html_failed "Dbtest force failed in a readonly directory $ret"
235 else
236 html_passed "Dbtest force succeeded in a readonly dir $ret"
239 Echo "ls -l $RONLY_DIR"
240 ls -ld $RONLY_DIR $RONLY_DIR/*
244 ################## main #################################################
246 dbtest_init
247 dbtest_main >$DBTEST_LOG 2>&1
248 dbtest_cleanup