Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / tests / dbtests / dbtests.sh
blob1ad4854678c5ecdb7867f97d8e0d224481830a0d
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 certutil -L -X -d ./non_existant_dir
118 ret=$?
119 if [ $ret -ne 255 ]; then
120 html_failed "<TR><TD> Certutil succeeded in a nonexisting directory $ret"
121 else
122 html_passed "<TR><TD> Certutil didn't work in a nonexisting dir $ret"
124 dbtest -r -d ./non_existant_dir
125 ret=$?
126 if [ $ret -ne 46 ]; then
127 html_failed "<TR><TD> Dbtest readonly succeeded in a nonexisting directory $ret"
128 else
129 html_passed "<TR><TD> Dbtest readonly didn't work in a nonexisting dir $ret"
132 Echo "test force opening the database in a nonexisting directory"
133 dbtest -f -d ./non_existant_dir
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 html_failed "<TR><TD> Dbtest force failed in a nonexisting directory $ret"
137 else
138 html_passed "<TR><TD> Dbtest force succeeded in a nonexisting dir $ret"
141 Echo "test opening the database readonly in an empty directory"
142 mkdir $EMPTY_DIR
143 tstclnt -h ${HOST} -d $EMPTY_DIR
144 ret=$?
145 if [ $ret -ne 1 ]; then
146 html_failed "<TR><TD> Tstclnt succeded in an empty directory $ret"
147 else
148 html_passed "<TR><TD> Tstclnt didn't work in an empty dir $ret"
150 dbtest -r -d $EMPTY_DIR
151 ret=$?
152 if [ $ret -ne 46 ]; then
153 html_failed "<TR><TD> Dbtest readonly succeeded in an empty directory $ret"
154 else
155 html_passed "<TR><TD> Dbtest readonly didn't work in an empty dir $ret"
157 rm -rf $EMPTY_DIR/* 2>/dev/null
158 certutil -D -n xxxx -d $EMPTY_DIR #created DB
159 ret=$?
160 if [ $ret -ne 255 ]; then
161 html_failed "<TR><TD> Certutil succeeded in deleting a cert in an empty directory $ret"
162 else
163 html_passed "<TR><TD> Certutil didn't work in an empty dir $ret"
165 rm -rf $EMPTY_DIR/* 2>/dev/null
166 Echo "test force opening the database readonly in a empty directory"
167 dbtest -r -f -d $EMPTY_DIR
168 ret=$?
169 if [ $ret -ne 0 ]; then
170 html_failed "<TR><TD> Dbtest force readonly failed in an empty directory $ret"
171 else
172 html_passed "<TR><TD> Dbtest force readonly succeeded in an empty dir $ret"
175 Echo "test opening the database r/w in a readonly directory"
176 mkdir $RONLY_DIR
177 cp -r ${CLIENTDIR}/* $RONLY_DIR
178 chmod -w $RONLY_DIR $RONLY_DIR/*
180 # On Mac OS X 10.1, if we do a "chmod -w" on files in an
181 # NFS-mounted directory, it takes several seconds for the
182 # first open to see the files are readonly, but subsequent
183 # opens immediately see the files are readonly. As a
184 # workaround we open the files once first. (Bug 185074)
185 if [ "${OS_ARCH}" = "Darwin" ]; then
186 cat $RONLY_DIR/* > /dev/null
189 dbtest -d $RONLY_DIR
190 ret=$?
191 if [ $ret -ne 46 ]; then
192 html_failed "<TR><TD> Dbtest r/w succeeded in an readonly directory $ret"
193 else
194 html_passed "<TR><TD> Dbtest r/w didn't work in an readonly dir $ret"
196 certutil -D -n "TestUser" -d .
197 ret=$?
198 if [ $ret -ne 255 ]; then
199 html_failed "<TR><TD> Certutil succeeded in deleting a cert in an readonly directory $ret"
200 else
201 html_passed "<TR><TD> Certutil didn't work in an readonly dir $ret"
204 Echo "test opening the database ronly in a readonly directory"
206 dbtest -d $RONLY_DIR -r
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 html_failed "<TR><TD> Dbtest readonly failed in a readonly directory $ret"
210 else
211 html_passed "<TR><TD> Dbtest readonly succeeded in a readonly dir $ret"
214 Echo "test force opening the database r/w in a readonly directory"
215 dbtest -d $RONLY_DIR -f
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 html_failed "<TR><TD> Dbtest force failed in a readonly directory $ret"
219 else
220 html_passed "<TR><TD> Dbtest force succeeded in a readonly dir $ret"
223 Echo "ls -l $RONLY_DIR"
224 ls -ld $RONLY_DIR $RONLY_DIR/*
228 ################## main #################################################
230 dbtest_init
231 dbtest_main >$DBTEST_LOG 2>&1
232 dbtest_cleanup