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