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
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.
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 # --------------------------------------------------
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 ########################################################################
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
77 if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here
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
95 ########################################################################
100 chmod a
+rw
$RONLY_DIR
107 echo "---------------------------------------------------------------"
109 echo "---------------------------------------------------------------"
116 Echo
"test opening the database read/write in a nonexisting directory"
117 ${BINDIR}/certutil
-L -X -d .
/non_existant_dir
119 if [ $ret -ne 255 ]; then
120 html_failed
"Certutil succeeded in a nonexisting directory $ret"
122 html_passed
"Certutil didn't work in a nonexisting dir $ret"
124 ${BINDIR}/dbtest
-r -d .
/non_existant_dir
126 if [ $ret -ne 46 ]; then
127 html_failed
"Dbtest readonly succeeded in a nonexisting directory $ret"
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
135 if [ $ret -ne 0 ]; then
136 html_failed
"Dbtest force failed in a nonexisting directory $ret"
138 html_passed
"Dbtest force succeeded in a nonexisting dir $ret"
141 Echo
"test opening the database readonly in an empty directory"
143 ${BINDIR}/tstclnt
-h ${HOST} -d $EMPTY_DIR
145 if [ $ret -ne 1 ]; then
146 html_failed
"Tstclnt succeded in an empty directory $ret"
148 html_passed
"Tstclnt didn't work in an empty dir $ret"
150 ${BINDIR}/dbtest
-r -d $EMPTY_DIR
152 if [ $ret -ne 46 ]; then
153 html_failed
"Dbtest readonly succeeded in an empty directory $ret"
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
160 if [ $ret -ne 0 ]; then
161 html_failed
"Dbtest logout after empty DB Init looses key $ret"
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
168 if [ $ret -ne 0 ]; then
169 html_failed
"Dbtest password DB Init looses needlogin state $ret"
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
176 if [ $ret -ne 255 ]; then
177 html_failed
"Certutil succeeded in deleting a cert in an empty directory $ret"
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
185 if [ $ret -ne 0 ]; then
186 html_failed
"Dbtest force readonly failed in an empty directory $ret"
188 html_passed
"Dbtest force readonly succeeded in an empty dir $ret"
191 Echo
"test opening the database r/w in a readonly directory"
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
207 if [ $ret -ne 46 ]; then
208 html_failed
"Dbtest r/w succeeded in an readonly directory $ret"
210 html_passed
"Dbtest r/w didn't work in an readonly dir $ret"
212 ${BINDIR}/certutil
-D -n "TestUser" -d .
214 if [ $ret -ne 255 ]; then
215 html_failed
"Certutil succeeded in deleting a cert in an readonly directory $ret"
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
224 if [ $ret -ne 0 ]; then
225 html_failed
"Dbtest readonly failed in a readonly directory $ret"
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
233 if [ $ret -ne 0 ]; then
234 html_failed
"Dbtest force failed in a readonly directory $ret"
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 #################################################
247 dbtest_main
>$DBTEST_LOG 2>&1