Update gnulib files.
[shishi.git] / tests / shisa.sh
blob290b672d0302b79e28c97e5b63905f6d5b2e90b7
1 #!/bin/sh
2 # Copyright (C) 2003, 2005, 2007 Simon Josefsson.
4 # This file is part of Shishi.
6 # Shishi is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Shishi is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Shishi; if not, see http://www.gnu.org/licenses or write
18 # to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 # Floor, Boston, MA 02110-1301, USA.
21 SHISA=$PWD/../src/shisa
22 DBDIR=shisa.db.tmp.$$
24 OUT=$DBDIR/out
25 ERR=$DBDIR/err
26 CONF=$DBDIR/conf
28 if test -n "$VERBOSE"; then
29 set -x
32 mkdir $DBDIR
33 if test ! -d $DBDIR; then
34 echo Cannot create $DBDIR
35 exit 1
38 trap "rm -rf $DBDIR" EXIT
40 echo "db file $DBDIR" > $CONF
41 if test ! -f $CONF; then
42 echo Cannot create $CONF
43 exit 1
46 if test ! -f $SHISA; then
47 echo Cannot find $SHISA
48 exit 1
51 echo Dump empty database.
52 out=`$SHISA -c $CONF -d`
53 if test $? != 0; then
54 echo rc $?
55 exit 1
57 expectout=""
58 if test "$out" != "$expectout"; then
59 echo expected: $expectout >&2
60 echo -----got: $out >&2
61 exit 1
64 echo Add realm.
65 out=`$SHISA -c $CONF -a TESTREALM`
66 if test $? != 0; then
67 echo rc $?
68 exit 1
70 expectout="Adding realm \`TESTREALM'...
71 Adding realm \`TESTREALM'...done"
72 if test "$out" != "$expectout"; then
73 echo expected: $expectout >&2
74 echo -----got: $out >&2
75 exit 1
78 echo List database.
79 out=`$SHISA -c $CONF -l`
80 if test $? != 0; then
81 echo rc $?
82 exit 1
84 expectout="TESTREALM"
85 if test "$out" != "$expectout"; then
86 echo expected: $expectout >&2
87 echo -----got: $out >&2
88 exit 1
91 echo Add realm.
92 out=`$SHISA -c $CONF -a TESTREALM2`
93 if test $? != 0; then
94 echo rc $?
95 exit 1
97 expectout="Adding realm \`TESTREALM2'...
98 Adding realm \`TESTREALM2'...done"
99 if test "$out" != "$expectout"; then
100 echo expected: $expectout >&2
101 echo -----got: $out >&2
102 exit 1
105 echo Dump database.
106 out=`$SHISA -c $CONF -d`
107 if test $? != 0; then
108 echo rc $?
109 exit 1
111 expectout="TESTREALM
112 TESTREALM2"
113 if test "$out" != "$expectout"; then
114 echo expected: $expectout >&2
115 echo -----got: $out >&2
116 exit 1
119 echo Remove realm.
120 out=`$SHISA -c $CONF -r TESTREALM2`
121 if test $? != 0; then
122 echo rc $?
123 exit 1
125 expectout="Removing realm \`TESTREALM2'...
126 Removing realm \`TESTREALM2'...done"
127 if test "$out" != "$expectout"; then
128 echo expected: $expectout >&2
129 echo -----got: $out >&2
130 exit 1
133 echo Dump database.
134 out=`$SHISA -c $CONF -d`
135 if test $? != 0; then
136 echo rc $?
137 exit 1
139 expectout="TESTREALM"
140 if test "$out" != "$expectout"; then
141 echo expected: $expectout >&2
142 echo -----got: $out >&2
143 exit 1
146 echo Add principal.
147 out=`$SHISA -c $CONF -a TESTREALM test/principal`
148 if test $? != 0; then
149 echo rc $?
150 exit 1
152 expectout="Adding principal \`test/principal@TESTREALM'...
153 Adding principal \`test/principal@TESTREALM'...done"
154 if test "$out" != "$expectout"; then
155 echo expected: $expectout >&2
156 echo -----got: $out >&2
157 exit 1
160 echo Dump database.
161 out=`$SHISA -c $CONF -d`
162 if test $? != 0; then
163 echo rc $?
164 exit 1
166 expectout="TESTREALM
167 test/principal
168 Account is enabled.
169 Current key version 0 (0x0).
170 Key 0 (0x0).
171 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
172 if test "$out" != "$expectout"; then
173 echo expected: $expectout >&2
174 echo -----got: $out >&2
175 exit 1
178 echo Add second principal.
179 out=`$SHISA -c $CONF -a TESTREALM test/principal2`
180 if test $? != 0; then
181 echo rc $?
182 exit 1
184 expectout="Adding principal \`test/principal2@TESTREALM'...
185 Adding principal \`test/principal2@TESTREALM'...done"
186 if test "$out" != "$expectout"; then
187 echo expected: $expectout >&2
188 echo -----got: $out >&2
189 exit 1
192 echo Dump database.
193 out=`$SHISA -c $CONF -d`
194 if test $? != 0; then
195 echo rc $?
196 exit 1
198 expectout="TESTREALM
199 test/principal
200 Account is enabled.
201 Current key version 0 (0x0).
202 Key 0 (0x0).
203 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
204 test/principal2
205 Account is enabled.
206 Current key version 0 (0x0).
207 Key 0 (0x0).
208 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
209 if test "$out" != "$expectout"; then
210 echo expected: $expectout >&2
211 echo -----got: $out >&2
212 exit 1
215 echo Add third principal.
216 out=`$SHISA -c $CONF -a TESTREALM test/principal3`
217 if test $? != 0; then
218 echo rc $?
219 exit 1
221 expectout="Adding principal \`test/principal3@TESTREALM'...
222 Adding principal \`test/principal3@TESTREALM'...done"
223 if test "$out" != "$expectout"; then
224 echo expected: $expectout >&2
225 echo -----got: $out >&2
226 exit 1
229 echo Add third principal again.
230 out=`$SHISA -c $CONF -a TESTREALM test/principal3 2>&1`
231 if test $? != 1; then
232 echo rc $?
233 exit 1
236 echo Remove second principal.
237 out=`$SHISA -c $CONF -r TESTREALM test/principal2`
238 if test $? != 0; then
239 echo rc $?
240 exit 1
242 expectout="Removing principal \`test/principal2@TESTREALM'...
243 Removing principal \`test/principal2@TESTREALM'...done"
244 if test "$out" != "$expectout"; then
245 echo expected: $expectout >&2
246 echo -----got: $out >&2
247 exit 1
250 echo Dump database.
251 out=`$SHISA -c $CONF -d`
252 if test $? != 0; then
253 echo rc $?
254 exit 1
256 expectout="TESTREALM
257 test/principal
258 Account is enabled.
259 Current key version 0 (0x0).
260 Key 0 (0x0).
261 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
262 test/principal3
263 Account is enabled.
264 Current key version 0 (0x0).
265 Key 0 (0x0).
266 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
267 if test "$out" != "$expectout"; then
268 echo expected: $expectout >&2
269 echo -----got: $out >&2
270 exit 1
273 echo Tring to remove entire realm.
274 out=`$SHISA -c $CONF -r TESTREALM 2>&1`
275 if test $? != 1; then
276 echo rc $?
277 exit 1
280 echo Dump database.
281 out=`$SHISA -c $CONF -d`
282 if test $? != 0; then
283 echo rc $?
284 exit 1
286 expectout="TESTREALM
287 test/principal
288 Account is enabled.
289 Current key version 0 (0x0).
290 Key 0 (0x0).
291 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
292 test/principal3
293 Account is enabled.
294 Current key version 0 (0x0).
295 Key 0 (0x0).
296 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
297 if test "$out" != "$expectout"; then
298 echo expected: $expectout >&2
299 echo -----got: $out >&2
300 exit 1
303 echo Add principal with des key and password.
304 out=`$SHISA -c $CONF -a TESTREALM test/principal2 -E des --password=foo --keys`
305 if test $? != 0; then
306 echo rc $?
307 exit 1
309 expectout="Adding principal \`test/principal2@TESTREALM'...
310 -----BEGIN SHISHI KEY-----
311 Keytype: 3 (des-cbc-md5)
312 Principal: test/principal2
313 Realm: TESTREALM
315 s3WXrcITWPE=
316 -----END SHISHI KEY-----
317 Adding principal \`test/principal2@TESTREALM'...done"
318 if test "$out" != "$expectout"; then
319 echo expected: $expectout >&2
320 echo -----got: $out >&2
321 exit 1
324 echo Add aes key with password to principal.
325 out=`$SHISA -c $CONF -n TESTREALM test/principal2 -E aes --password=foo --keys`
326 if test $? != 0; then
327 echo rc $?
328 exit 1
330 expectout="Adding key to \`test/principal2@TESTREALM'...
331 -----BEGIN SHISHI KEY-----
332 Keytype: 18 (aes256-cts-hmac-sha1-96)
333 Principal: test/principal2
334 Realm: TESTREALM
336 3XpVlkzCS2gGYbaShDQktrmYVkcqvMIMuJKLxq9a6oU=
337 -----END SHISHI KEY-----
338 Adding key to \`test/principal2@TESTREALM'...done"
339 if test "$out" != "$expectout"; then
340 echo expected: $expectout >&2
341 echo -----got: $out >&2
342 exit 1
345 echo Dump database.
346 out=`$SHISA -c $CONF -d`
347 if test $? != 0; then
348 echo rc $?
349 exit 1
351 expectout="TESTREALM
352 test/principal
353 Account is enabled.
354 Current key version 0 (0x0).
355 Key 0 (0x0).
356 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
357 test/principal2
358 Account is enabled.
359 Current key version 0 (0x0).
360 Key 0 (0x0).
361 Etype des-cbc-md5 (0x3, 3).
362 Key 1 (0x1).
363 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
364 test/principal3
365 Account is enabled.
366 Current key version 0 (0x0).
367 Key 0 (0x0).
368 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
369 if test "$out" != "$expectout"; then
370 echo expected: $expectout >&2
371 echo -----got: $out >&2
372 exit 1
375 echo Add 3des key with password to principal.
376 out=`$SHISA -c $CONF -n TESTREALM test/principal2 -E des3 --password=foo --keys`
377 if test $? != 0; then
378 echo rc $?
379 exit 1
381 expectout="Adding key to \`test/principal2@TESTREALM'...
382 -----BEGIN SHISHI KEY-----
383 Keytype: 16 (des3-cbc-sha1-kd)
384 Principal: test/principal2
385 Realm: TESTREALM
387 nXV/NLyMwgSunRZATGitesFP466wyGfZ
388 -----END SHISHI KEY-----
389 Adding key to \`test/principal2@TESTREALM'...done"
390 if test "$out" != "$expectout"; then
391 echo expected: $expectout >&2
392 echo -----got: $out >&2
393 exit 1
396 echo Dump database.
397 out=`$SHISA -c $CONF -d`
398 if test $? != 0; then
399 echo rc $?
400 exit 1
402 expectout="TESTREALM
403 test/principal
404 Account is enabled.
405 Current key version 0 (0x0).
406 Key 0 (0x0).
407 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
408 test/principal2
409 Account is enabled.
410 Current key version 0 (0x0).
411 Key 0 (0x0).
412 Etype des-cbc-md5 (0x3, 3).
413 Key 1 (0x1).
414 Etype aes256-cts-hmac-sha1-96 (0x12, 18).
415 Key 2 (0x2).
416 Etype des3-cbc-sha1-kd (0x10, 16).
417 test/principal3
418 Account is enabled.
419 Current key version 0 (0x0).
420 Key 0 (0x0).
421 Etype aes256-cts-hmac-sha1-96 (0x12, 18)."
422 if test "$out" != "$expectout"; then
423 echo expected: $expectout >&2
424 echo -----got: $out >&2
425 exit 1
428 echo Remove first principal.
429 out=`$SHISA -c $CONF -r TESTREALM test/principal`
430 if test $? != 0; then
431 echo rc $?
432 exit 1
434 expectout="Removing principal \`test/principal@TESTREALM'...
435 Removing principal \`test/principal@TESTREALM'...done"
436 if test "$out" != "$expectout"; then
437 echo expected: $expectout >&2
438 echo -----got: $out >&2
439 exit 1
442 echo Remove third principal.
443 out=`$SHISA -c $CONF -r TESTREALM test/principal3`
444 if test $? != 0; then
445 echo rc $?
446 exit 1
448 expectout="Removing principal \`test/principal3@TESTREALM'...
449 Removing principal \`test/principal3@TESTREALM'...done"
450 if test "$out" != "$expectout"; then
451 echo expected: $expectout >&2
452 echo -----got: $out >&2
453 exit 1
456 echo Remove aes key on second principal.
457 out=`$SHISA -c $CONF --key-remove TESTREALM test/principal2 -E aes`
458 if test $? != 0; then
459 echo rc $?
460 exit 1
462 expectout="Removing key from \`test/principal2@TESTREALM'...
463 Removing key from \`test/principal2@TESTREALM'...done"
464 if test "$out" != "$expectout"; then
465 echo expected: $expectout >&2
466 echo -----got: $out >&2
467 exit 1
470 echo Dump database.
471 out=`$SHISA -c $CONF -d`
472 if test $? != 0; then
473 echo rc $?
474 exit 1
476 expectout="TESTREALM
477 test/principal2
478 Account is enabled.
479 Current key version 0 (0x0).
480 Key 0 (0x0).
481 Etype des-cbc-md5 (0x3, 3).
482 Key 1 (0x1).
483 Etype des3-cbc-sha1-kd (0x10, 16)."
484 if test "$out" != "$expectout"; then
485 echo expected: $expectout >&2
486 echo -----got: $out >&2
487 exit 1
490 echo Add 3des key with password to principal.
491 out=`$SHISA -c $CONF -n TESTREALM test/principal2 -E des3 --password=bar --keys`
492 if test $? != 0; then
493 echo rc $?
494 exit 1
496 expectout="Adding key to \`test/principal2@TESTREALM'...
497 -----BEGIN SHISHI KEY-----
498 Keytype: 16 (des3-cbc-sha1-kd)
499 Principal: test/principal2
500 Realm: TESTREALM
502 wb9SbVsgCEmttWiFikwvGQLj5YZ2NFja
503 -----END SHISHI KEY-----
504 Adding key to \`test/principal2@TESTREALM'...done"
505 if test "$out" != "$expectout"; then
506 echo expected: $expectout >&2
507 echo -----got: $out >&2
508 exit 1
511 echo Dump database.
512 out=`$SHISA -c $CONF -d --keys`
513 if test $? != 0; then
514 echo rc $?
515 exit 1
517 expectout="TESTREALM
518 test/principal2
519 Account is enabled.
520 Current key version 0 (0x0).
521 Key 0 (0x0).
522 Etype des-cbc-md5 (0x3, 3).
523 -----BEGIN SHISHI KEY-----
524 Keytype: 3 (des-cbc-md5)
525 Principal: test/principal2
526 Realm: TESTREALM
528 s3WXrcITWPE=
529 -----END SHISHI KEY-----
530 Password foo.
531 Key 1 (0x1).
532 Etype des3-cbc-sha1-kd (0x10, 16).
533 -----BEGIN SHISHI KEY-----
534 Keytype: 16 (des3-cbc-sha1-kd)
535 Principal: test/principal2
536 Realm: TESTREALM
538 wb9SbVsgCEmttWiFikwvGQLj5YZ2NFja
539 -----END SHISHI KEY-----
540 Password bar.
541 Key 2 (0x2).
542 Etype des3-cbc-sha1-kd (0x10, 16).
543 -----BEGIN SHISHI KEY-----
544 Keytype: 16 (des3-cbc-sha1-kd)
545 Principal: test/principal2
546 Realm: TESTREALM
548 nXV/NLyMwgSunRZATGitesFP466wyGfZ
549 -----END SHISHI KEY-----
550 Password foo."
551 if test "$out" != "$expectout"; then
552 echo expected: $expectout >&2
553 echo -----got: $out >&2
554 exit 1
557 echo Remove 3des key with password 'bar' on second principal.
558 out=`$SHISA -c $CONF --key-remove TESTREALM test/principal2 -E des3 --password=bar`
559 if test $? != 0; then
560 echo rc $?
561 exit 1
563 expectout="Removing key from \`test/principal2@TESTREALM'...
564 Removing key from \`test/principal2@TESTREALM'...done"
565 if test "$out" != "$expectout"; then
566 echo expected: $expectout >&2
567 echo -----got: $out >&2
568 exit 1
571 echo Remove 3des key with password 'foo' on second principal.
572 out=`$SHISA -c $CONF --key-remove TESTREALM test/principal2 -E des3 --password=foo`
573 if test $? != 0; then
574 echo rc $?
575 exit 1
577 expectout="Removing key from \`test/principal2@TESTREALM'...
578 Removing key from \`test/principal2@TESTREALM'...done"
579 if test "$out" != "$expectout"; then
580 echo expected: $expectout >&2
581 echo -----got: $out >&2
582 exit 1
585 echo Dump database.
586 out=`$SHISA -c $CONF -d`
587 if test $? != 0; then
588 echo rc $?
589 exit 1
591 expectout="TESTREALM
592 test/principal2
593 Account is enabled.
594 Current key version 0 (0x0).
595 Key 0 (0x0).
596 Etype des-cbc-md5 (0x3, 3)."
597 if test "$out" != "$expectout"; then
598 echo expected: $expectout >&2
599 echo -----got: $out >&2
600 exit 1
603 echo Tests finished
604 exit 0