chiark / gitweb /
server/tests.at, t/keyring-*: New tests for key management.
[tripe] / server / tests.at
CommitLineData
5d85da1c
MW
1### -*-autotest-*-
2###
3### Test script for the main server
4###
5### (c) 2008 Straylight/Edgeware
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This file is part of Trivial IP Encryption (TrIPE).
11###
12### TrIPE is free software; you can redistribute it and/or modify
13### it under the terms of the GNU General Public License as published by
14### the Free Software Foundation; either version 2 of the License, or
15### (at your option) any later version.
16###
17### TrIPE is distributed in the hope that it will be useful,
18### but WITHOUT ANY WARRANTY; without even the implied warranty of
19### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20### GNU General Public License for more details.
21###
22### You should have received a copy of the GNU General Public License
23### along with TrIPE; if not, write to the Free Software Foundation,
24### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26m4_define([nl], [
27])
28
29## Configure a directory ready for use by tripe.
30m4_define([SETUPDIR], [
31 cp $abs_top_srcdir/t/keyring-$1 ./keyring
32 key extract -f-secret keyring.pub
33])
34
35## Running standard programs with useful options.
36m4_define([TRIPE],
388e0319
MW
37 [env TRIPE_PRIVHELPER=$abs_top_builddir/priv/tripe-privhelper \
38 $abs_top_builddir/server/tripe -F -d. -aadmin -p0 -b127.0.0.1 -talice])
5d85da1c
MW
39m4_define([TRIPECTL], [$abs_top_builddir/client/tripectl -d. -aadmin])
40m4_define([USLIP], [$abs_top_builddir/uslip/tripe-uslip])
01c21903
MW
41m4_define([PKSTREAM],
42 [$abs_top_builddir/pkstream/pkstream -b127.0.0.1 -p127.0.0.1])
5d85da1c
MW
43
44## Sequences. (These are used for testing the replay protection machinery.)
45m4_define([R32], [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 dnl
46 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31])
47m4_define([P32], [21 26 14 12 25 18 2 27 10 31 24 29 0 20 17 11 dnl
48 8 3 7 23 19 1 13 30 6 9 5 22 15 28 16 4])
49
50###--------------------------------------------------------------------------
51### Scaffolding for running a TrIPE server.
52
05d4b7da 53## WITH_TRIPEX(dir, args, body)
5d85da1c
MW
54m4_define([WITH_TRIPEX], [
55
05d4b7da
MW
56## If this directory doesn't exist then Bad Things will happen.
57if test ! -d $1; then
58 echo >&2 "server directory \`$1' doesn't exist"
59 exit 99
60fi
61
5d85da1c
MW
62## Remove the status file. This is how we notice that the server's died.
63rm -f $1/server-status
64> $1/expected-server-output
65> $1/expected-server-errors
66
768a2316
MW
67## Autotest writes crap to standard output, which we don't want going to the
68## server. So keep a copy of the standard output, do the pipe, and recover
69## the old stdout inside the group.
5d85da1c
MW
70exec 3>&1
71{ (
72exec 1>&3 3>&-
73
74## Wait for the socket to appear. Watch for the server crashing during
75## initialization. Busy waiting is evil, but it's the best I can do and
76## not sleep for ages. (Yes, a second on each test group is a long time.)
768a2316 77while test ! -r $1/server-status && test ! -S $1/admin; do :; done
5d85da1c 78
05d4b7da
MW
79## Make the port number availale.
80AT_CHECK([TRIPECTL -d$1 PORT],, [stdout])
81mv stdout $1/port
82
5d85da1c
MW
83## Test body...
84$3
85
96f1fb57
MW
86## End of the test, now run the server. There's an awful hack here. If a
87## process running under strace exits with a signal, then strace will kill
88## itself with the same signal -- and therefore clobber the original
89## process's core file. So we arrange to run strace in one directory and
90## have the child process run in another.
5d85da1c
MW
91) && :; } | {
92 cd $1
96f1fb57 93 mkdir -p strace-hack/
5d85da1c 94 echo TRIPE $2 >&2
96f1fb57
MW
95 (cd strace-hack/
96 ulimit -c hard >/dev/null 2>&1
97 strace -f -o ../tripe.trace \
05d4b7da 98 TRIPE -d.. $2 >../server-output.full 2>../server-errors)
5d85da1c
MW
99 stat=$?
100 echo $stat >server-status
101 if test $stat -ne 0; then
102 echo "exit status: $stat" >>server-errors
103 fi
05d4b7da
MW
104
105 ## We interrupt this relatively sensible macro for an especially awful
106 ## hack. The tripe server emits warnings which are often caused by lack of
107 ## synchronization between two peers. These are harmless and shouldn't
108 ## cause test failures. But we shouldn't just trim out all messages that
109 ## look like the spurious ones: if they appear when we're not expecting
110 ## them, that's bad and they should properly cause a test failure.
111 ##
112 ## So we use the WARN command to insert magic directives into the server's
113 ## message stream. The directives begin with `WARN USER test'; remaining
114 ## tokens may be as follows.
115 ##
116 ## PUSH Introduce a new layer of nesting. Settings between
117 ## this PUSH and the matching POP will be forgotten
118 ## following the POP.
119 ##
120 ## POP End a layer of nesting. See PUSH above.
121 ##
122 ## IGNORE tokens Ignore lines which begin with the tokens.
123 ##
124 ## Token comparison isn't done very well, but it's good enough for these
125 ## purposes.
126 ##
127 ## We also trim out trace lines here, since it's useful to produce them for
128 ## debugging purposes and changing or introducing more of them shouldn't
129 ## cause failures.
130 awk '
131 BEGIN {
132 sp = 0;
133 npat = 0;
134 }
135 $[]1 == "TRACE" { next; }
136 $[]1 == "WARN" && $[]2 == "USER" && $[]3 == "test" {
137 if ($[]4 == "PUSH")
138 npatstk[[sp++]] = npat;
139 else if ($[]4 == "IGNORE") {
140 s = "";
141 p = "";
142 for (i = 5; i <= NF; i++) {
143 p = p s $[]i;
144 s = " ";
145 }
146 pat[[npat++]] = p;
147 } else if ($[]4 == "POP")
148 npat = npatstk[[--sp]];
149 next;
150 }
151 {
152 for (i = 0; i < npat; i++) {
153 n = length(pat[[i]]);
154 if (substr($[]0, 0, n) == pat[[i]])
155 next;
156 }
157 print $[]0;
158 }
159 ' server-output.full >server-output
5d85da1c
MW
160}
161exec 3>&-
162
163## Now check that the server's output matches our expectations.
164mv $1/expected-server-output expout
165mv $1/expected-server-errors experr
166AT_CHECK([cat $1/server-output; cat >&2 $1/server-errors],,
167 [expout], [experr])
168])
169
05d4b7da 170## WITH_TRIPE(args, body)
5d85da1c
MW
171m4_define([WITH_TRIPE], [WITH_TRIPEX([.], [$1], [$2])])
172
05d4b7da 173## WITH_2TRIPES(adir, bdir, bothargs, aargs, bargs, body)
5d85da1c
MW
174m4_define([WITH_2TRIPES],
175 [WITH_TRIPEX([$1], [$3 $4], [WITH_TRIPEX([$2], [$3 $5], [$6])])])
176
203e1b1f
MW
177## WITH_3TRIPES(adir, bdir, cdir, allargs, aargs, bargs, cargs, body)
178m4_define([WITH_3TRIPES],
179 [WITH_TRIPEX([$1], [$4 $5],
180 [WITH_TRIPEX([$2], [$4 $6],
181 [WITH_TRIPEX([$3], [$4 $7],
182 [$8])])])])
183
05d4b7da
MW
184## COMMS_EPING(adir, aname, bdir, bname)
185m4_define([COMMS_EPING], [
186 AT_CHECK([TRIPECTL -d$1 EPING $4],, [ignore])
187 AT_CHECK([TRIPECTL -d$3 EPING $2],, [ignore])
188])
189
190## COMMS_SLIP(adir, aname, bdir, bname)
191m4_define([COMMS_SLIP], [
192 AT_CHECK([echo "from $1" | USLIP -p $1/$4])
193 AT_CHECK([USLIP -g $3/$2],, [from $1[]nl])
194 AT_CHECK([echo "from $3" | USLIP -p $3/$2])
195 AT_CHECK([USLIP -g $1/$4],, [from $3[]nl])
196])
197
198## AWAIT_KXDONE(adir, aname, bdir, bname, body)
199m4_define([AWAIT_KXDONE], [
200
201 ## Ignore some reports caused by races.
202 TRIPECTL -d$3 WARN test PUSH
203 TRIPECTL -d$3 WARN test IGNORE WARN KX $2 incorrect cookie
204 TRIPECTL -d$3 WARN test IGNORE WARN KX $2 unexpected pre-challenge
205
206 ## Watch for the key-exchange completion announcement in the background.
207 COPROCESSES([wait-$1], [
208 echo WATCH +n
209 while read line; do
210 set x $line; shift
211 echo >&2 ">>> $line"
212 case "$[]1:$[]2:$[]3" in
213 OK::) ;;
214 NOTE:KXDONE:$4) break ;;
215 NOTE:*) ;;
216 *) exit 63 ;;
217 esac
218 done
219 ], [
220 TRIPECTL -d$1
221 ]) & waiter_$1=$!
222
223 $5
224
225 ## Collect the completion announcement.
226 wait $waiter_$1; waitrc=$?
227 AT_CHECK([echo $waitrc],, [0[]nl])
228
229 ## Be interested in key-exchange warnings again.
230 TRIPECTL -d$4 WARN test POP
231])
232
01c21903 233## ESTABLISH(adir, aname, aopts, bdir, bname, bopts, [aport], [bport])
05d4b7da
MW
234m4_define([ESTABLISH], [
235
236 ## Set up the establishment.
237 AWAIT_KXDONE([$1], [$2], [$4], [$5], [
01c21903
MW
238 AT_CHECK([TRIPECTL -d$1 ADD -cork $6 $5 INET 127.0.0.1 \
239 m4_if([$8], [], [$(cat $4/port)], [$8])])
240 AT_CHECK([TRIPECTL -d$4 ADD $3 $2 INET 127.0.0.1 \
241 m4_if([$7], [], [$(cat $1/port)], [$7])])
05d4b7da
MW
242 ])
243
244 ## Check transport pinging.
245 AT_CHECK([TRIPECTL -d$1 PING $5],, [ignore])
246 AT_CHECK([TRIPECTL -d$4 PING $2],, [ignore])
247
248 ## Check communication works.
249 COMMS_EPING([$1], [$2], [$4], [$5])
250 COMMS_SLIP([$1], [$2], [$4], [$5])
251])
252
5d85da1c
MW
253###--------------------------------------------------------------------------
254### Very unpleasant coprocess handling.
255
256## COPROCESSES(TAG, PROC-A, PROC-B)
257m4_define([COPROCESSES], [dnl
258rm -f pipe-$1; mknod pipe-$1 p
259{ { $2 nl } <pipe-$1 | { $3 nl } >pipe-$1; } dnl
260])
261
262## TRIPECTL_INTERACT(ARGS, SHELLSTUFF)
263m4_define([TRIPECTL_INTERACT], [
768a2316 264 exec 3>&1
11715242 265 COPROCESSES([client], [exec 4>&1 1>&3 $1], [TRIPECTL $2])
5d85da1c
MW
266])
267
268## TRIPECTL_COMMAND(CMD, EXPECT)
269m4_define([TRIPECTL_COMMAND], [
270 AT_CHECK([
271 m4_if([$1], [!], [:], [echo "$1" >&4])
272 read line
273 case "$line" in
274 "$2") ;;
275 *) echo 2>&1 "submitted $1: expected $2, found $line"; exit 1 ;;
276 esac
277 ])
278 exec 3>&-
279])
280
281###--------------------------------------------------------------------------
282### Make sure the thing basically works.
283
284AT_SETUP([server basics])
59d05259 285SETUPDIR([alpha])
5d85da1c
MW
286AT_CHECK([echo port | TRIPE -p54321],, [INFO 54321[]nl[]OK[]nl])
287AT_CLEANUP
288
289###--------------------------------------------------------------------------
290### Challenges.
291
292AT_SETUP([server challenges])
293AT_KEYWORDS([chal])
59d05259 294SETUPDIR([alpha])
5d85da1c
MW
295
296WITH_TRIPE(, [
297 ## A simple test.
298 AT_CHECK([chal=$(TRIPECTL GETCHAL); TRIPECTL checkchal $chal])
299
300 ## A wrong challenge. (This was valid once, but the probablity that the
301 ## server chose the same key is negligible.)
302 AT_CHECK([TRIPECTL checkchal AAAAAHyoOL+HMaE0Y9B3ivuszt0], [1],,
303 [tripectl: invalid-challenge[]nl])
304 echo WARN CHAL incorrect-tag >>expected-server-output
305
306 ## A duplicated challenge.
307 AT_CHECK([
308 chal=$(TRIPECTL GETCHAL)
309 TRIPECTL CHECKCHAL $chal
310 TRIPECTL CHECKCHAL $chal
311 ], [1],, [tripectl: invalid-challenge[]nl])
312 echo WARN CHAL replay duplicated-sequence >>expected-server-output
313
314 ## Out-of-order reception. There should be a window of 32 challenges; we
315 ## make 33 and check them in a strange order.
316 rm -f experr
317 echo "tripectl: invalid-challenge" >>experr
318 echo "WARN CHAL replay old-sequence" >>expected-server-output
319 for i in P32; do
320 echo "tripectl: invalid-challenge" >>experr
321 echo "WARN CHAL replay duplicated-sequence" >>expected-server-output
322 done
323 AT_CHECK([
324
325 ## Make the challenges.
326 for i in old R32; do TRIPECTL GETCHAL >chal-$i || exit 2; done
327
328 ## Now check them back.
329 for i in P32; do TRIPECTL CHECKCHAL $(cat chal-$i) || exit 3; done
330
331 ## Check the one which should have fallen off the front.
332 TRIPECTL CHECKCHAL $(cat chal-old) && exit 4
333
334 ## And make sure that the others are now considered duplicates.
335 for i in R32; do TRIPECTL CHECKCHAL $(cat chal-$i) && exit 5; done
336
337 ## All done: tidy cruft away.
338 rm -f chal-*
339 exit 0
340 ], [0],, [experr])
341])
342
343AT_CLEANUP
344
345###--------------------------------------------------------------------------
346### Communication.
347
348AT_SETUP([server communication])
349AT_KEYWORDS([comm])
350export TRIPE_SLIPIF=USLIP
351
59d05259 352for p in alice bob; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
5d85da1c
MW
353
354WITH_2TRIPES([alice], [bob], [-nslip], [-talice], [-tbob], [
05d4b7da
MW
355 ESTABLISH([alice], [not-alice], [-key alice],
356 [bob], [bob], [])
5d85da1c
MW
357])
358
359AT_CLEANUP
360
01c21903
MW
361###--------------------------------------------------------------------------
362### Mobile peer tracking.
363
364AT_SETUP([peer tracking])
365AT_KEYWORDS([mobile])
366export TRIPE_SLIPIF=USLIP
367
368for p in alice bob carol; do (mkdir $p; cd $p; SETUPDIR([alpha])); done
369
370## WITH_PKSTREAM(adir, aport, bdir, bport, body)
371m4_define([WITH_PKSTREAM], [
372 echo >&2 "pkstream: $1 <--> :$2 <-pkstream-> :$4 <--> $3"
373 PKSTREAM -l$4 127.0.0.1:$4 127.0.0.1:$(cat $3/port)& pkstream_$3_$1=$!
374 sleep 1
375 PKSTREAM -c127.0.0.1:$4 127.0.0.1:$2 127.0.0.1:$(cat $1/port)&
376 pkstream_$1_$3=$!
377 set +x
378 $5
379 kill $pkstream_$3_$1 $pkstream_$1_$3
380])
381
382WITH_3TRIPES([alice], [bob], [carol], [-nslip],
383 [-talice], [-tbob], [-tcarol], [
384
385 ## We need an indirection layer between the two peers so that we can
386 ## simulate the effects of NAT remapping. The nearest thing we have to
387 ## this is pkstream, so we may as well use that.
388 ##
389 ## alice <--> :5311 <-pkstream-> :5312 <--> bob
390 ## alice <--> :5321 <-pkstream-> :5322 <--> carol
391
392 WITH_PKSTREAM([alice], [5311], [bob], [5312], [
393 ESTABLISH([alice], [alice], [], [bob], [bob], [-mobile], [5312], [5311])
394 ])
395
396 WITH_PKSTREAM([alice], [5319], [bob], [5312], [
397 COMMS_EPING([bob], [bob], [alice], [alice])
398 COMMS_SLIP([bob], [bob], [alice], [alice])
399 ])
400
401 WITH_PKSTREAM([alice], [5321], [carol], [5322], [
402 ESTABLISH([alice], [alice], [], [carol], [carol], [-mobile],
403 [5322], [5321])
404 ])
405
406 WITH_PKSTREAM([alice], [5311], [bob], [5312], [
407 WITH_PKSTREAM([alice], [5321], [carol], [5322], [
408 COMMS_EPING([bob], [bob], [alice], [alice])
409 COMMS_EPING([carol], [carol], [alice], [alice])
410 COMMS_SLIP([bob], [bob], [alice], [alice])
411 COMMS_SLIP([carol], [carol], [alice], [alice])
412 ])])
413
414 WITH_PKSTREAM([alice], [5321], [bob], [5312], [
415 WITH_PKSTREAM([alice], [5311], [carol], [5322], [
416 COMMS_EPING([bob], [bob], [alice], [alice])
417 COMMS_EPING([carol], [carol], [alice], [alice])
418 COMMS_SLIP([bob], [bob], [alice], [alice])
419 COMMS_SLIP([carol], [carol], [alice], [alice])
420 ])])
421 wait
422])
423
424AT_CLEANUP
425
31b8e627
MW
426###--------------------------------------------------------------------------
427### Key management.
428
429AT_SETUP([server key-management])
430AT_KEYWORDS([keymgmt])
431export TRIPE_SLIPIF=USLIP
432
433## Determine all of the nets and the principals.
434princs=""
435nets=" "
436while read princ pnets; do
437 princs="$princs $princ"
438 for n in $pnets; do
439 case " $nets " in *" $n "*) ;; *) nets="$nets$n " ;; esac
440 done
441done <<PRINC
442alice alpha beta
443bob alpha beta
444carol beta
445PRINC
446
447## Build the master keyring. All key tags here are of the form PRINC/NET.
448for n in $nets; do
449 key -k$abs_top_srcdir/t/keyring-$n extract keyring-$n $princs
450 for p in $princs; do key -kkeyring-$n tag $p $p/$n; done
451 key merge keyring-$n
452 rm keyring-$n
453done
454key extract -f-secret keyring.pub
455
456## Set up the principals' directories.
457for p in $princs; do
458 mkdir $p
459 cp keyring keyring.pub $p/
460done
461
462WITH_3TRIPES([alice], [bob], [carol], [-nslip -Tmx],
463 [-talice/alpha], [-tbob/alpha], [-tcarol/beta], [
464
465 ## Establish this little merry-go-round.
466 ESTABLISH([alice], [alice], [-key alice/alpha],
467 [bob], [bob], [-key bob/alpha])
468 ESTABLISH([alice], [alice], [-key alice/beta],
469 [carol], [carol], [-priv alice/beta -key carol/beta])
470 ESTABLISH([bob], [bob], [-key bob/beta],
471 [carol], [carol], [-priv bob/beta -key carol/beta])
472
473 ## Tweak Bob's alpha key.
474 for p in $princs; do
475 TRIPECTL -d$p WARN test COMMENT tweak bob/alpha
476 done
477
478 key -k$abs_top_srcdir/t/keyring-alpha extract keyring-bob-new bob-new
479 key merge keyring-bob-new
480 key tag -r bob-new bob/alpha
481 key extract -f-secret keyring.pub
482 for p in alice bob; do cp keyring keyring.pub $p/; done
483
484 ## Kick the peers to see whether they update.
485 AWAIT_KXDONE([alice], [alice], [bob], [bob], [
486 TRIPECTL -dalice RELOAD
487 TRIPECTL -dbob RELOAD
488 TRIPECTL -dalice FORCEKX bob
489 TRIPECTL -dbob FORCEKX alice
490 ])
491
492 COMMS_EPING([alice], [alice], [bob], [bob])
493 COMMS_EPING([bob], [bob], [alice], [alice])
494
495 ## Update the beta ring.
496 key merge $abs_top_srcdir/t/keyring-beta-new
497 for p in $princs; do key tag -r $p $p/beta; done
498 key extract -f-secret keyring.pub
499
500 ## Update alice's and carol's private keys, bob's public. This should be
501 ## insufficient for them to switch, but the results could be interesting.
502 for p in $princs; do
503 TRIPECTL -d$p WARN test COMMENT tweak beta step 1
504 done
505
506 for p in alice carol; do cp keyring $p/; done
507 cp keyring.pub bob/
508 for p in $princs; do TRIPECTL -d$p RELOAD; done
509
510 AT_DATA([algs-alpha], [dnl
511kx-group=ec kx-group-order-bits=256 kx-group-elt-bits=512
512hash=rmd160 mgf=rmd160-mgf hash-sz=20
513cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
514cipher-data-limit=67108864
515mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
516])
517
518 AT_DATA([algs-beta-old], [dnl
519kx-group=prime kx-group-order-bits=160 kx-group-elt-bits=1023
520hash=rmd160 mgf=rmd160-mgf hash-sz=20
521cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
522cipher-data-limit=67108864
523mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
524])
525
526 AT_DATA([algs-beta-new], [dnl
527kx-group=ec kx-group-order-bits=161 kx-group-elt-bits=320
528hash=rmd160 mgf=rmd160-mgf hash-sz=20
529cipher=blowfish-cbc cipher-keysz=20 cipher-blksz=8
530cipher-data-limit=67108864
531mac=rmd160-hmac mac-keysz=20 mac-tagsz=10
532])
533
534 cp algs-alpha expout; AT_CHECK([TRIPECTL -dalice ALGS],, [expout])
535 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
536 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dbob ALGS carol],, [expout])
537 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],, [expout])
538 cp algs-beta-old expout; AT_CHECK([TRIPECTL -dcarol ALGS alice],, [expout])
539
540 ## Now copy the full keys. We expect this to provoke key exchange.
541 for p in $princs; do
542 TRIPECTL -d$p WARN test COMMENT tweak beta step 2
543 done
544
545 for p in $princs; do cp keyring keyring.pub $p/; done
546
547 AWAIT_KXDONE([alice], [alice], [carol], [carol], [
548 TRIPECTL -dalice RELOAD
549 AWAIT_KXDONE([bob], [bob], [carol], [carol], [
550 TRIPECTL -dbob RELOAD
551 TRIPECTL -dcarol RELOAD
552 ])
553 ])
554
555 cp algs-alpha expout; AT_CHECK([TRIPECTL -dalice ALGS],, [expout])
556 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dalice ALGS carol],, [expout])
557 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dbob ALGS carol],, [expout])
558 cp algs-beta-new expout; AT_CHECK([TRIPECTL -dcarol ALGS],, [expout])
559])
560
561AT_CLEANUP
562
5d85da1c
MW
563###--------------------------------------------------------------------------
564### Services.
565
566AT_SETUP([server services])
567AT_KEYWORDS([svc])
59d05259 568SETUPDIR([alpha])
5d85da1c
MW
569
570WITH_TRIPE(, [
571
572 ## Make sure it's not running yet.
573 AT_CHECK([TRIPECTL SVCENSURE test], [1],,
574 [tripectl: unknown-service test[]nl])
575
576 ## Run a simple service.
577 rm -f svc-test-running tripectl-status
578 COPROCESSES([svc], [
579 echo SVCCLAIM test 1.0.0
580 read line
581 case "$line" in
582 OK)
2f20abf2 583 ;;
5d85da1c 584 *)
2f20abf2 585 echo >&2 "SVCCLAIM failed: $line"
5d85da1c
MW
586 exit 1
587 ;;
588 esac
589 echo ok >svc-test-running
590 while read line; do
591 set -- $line
592 case "$[]1,$[]3,$[]4" in
593 SVCJOB,test,HELP)
594 echo SVCINFO try not to use this service for anything useful
595 echo SVCOK $[]2
596 ;;
597 SVCJOB,test,GOOD)
598 echo SVCOK $[]2
599 ;;
600 SVCJOB,test,BAD)
601 echo SVCFAIL $[]2 this-command-always-fails
602 ;;
603 SVCJOB,test,UGLY)
604 tag=$2
605 while read line; do
606 set -- $line
607 case "$[]1,$[]2,$[]3,$[]4" in
608 SVCCANCEL,$tag,,) break ;;
609 SVCJOB,*,test,ESCAPE)
2f20abf2 610 echo >&2 "attempt to escape from alkatraz"
5d85da1c
MW
611 exit 1
612 ;;
613 esac
614 done
615 ;;
616 SVCJOB,test,FIRST)
617 firsttag=$[]2
618 ;;
619 SVCJOB,test,SECOND)
620 echo SVCOK $firsttag
621 echo SVCOK $[]2
622 ;;
623 SVCJOB,*)
624 echo SVCFAIL $[]2 unknown-svc-command $[]4
625 ;;
626 SVCCLAIM,*)
627 break
628 ;;
629 OK,* | INFO,*)
630 ;;
631 FAIL,*)
632 echo "failure in service: $line" >&2
633 ;;
634 esac
635 done
636 ], [
637 TRIPECTL; echo $? >tripectl-status
638 ]) 2>tripectl-errors &
639
640 ## Wait until it starts up.
641 while test ! -r svc-test-running && test ! -r tripectl-status; do :; done
642
643 ## Make sure it's running.
644 AT_CHECK([TRIPECTL SVCQUERY test],, [name=test version=1.0.0[]nl])
645
646 ## Try some simple commands.
647 AT_CHECK([TRIPECTL SVCSUBMIT test GOOD])
648 AT_CHECK([TRIPECTL SVCSUBMIT test BAD], [1],,
649 [tripectl: this-command-always-fails[]nl])
650
651 ## And now with commands in the background.
652 TRIPECTL_INTERACT([
653 TRIPECTL_COMMAND([SVCSUBMIT test GOOD], [OK])
654 TRIPECTL_COMMAND([SVCSUBMIT -background foo test UGLY], [BGDETACH foo])
655 TRIPECTL_COMMAND([BGCANCEL foo], [OK])
656 TRIPECTL_COMMAND([SVCSUBMIT test ESCAPE],
657 [FAIL unknown-svc-command ESCAPE])
658 ])
659
660 ## Out-of-order completion.
661 TRIPECTL_INTERACT([
662 TRIPECTL_COMMAND([SVCSUBMIT -background one test FIRST], [BGDETACH one])
663 TRIPECTL_COMMAND([SVCSUBMIT -background two test SECOND], [BGDETACH two])
664 TRIPECTL_COMMAND([!], [BGOK one])
665 TRIPECTL_COMMAND([!], [BGOK two])
666 ])
667
668 ## All done.
669 exit 0
670])
671
672AT_CLEANUP
673
674###----- That's all, folks --------------------------------------------------