xref: /netbsd-src/crypto/external/bsd/heimdal/dist/tests/db/add-modify-delete.in (revision 929c70cba110089af68ff46da658d45500ef61a1)
1ca1c9b0cSelric#!/bin/sh
2ca1c9b0cSelric#
3ca1c9b0cSelric# Copyright (c) 2006 Kungliga Tekniska Högskolan
4ca1c9b0cSelric# (Royal Institute of Technology, Stockholm, Sweden).
5ca1c9b0cSelric# All rights reserved.
6ca1c9b0cSelric#
7ca1c9b0cSelric# Redistribution and use in source and binary forms, with or without
8ca1c9b0cSelric# modification, are permitted provided that the following conditions
9ca1c9b0cSelric# are met:
10ca1c9b0cSelric#
11ca1c9b0cSelric# 1. Redistributions of source code must retain the above copyright
12ca1c9b0cSelric#    notice, this list of conditions and the following disclaimer.
13ca1c9b0cSelric#
14ca1c9b0cSelric# 2. Redistributions in binary form must reproduce the above copyright
15ca1c9b0cSelric#    notice, this list of conditions and the following disclaimer in the
16ca1c9b0cSelric#    documentation and/or other materials provided with the distribution.
17ca1c9b0cSelric#
18ca1c9b0cSelric# 3. Neither the name of the Institute nor the names of its contributors
19ca1c9b0cSelric#    may be used to endorse or promote products derived from this software
20ca1c9b0cSelric#    without specific prior written permission.
21ca1c9b0cSelric#
22ca1c9b0cSelric# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23ca1c9b0cSelric# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ca1c9b0cSelric# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ca1c9b0cSelric# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26ca1c9b0cSelric# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ca1c9b0cSelric# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ca1c9b0cSelric# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ca1c9b0cSelric# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ca1c9b0cSelric# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ca1c9b0cSelric# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ca1c9b0cSelric# SUCH DAMAGE.
33ca1c9b0cSelric#
34b40995a4Selric# Id
35ca1c9b0cSelric#
36ca1c9b0cSelric
37ca1c9b0cSelricsrcdir="@srcdir@"
38ca1c9b0cSelricobjdir="@objdir@"
39ca1c9b0cSelricEGREP="@EGREP@"
40ca1c9b0cSelric
41b9d004c6Schristosdefault_db_type=@default_db_type@
42b9d004c6Schristosdb_type=${1:-${default_db_type}}
43b9d004c6Schristos
44*929c70cbSchristos# If there is no useful db support compiled in, disable test
45ca1c9b0cSelric./have-db || exit 77
46ca1c9b0cSelric
47ca1c9b0cSelricR=EXAMPLE.ORG
48ca1c9b0cSelric
49ca1c9b0cSelrickadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R"
50ca1c9b0cSelriciproplog="${TESTS_ENVIRONMENT} ../../lib/kadm5/iprop-log"
51ca1c9b0cSelric
52b9d004c6SchristosKRB5_CONFIG="${objdir}/krb5.conf-${db_type}"
53ca1c9b0cSelricexport KRB5_CONFIG
54ca1c9b0cSelric
55ca1c9b0cSelricrm -f current-db*
56ca1c9b0cSelricrm -f log.current-db*
57ca1c9b0cSelricrm -f out-*
58ca1c9b0cSelricrm -f mkey.file*
59ca1c9b0cSelric
60ca1c9b0cSelricecho init database
61ca1c9b0cSelric${kadmin} \
62ca1c9b0cSelric    init \
63ca1c9b0cSelric    --realm-max-ticket-life=1day \
64ca1c9b0cSelric    --realm-max-renewable-life=1month \
65ca1c9b0cSelric    EXAMPLE.ORG || exit 1
66ca1c9b0cSelric
67ca1c9b0cSelricecho test add
68ca1c9b0cSelric${kadmin} add -r --use-defaults foo || exit 1
69ca1c9b0cSelric${kadmin} list '*' > /dev/null || exit 1
70ca1c9b0cSelric${kadmin} list '*' | ${EGREP} '^foo$' > /dev/null || exit 1
71ca1c9b0cSelric
72ca1c9b0cSelricecho "test add (double)"
73ca1c9b0cSelric${kadmin} add -r --use-defaults foo 2>/dev/null && exit 1
74ca1c9b0cSelric
75ca1c9b0cSelricecho test rename
76ca1c9b0cSelric${kadmin} rename foo bar
77ca1c9b0cSelric${kadmin} list '*' | ${EGREP} '^foo$' > /dev/null && exit 1
78ca1c9b0cSelric${kadmin} list '*' | ${EGREP} '^bar$' > /dev/null || exit 1
79ca1c9b0cSelric
80ca1c9b0cSelricecho test delete
81ca1c9b0cSelric${kadmin} delete bar || exit 1
82ca1c9b0cSelric${kadmin} list '*' | ${EGREP} '^bar$' > /dev/null && exit 1
83ca1c9b0cSelric
84ca1c9b0cSelricecho "test delete (double)"
85ca1c9b0cSelric${kadmin} delete bar 2> /dev/null && exit 1
86ca1c9b0cSelric
87ca1c9b0cSelricecho "creating sample user"
88ca1c9b0cSelric${kadmin} add -r --use-defaults foo  || exit 1
89ca1c9b0cSelric${kadmin} get foo > tempfile  || exit 1
90ca1c9b0cSelricecho checking principal
91ca1c9b0cSelric${EGREP} " *Principal: foo@EXAMPLE.ORG$" tempfile > /dev/null || exit 1
92ca1c9b0cSelricecho checking kvno
93ca1c9b0cSelric${EGREP} " *Kvno: 1$" tempfile > /dev/null || exit 1
94ca1c9b0cSelricecho checking failed login count
95ca1c9b0cSelric${EGREP} " *Failed login count: 0$" tempfile > /dev/null || exit 1
96ca1c9b0cSelricecho checking modifier
97ca1c9b0cSelric${EGREP} " *Modifier: kadmin/admin@EXAMPLE.ORG$" tempfile > /dev/null || exit 1
98ca1c9b0cSelricecho checking attributes
99ca1c9b0cSelric${EGREP} " *Attributes: $" tempfile > /dev/null || exit 1
100ca1c9b0cSelricecho checking renew time
101ca1c9b0cSelric${EGREP} " *Max renewable life: 1 week$" tempfile > /dev/null || exit 1
102ca1c9b0cSelric
103ca1c9b0cSelricecho modifing renewable-life
104ca1c9b0cSelric${kadmin} modify --max-renewable-life=2months foo
105ca1c9b0cSelricecho checking renew time
106ca1c9b0cSelric${kadmin} get foo > tempfile  || exit 1
107ca1c9b0cSelric${EGREP} " *Max renewable life: 2 months$" tempfile > /dev/null || exit 1
108ca1c9b0cSelric
109ca1c9b0cSelricecho "creating sample server"
110ca1c9b0cSelric${kadmin} add -r --use-defaults host/datan.example.org  || exit 1
111ca1c9b0cSelric${kadmin} get host/datan.example.org > tempfile  || exit 1
112ca1c9b0cSelricecho checking principal
113ca1c9b0cSelric${EGREP} " *Principal: host/datan.example.org@EXAMPLE.ORG$" tempfile > /dev/null || exit 1
114ca1c9b0cSelricecho checking kvno
115ca1c9b0cSelric${EGREP} " *Kvno: 1$" tempfile > /dev/null || exit 1
116ca1c9b0cSelric
117ca1c9b0cSelricecho "iprop-log dump"
118ca1c9b0cSelric${iproplog} dump > /dev/null || exit 1
119ca1c9b0cSelricecho "iprop-log last-version"
120ca1c9b0cSelric${iproplog} last-version > /dev/null || exit 1
121ca1c9b0cSelric
122ca1c9b0cSelricecho "check iprop replay"
123ca1c9b0cSelric
124ca1c9b0cSelric${kadmin} dump out-current-db  || exit 1
125ca1c9b0cSelricsort out-current-db > out-current-db-sort
126ca1c9b0cSelric
127ca1c9b0cSelricrm -f current-db*
128ca1c9b0cSelric
129ca1c9b0cSelricecho "replaying"
130ca1c9b0cSelric${iproplog} replay > /dev/null || exit 1
131ca1c9b0cSelric
132ca1c9b0cSelric${kadmin} dump out-current-db2  || exit 1
133ca1c9b0cSelricsort out-current-db2 > out-current-db2-sort
134ca1c9b0cSelric
135ca1c9b0cSelric# XXX database should really be the same afterward... :(
136ca1c9b0cSelric# cmp out-current-db-sort out-current-db2-sort || exit 1
137ca1c9b0cSelric
138ca1c9b0cSelric
139ca1c9b0cSelric
140ca1c9b0cSelricexit 0
141