Fix false resource release <-> double free (Bob Tennent)..
[s-mailx.git] / cc-test.sh
blob003ff7423325cf4a5bae741aee37c1d649ea45bf
1 #!/bin/sh -
2 #@ Usage: ./cc-test.sh [--check-only [s-nail-binary]]
4 SNAIL=./s-nail
5 ARGS='-n# -Sstealthmua -Sexpandaddr=restrict'
6 CONF=./make.rc
7 BODY=./.cc-body.txt
8 MBOX=./.cc-test.mbox
10 MAKE="${MAKE:-`command -v make`}"
11 awk=${awk:-`command -v awk`}
12 cat=${cat:-`command -v cat`}
13 cksum=${cksum:-`command -v cksum`}
14 rm=${rm:-`command -v rm`}
15 sed=${sed:-`command -v sed`}
16 grep=${grep:-`command -v grep`}
18 ## -- >8 -- 8< -- ##
20 export SNAIL ARGS CONF BODY MBOX MAKE awk cat cksum rm sed grep
22 # NOTE! UnixWare 7.1.4 gives ISO-10646-Minimum-European-Subset for
23 # nl_langinfo(CODESET), then, so also overwrite ttycharset.
24 # (In addition this setup allows us to succeed on TinyCore 4.4 that has no
25 # other locales than C/POSIX installed by default!)
26 LC=en_US.UTF-8
27 LC_ALL=${LC} LANG=${LC}
28 ttycharset=UTF-8
29 export LC_ALL LANG ttycharset
31 ESTAT=0
33 usage() {
34 echo >&2 "Usage: ./cc-test.sh [--check-only [s-nail-binary]]"
35 exit 1
38 CHECK_ONLY=
39 [ ${#} -gt 0 ] && {
40 [ "${1}" = --check-only ] || usage
41 [ ${#} -gt 2 ] && usage
42 [ ${#} -eq 2 ] && SNAIL="${2}"
43 [ -x "${SNAIL}" ] || usage
44 CHECK_ONLY=1
47 # cc_all_configs()
48 # Test all configs TODO doesn't cover all *combinations*, stupid!
49 cc_all_configs() {
50 < ${CONF} ${awk} '
51 BEGIN {i = 0}
52 /^[[:space:]]*WANT_/ {
53 sub(/^[[:space:]]*/, "")
54 # This bails for UnixWare 7.1.4 awk(1), but preceeding = with \
55 # does not seem to be a compliant escape for =
56 #sub(/=.*$/, "")
57 $1 = substr($1, 1, index($1, "=") - 1)
58 if ($1 == "WANT_AUTOCC")
59 next
60 data[i++] = $1
62 END {
63 for (j = 1; j < i; ++j) {
64 for (k = 1; k < j; ++k)
65 printf data[k] "=1 "
66 for (k = j; k < i; ++k)
67 printf data[k] "=0 "
68 printf "WANT_AUTOCC=1\n"
70 for (k = 1; k < j; ++k)
71 printf data[k] "=0 "
72 for (k = j; k < i; ++k)
73 printf data[k] "=1 "
74 printf "WANT_AUTOCC=1\n"
77 ' | while read c; do
78 printf "\n\n##########\n$c\n"
79 printf "\n\n##########\n$c\n" >&2
80 sh -c "${MAKE} ${c}"
81 t_all
82 ${MAKE} distclean
83 done
86 # cksum_test()
87 # Read mailbox $2, strip non-constant headers and MIME boundaries, query the
88 # cksum(1) of the resulting data and compare against the checksum $3
89 cksum_test() {
90 tid=${1} f=${2} s=${3}
91 printf "${tid}: "
92 csum="`${sed} -e '/^From /d' -e '/^Date: /d' \
93 -e '/^ boundary=/d' -e '/^--=-=/d' < \"${f}\" \
94 -e '/^\[-- Message/d' | ${cksum}`";
95 if [ "${csum}" = "${s}" ]; then
96 printf 'ok\n'
97 else
98 ESTAT=1
99 printf 'error: checksum mismatch (got %s)\n' "${csum}"
103 have_feat() {
105 echo 'feat' |
106 MAILRC=/dev/null "${SNAIL}" ${ARGS} |
107 ${grep} ${1}
108 ) >/dev/null 2>&1
111 # t_behave()
112 # Basic (easily testable) behaviour tests
113 t_behave() {
114 # Test for [d1f1a19]
115 ${rm} -f "${MBOX}"
116 printf 'echo +nix\nset folder=/\necho +nix\nset nofolder\necho +nix\nx' |
117 MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
118 cksum_test behave:001 "${MBOX}" '4214021069 15'
120 # POSIX: setting *noprompt*/prompt='' shall prevent prompting TODO
121 # TODO for this to be testable we need a way to echo a variable
122 # TODO or to force echo of the prompt
124 __behave_ifelse
126 # FIXME __behave_alias
128 # FIXME __behave_mlist
130 have_feat SSL/TLS && have_feat S/MIME && __behave_smime
133 __behave_ifelse() {
134 # Nestable conditions test
135 ${rm} -f "${MBOX}"
136 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
137 if 0
138 echo 1.err
139 else
140 echo 1.ok
141 endif
142 if 1
143 echo 2.ok
144 else
145 echo 2.err
146 endif
147 if $dietcurd
148 echo 3.err
149 else
150 echo 3.ok
151 endif
152 set dietcurd=yoho
153 if $dietcurd
154 echo 4.ok
155 else
156 echo 4.err
157 endif
158 if $dietcurd == 'yoho'
159 echo 5.ok
160 else
161 echo 5.err
162 endif
163 if $dietcurd != 'yoho'
164 echo 6.err
165 else
166 echo 6.ok
167 endif
168 # Nesting
169 if faLse
170 echo 7.err1
171 if tRue
172 echo 7.err2
173 if yEs
174 echo 7.err3
175 else
176 echo 7.err4
177 endif
178 echo 7.err5
179 endif
180 echo 7.err6
181 else
182 echo 7.ok7
183 if YeS
184 echo 7.ok8
185 if No
186 echo 7.err9
187 else
188 echo 7.ok9
189 endif
190 echo 7.ok10
191 else
192 echo 7.err11
193 if yeS
194 echo 7.err12
195 else
196 echo 7.err13
197 endif
198 endif
199 echo 7.ok14
200 endif
201 if r
202 echo 8.ok1
203 if R
204 echo 8.ok2
205 else
206 echo 8.err2
207 endif
208 echo 8.ok3
209 else
210 echo 8.err1
211 endif
212 if s
213 echo 9.err1
214 else
215 echo 9.ok1
216 if S
217 echo 9.err2
218 else
219 echo 9.ok2
220 endif
221 echo 9.ok3
222 endif
223 # `elif'
224 if $dietcurd == 'yohu'
225 echo 10.err1
226 elif $dietcurd == 'yoha'
227 echo 10.err2
228 elif $dietcurd == 'yohe'
229 echo 10.err3
230 elif $dietcurd == 'yoho'
231 echo 10.ok1
232 if $dietcurd == 'yohu'
233 echo 10.err4
234 elif $dietcurd == 'yoha'
235 echo 10.err5
236 elif $dietcurd == 'yohe'
237 echo 10.err6
238 elif $dietcurd == 'yoho'
239 echo 10.ok2
240 if $dietcurd == 'yohu'
241 echo 10.err7
242 elif $dietcurd == 'yoha'
243 echo 10.err8
244 elif $dietcurd == 'yohe'
245 echo 10.err9
246 elif $dietcurd == 'yoho'
247 echo 10.ok3
248 else
249 echo 10.err10
250 endif
251 else
252 echo 10.err11
253 endif
254 else
255 echo 10.err12
256 endif
257 # integer conversion, <..>..
258 set dietcurd=10
259 if $dietcurd < 11
260 echo 11.ok1
261 if $dietcurd > 9
262 echo 11.ok2
263 else
264 echo 11.err2
265 endif
266 if $dietcurd == 10
267 echo 11.ok3
268 else
269 echo 11.err3
270 endif
271 if $dietcurd >= 10
272 echo 11.ok4
273 else
274 echo 11.err4
275 endif
276 if $dietcurd <= 10
277 echo 11.ok5
278 else
279 echo 11.err5
280 endif
281 if $dietcurd >= 11
282 echo 11.err6
283 else
284 echo 11.ok6
285 endif
286 if $dietcurd <= 9
287 echo 11.err7
288 else
289 echo 11.ok7
290 endif
291 else
292 echo 11.err1
293 endif
294 set dietcurd=Abc
295 if $dietcurd < aBd
296 echo 12.ok1
297 if $dietcurd > abB
298 echo 12.ok2
299 else
300 echo 12.err2
301 endif
302 if $dietcurd == aBC
303 echo 12.ok3
304 else
305 echo 12.err3
306 endif
307 if $dietcurd >= AbC
308 echo 12.ok4
309 else
310 echo 12.err4
311 endif
312 if $dietcurd <= ABc
313 echo 12.ok5
314 else
315 echo 12.err5
316 endif
317 if $dietcurd >= abd
318 echo 12.err6
319 else
320 echo 12.ok6
321 endif
322 if $dietcurd <= abb
323 echo 12.err7
324 else
325 echo 12.ok7
326 endif
327 else
328 echo 12.err1
329 endif
330 if $dietcurd =@ aB
331 echo 13.ok
332 else
333 echo 13.err
334 endif
335 if $dietcurd =@ bC
336 echo 14.ok
337 else
338 echo 14.err
339 endif
340 if $dietcurd !@ aB
341 echo 15.err
342 else
343 echo 15.ok
344 endif
345 if $dietcurd !@ bC
346 echo 15.err
347 else
348 echo 15.ok
349 endif
350 if $dietcurd =@ Cd
351 echo 16.err
352 else
353 echo 16.ok
354 endif
355 if $dietcurd !@ Cd
356 echo 17.ok
357 else
358 echo 17.err
359 endif
360 set diet=abc curd=abc
361 if $diet == $curd
362 echo 18.ok
363 else
364 echo 18.err
365 endif
366 set diet=abc curd=abcd
367 if $diet != $curd
368 echo 19.ok
369 else
370 echo 19.err
371 endif
372 # 1. Shitty grouping capabilities as of today
373 unset diet curd ndefined
374 if [ [ false ] || [ false ] || [ true ] ] && [ [ false ] || [ true ] ] && \
375 [ yes ]
376 echo 20.ok
377 else
378 echo 20.err
379 endif
380 if [ [ [ [ 0 ] || [ 1 ] ] && [ [ 1 ] || [ 0 ] ] ] && [ 1 ] ] && [ yes ]
381 echo 21.ok
382 else
383 echo 21.err
384 endif
385 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] ]
386 echo 22.ok
387 else
388 echo 22.err
389 endif
390 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] ]
391 echo 23.ok
392 else
393 echo 23.err
394 endif
395 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] || [ 1 ] ] && [ no ]
396 echo 24.err
397 else
398 echo 24.ok
399 endif
400 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] || [ 1 ] ] \
401 && [ no ] || [ yes ]
402 echo 25.ok
403 else
404 echo 25.err
405 endif
406 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 1 ] ]
407 echo 26.ok
408 else
409 echo 26.err
410 endif
411 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 0 ] ]
412 echo 27.err
413 else
414 echo 27.ok
415 endif
416 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 0 ] ] && [ 1 ] ] ] && [ 1 ] ]
417 echo 28.err
418 else
419 echo 28.ok
420 endif
421 if [ [ [ [ [ [ [ 0 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 1 ] ]
422 echo 29.err
423 else
424 echo 29.ok
425 endif
426 if [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] && [ 0 ]
427 echo 30.err
428 else
429 echo 30.ok
430 endif
431 if [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] && [ 1 ]
432 echo 31.ok
433 else
434 echo 31.err
435 endif
436 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ]
437 echo 32.err
438 else
439 echo 32.ok
440 endif
441 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 1 ]
442 echo 33.ok
443 else
444 echo 33.err
445 endif
446 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ] || [ 1 ] && [ 0 ]
447 echo 34.err
448 else
449 echo 34.ok
450 endif
451 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ] || [ 1 ] && [ 1 ]
452 echo 35.ok
453 else
454 echo 35.err
455 endif
456 set diet=yo curd=ho
457 if [ [ $diet == 'yo' ] && [ $curd == 'ho' ] ] && [ $ndefined ]
458 echo 36.err
459 else
460 echo 36.ok
461 endif
462 set ndefined
463 if [ [ $diet == 'yo' ] && [ $curd == 'ho' ] ] && [ $ndefined ]
464 echo 37.ok
465 else
466 echo 37.err
467 endif
468 # 2. Shitty grouping capabilities as of today
469 unset diet curd ndefined
470 if [ false || false || true ] && [ false || true ] && yes
471 echo 40.ok
472 else
473 echo 40.err
474 endif
475 if [ [ [ 0 || 1 ] && [ 1 || 0 ] ] && 1 ] && [ yes ]
476 echo 41.ok
477 else
478 echo 41.err
479 endif
480 if [ 1 || 0 || 0 || 0 ]
481 echo 42.ok
482 else
483 echo 42.err
484 endif
485 if [ 1 || 0 || 0 || 0 || [ 1 ] ]
486 echo 43.ok
487 else
488 echo 43.err
489 endif
490 if [ 1 || 0 || 0 || 0 || [ 1 ] || 1 ] && no
491 echo 44.err
492 else
493 echo 44.ok
494 endif
495 if [ 1 || 0 || 0 || 0 || 1 || [ 1 ] ] && no || [ yes ]
496 echo 45.ok
497 else
498 echo 45.err
499 endif
500 if [ [ [ [ [ [ 1 ] && 1 ] && 1 ] && 1 ] ] && [ 1 ] ]
501 echo 46.ok
502 else
503 echo 46.err
504 endif
505 if [ [ [ [ [ [ 1 ] && 1 ] && 1 ] && [ 1 ] ] ] && 0 ]
506 echo 47.err
507 else
508 echo 47.ok
509 endif
510 if [ [ [ [ [ [ [ 1 ] ] && 1 ] && 0 ] && [ 1 ] ] ] && 1 ]
511 echo 48.err
512 else
513 echo 48.ok
514 endif
515 if [ [ [ [ [ [ 0 ] && 1 ] && 1 ] && 1 ] ] && 1 ]
516 echo 49.err
517 else
518 echo 49.ok
519 endif
520 if 1 || 0 || 0 || 0 && 0
521 echo 50.err
522 else
523 echo 50.ok
524 endif
525 if 1 || 0 || 0 || 0 && 1
526 echo 51.ok
527 else
528 echo 51.err
529 endif
530 if 0 || 0 || 0 || 1 && 0
531 echo 52.err
532 else
533 echo 52.ok
534 endif
535 if 0 || 0 || 0 || 1 && 1
536 echo 53.ok
537 else
538 echo 53.err
539 endif
540 if 0 || 0 || 0 || 1 && 0 || 1 && 0
541 echo 54.err
542 else
543 echo 54.ok
544 endif
545 if 0 || 0 || 0 || 1 && 0 || 1 && 1
546 echo 55.ok
547 else
548 echo 55.err
549 endif
550 set diet=yo curd=ho
551 if [ $diet == 'yo' && $curd == 'ho' ] && $ndefined
552 echo 56.err
553 else
554 echo 56.ok
555 endif
556 if $diet == 'yo' && $curd == 'ho' && $ndefined
557 echo 57.err
558 else
559 echo 57.ok
560 endif
561 set ndefined
562 if [ $diet == 'yo' && $curd == 'ho' ] && $ndefined
563 echo 57.ok
564 else
565 echo 57.err
566 endif
567 if $diet == 'yo' && $curd == 'ho' && $ndefined
568 echo 58.ok
569 else
570 echo 58.err
571 endif
572 if [ [ [ [ [ [ $diet == 'yo' && $curd == 'ho' && $ndefined ] ] ] ] ] ]
573 echo 59.ok
574 else
575 echo 59.err
576 endif
577 # Unary !
578 if ! 0 && ! ! 1 && ! ! ! ! 2 && 3
579 echo 80.ok
580 else
581 echo 80.err
582 endif
583 if ! 0 && ! [ ! 1 ] && ! [ ! [ ! [ ! 2 ] ] ] && 3
584 echo 81.ok
585 else
586 echo 81.err
587 endif
588 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
589 echo 82.ok
590 else
591 echo 82.err
592 endif
593 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && ! 3
594 echo 83.err
595 else
596 echo 83.ok
597 endif
598 if [ ! 0 ] && [ ! [ ! 1 ] ] && ! [ [ ! [ ! [ ! [ 2 ] ] ] ] ] && ! 3
599 echo 84.err
600 else
601 echo 84.ok
602 endif
603 if [ ! 0 ] && ! [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
604 echo 85.err
605 else
606 echo 85.ok
607 endif
608 if ! [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
609 echo 86.err
610 else
611 echo 86.ok
612 endif
613 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] || 3
614 echo 87.ok
615 else
616 echo 87.err
617 endif
618 if [ ! 0 ] && [ ! ! [ ! ! 1 ] ] && [ ! ! [ ! ! [ ! ! [ ! ! [ 2 ] ] ] ] ]
619 echo 88.ok
620 else
621 echo 88.err
622 endif
623 # Unary !, odd
624 if ! 0 && ! ! 1 && ! ! ! 0 && 3
625 echo 90.ok
626 else
627 echo 90.err
628 endif
629 if ! 0 && ! [ ! 1 ] && ! [ ! [ ! [ 0 ] ] ] && 3
630 echo 91.ok
631 else
632 echo 91.err
633 endif
634 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ [ 0 ] ] ] ] ] && 3
635 echo 92.ok
636 else
637 echo 92.err
638 endif
639 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! ! [ ! [ ! 0 ] ] ] ] && ! 3
640 echo 93.err
641 else
642 echo 93.ok
643 endif
644 if [ ! 0 ] && [ ! [ ! 1 ] ] && ! [ ! [ ! [ ! [ ! 0 ] ] ] ] && 3
645 echo 94.ok
646 else
647 echo 94.err
648 endif
649 if [ ! 0 ] && ! [ ! [ ! 1 ] ] && [ ! ! [ ! [ ! [ ! [ 0 ] ] ] ] ] && 3
650 echo 95.err
651 else
652 echo 95.ok
653 endif
654 if ! [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! ! 0 ] ] ] ] && 3
655 echo 96.err
656 else
657 echo 96.ok
658 endif
659 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ ! 0 ] ] ] ] ] || 3
660 echo 97.ok
661 else
662 echo 97.err
663 endif
664 if [ ! 0 ] && [ ! ! [ ! ! 1 ] ] && [ ! ! [ ! ! [ ! ! [ ! [ 0 ] ] ] ] ]
665 echo 98.ok
666 else
667 echo 98.err
668 endif
669 __EOT
670 cksum_test behave:if-normal "${MBOX}" '3542193361 607'
672 if have_feat REGEX; then
673 ${rm} -f "${MBOX}"
674 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
675 set dietcurd=yoho
676 if $dietcurd =~ '^yo.*'
677 echo 1.ok
678 else
679 echo 1.err
680 endif
681 if $dietcurd =~ '^yoho.+'
682 echo 2.err
683 else
684 echo 2.ok
685 endif
686 if $dietcurd !~ '.*ho$'
687 echo 3.err
688 else
689 echo 3.ok
690 endif
691 if $dietcurd !~ '.+yoho$'
692 echo 4.ok
693 else
694 echo 4.err
695 endif
696 if [ $dietcurd !~ '.+yoho$' ]
697 echo 5.ok
698 else
699 echo 5.err
700 endif
701 if ! [ $dietcurd =~ '.+yoho$' ]
702 echo 6.ok
703 else
704 echo 6.err
705 endif
706 if ! ! [ $dietcurd !~ '.+yoho$' ]
707 echo 7.ok
708 else
709 echo 7.err
710 endif
711 if ! [ ! [ $dietcurd !~ '.+yoho$' ] ]
712 echo 8.ok
713 else
714 echo 8.err
715 endif
716 if [ ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
717 echo 9.ok
718 else
719 echo 9.err
720 endif
721 if ! [ ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
722 echo 10.err
723 else
724 echo 10.ok
725 endif
726 if ! ! ! $dietcurd !~ '.+yoho$'
727 echo 11.err
728 else
729 echo 11.ok
730 endif
731 if ! ! ! $dietcurd =~ '.+yoho$'
732 echo 12.ok
733 else
734 echo 12.err
735 endif
736 if ! [ ! ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
737 echo 13.ok
738 else
739 echo 13.err
740 endif
741 set diet=abc curd='^abc$'
742 if $diet =~ $curd
743 echo 14.ok
744 else
745 echo 14.err
746 endif
747 set diet=abc curd='^abcd$'
748 if $diet !~ $curd
749 echo 15.ok
750 else
751 echo 15.err
752 endif
753 __EOT
754 cksum_test behave:if-regex "${MBOX}" '439960016 81'
758 __behave_smime() { # FIXME add test/ dir, unroll tests therein, regular enable!
759 printf 'behave:s/mime: .. generating test key and certificate ..\n'
760 ${cat} <<-_EOT > ./t.conf
761 [ req ]
762 default_bits = 1024
763 default_keyfile = keyfile.pem
764 distinguished_name = req_distinguished_name
765 attributes = req_attributes
766 prompt = no
767 output_password =
769 [ req_distinguished_name ]
770 C = GB
771 ST = Over the
772 L = rainbow
773 O = S-nail
774 OU = S-nail.smime
775 CN = S-nail.test
776 emailAddress = test@localhost
778 [ req_attributes ]
779 challengePassword =
780 _EOT
781 openssl req -x509 -nodes -days 3650 -config ./t.conf \
782 -newkey rsa:1024 -keyout ./tkey.pem -out ./tcert.pem >/dev/null 2>&1
783 ${rm} -f ./t.conf
784 ${cat} ./tkey.pem ./tcert.pem > ./tpair.pem
786 printf "behave:s/mime:sign/verify: "
787 echo bla |
788 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
789 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
790 -Ssmime-sign -Sfrom=test@localhost \
791 -s 'S/MIME test' ./VERIFY
792 # TODO CHECK
793 printf 'verify\nx\n' |
794 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
795 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
796 -Ssmime-sign -Sfrom=test@localhost \
797 -Sbatch-exit-on-error -R \
798 -f ./VERIFY >/dev/null 2>&1
799 if [ $? -eq 0 ]; then
800 printf 'ok\n'
801 else
802 ESTAT=1
803 printf 'error: verification failed\n'
804 ${rm} -f ./VERIFY ./tkey.pem ./tcert.pem ./tpair.pem
805 return
807 ${rm} -rf ./VERIFY
809 printf "behave:s/mime:encrypt/decrypt: "
810 ${cat} <<-_EOT > ./tsendmail.sh
811 #!/bin/sh -
812 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
813 _EOT
814 chmod 0755 ./tsendmail.sh
816 echo bla |
817 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
818 -Ssmime-force-encryption \
819 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
820 -Ssendmail=./tsendmail.sh \
821 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
822 -Ssmime-sign -Sfrom=test@localhost \
823 -s 'S/MIME test' recei@ver.com
824 # TODO CHECK
825 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
826 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
827 -Ssmime-force-encryption \
828 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
829 -Ssendmail=./tsendmail.sh \
830 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
831 -Ssmime-sign -Sfrom=test@localhost \
832 -Sbatch-exit-on-error -R \
833 -f ./ENCRYPT >/dev/null 2>&1
834 if [ $? -eq 0 ]; then
835 printf 'ok\n'
836 else
837 ESTAT=1
838 printf 'error: decryption+verification failed\n'
840 ${rm} -f ./tsendmail.sh ./ENCRYPT ./DECRYPT \
841 ./tkey.pem ./tcert.pem ./tpair.pem
844 # t_content()
845 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
846 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
847 # Note we unfortunately need to place some statements without proper
848 # indentation because of continuation problems
849 t_content() {
850 ${rm} -f "${BODY}" "${MBOX}"
852 # MIME encoding (QP) stress message body
853 printf \
854 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
855 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
856 "wasde willst, gelle, gelle, gelle, gelle, gelle.\r\n"\
857 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst \r\n"\
858 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1\r\n"\
859 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12\r\n"\
860 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123\r\n"\
861 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1234\r\n"\
862 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12345\r\n"\
863 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123456\r\n"\
864 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1234567\r\n"\
865 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12345678\r\n"\
866 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123456789\r\n"\
867 "Unn ausserdem habe ich trailing SP/HT/SP/HT whitespace \r\n"\
868 "Unn ausserdem habe ich trailing HT/SP/HT/SP whitespace \r\n"\
869 "auf den zeilen vorher.\r\n"\
870 "From am Zeilenbeginn und From der Mitte gibt es auch.\r\n"\
871 ".\r\n"\
872 "Die letzte Zeile war nur ein Punkt.\r\n"\
873 "..\r\n"\
874 "Das waren deren zwei.\r\n"\
875 " \r\n"\
876 "Die letzte Zeile war ein Leerschritt.\n"\
877 "=VIER = EQUAL SIGNS=ON A LINE=\r\n"\
878 "Prösterchen.\r\n"\
879 ".\n"\
880 "Die letzte Zeile war nur ein Punkt, mit Unix Zeilenende.\n"\
881 "..\n"\
882 "Das waren deren zwei. ditto.\n"\
883 "Prösterchen.\n"\
884 "Unn ausseerdem habe ich trailing SP/HT/SP/HT whitespace \n"\
885 "Unn ausseerdem habe ich trailing HT/SP/HT/SP whitespace \n"\
886 "auf den zeilen vorher.\n"\
887 "ditto.\n"\
888 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.\n"\
889 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.1"\
890 "\n"\
891 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
892 "\n"\
893 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
894 "3\n"\
895 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
896 "34\n"\
897 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
898 "345\n"\
899 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
900 "3456\n"\
901 "=VIER = EQUAL SIGNS=ON A LINE=\n"\
902 " \n"\
903 "Die letzte Zeile war ein Leerschritt.\n"\
904 ' '\
905 > "${BODY}"
907 # MIME encoding (QP) stress message subject
908 SUB="Äbrä Kä?dä=brö Fü?di=bus? \
909 adadaddsssssssddddddddddddddddddddd\
910 ddddddddddddddddddddddddddddddddddd\
911 ddddddddddddddddddddddddddddddddddd\
912 dddddddddddddddddddd Hallelulja? Od\
913 er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
914 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
915 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f\
916 fffffffffffffffffffffffffffffffffff\
917 fffffffffffffffffffff ggggggggggggg\
918 ggggggggggggggggggggggggggggggggggg\
919 ggggggggggggggggggggggggggggggggggg\
920 ggggggggggggggggggggggggggggggggggg\
921 gggggggggggggggg"
923 # Three tests for MIME encodign and (a bit) content classification.
924 # At the same time testing -q FILE, < FILE and -t FILE
926 # TODO Note: because of our weird putline() handling in <-> collect.c
927 ${rm} -f "${MBOX}"
928 < "${BODY}" MAILRC=/dev/null \
929 "${SNAIL}" -nSstealthmua -Sexpandaddr -a "${BODY}" -s "${SUB}" "${MBOX}"
930 cksum_test content:001-0 "${MBOX}" '3498258986 5631'
932 ${rm} -f "${MBOX}"
933 < "${BODY}" MAILRC=/dev/null \
934 "${SNAIL}" ${ARGS} -Snodot -a "${BODY}" -s "${SUB}" "${MBOX}"
935 cksum_test content:001 "${MBOX}" '3916146590 5630'
937 ${rm} -f "${MBOX}"
938 < /dev/null MAILRC=/dev/null \
939 "${SNAIL}" ${ARGS} -a "${BODY}" -s "${SUB}" \
940 -q "${BODY}" "${MBOX}"
941 cksum_test content:002 "${MBOX}" '3498258986 5631'
943 ${rm} -f "${MBOX}"
944 ( echo "To: ${MBOX}" && echo "Subject: ${SUB}" && echo &&
945 ${cat} "${BODY}"
946 ) | MAILRC=/dev/null "${SNAIL}" ${ARGS} -Snodot -a "${BODY}" -t
947 cksum_test content:003 "${MBOX}" '3916146590 5630'
949 # Test for [260e19d] (Juergen Daubert)
950 ${rm} -f "${MBOX}"
951 echo body | MAILRC=/dev/null "${SNAIL}" ${ARGS} "${MBOX}"
952 cksum_test content:004 "${MBOX}" '4140682175 72'
954 # Sending of multiple mails in a single invocation
955 ${rm} -f "${MBOX}"
956 ( printf "m ${MBOX}\n~s subject1\nE-Mail Körper 1\n.\n" &&
957 printf "m ${MBOX}\n~s subject2\nEmail body 2\n.\n" &&
958 echo x
959 ) | MAILRC=/dev/null "${SNAIL}" ${ARGS}
960 cksum_test content:005 "${MBOX}" '3503215815 245'
962 ## $BODY CHANGED
964 # "Test for" [d6f316a] (Gavin Troy)
965 ${rm} -f "${MBOX}"
966 printf "m ${MBOX}\n~s subject1\nEmail body\n.\nfi ${MBOX}\np\nx\n" |
967 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
968 -Spipe-text/plain="${cat}" > "${BODY}"
969 ${sed} -e 1d < "${BODY}" > "${MBOX}"
970 cksum_test content:006 "${MBOX}" '11112309 106'
972 # "Test for" [c299c45] (Peter Hofmann) TODO shouldn't end up QP-encoded?
973 # TODO Note: because of our weird putline() handling in <-> collect.c
974 ${rm} -f "${MBOX}"
975 LC_ALL=C ${awk} 'BEGIN{
976 for(i = 0; i < 10000; ++i)
977 printf "\xC3\xBC"
978 #printf "\xF0\x90\x87\x90"
979 }' |
980 MAILRC=/dev/null "${SNAIL}" -nSstealthmua -Sexpandaddr \
981 -s TestSubject "${MBOX}"
982 cksum_test content:007-0 "${MBOX}" '2747333583 61729'
984 ${rm} -f "${MBOX}"
985 LC_ALL=C ${awk} 'BEGIN{
986 for(i = 0; i < 10000; ++i)
987 printf "\xC3\xBC"
988 #printf "\xF0\x90\x87\x90"
989 }' |
990 MAILRC=/dev/null "${SNAIL}" ${ARGS} -s TestSubject "${MBOX}"
991 cksum_test content:007 "${MBOX}" '3343002941 61728'
993 ## Test some more corner cases for header bodies (as good as we can today) ##
996 ${rm} -f "${MBOX}"
997 echo |
998 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
999 -s 'a̲b̲c̲d̲e̲f̲h̲i̲k̲l̲m̲n̲o̲r̲s̲t̲u̲v̲w̲x̲z̲a̲b̲c̲d̲e̲f̲h̲i̲k̲l̲m̲n̲o̲r̲s̲t̲u̲v̲w̲x̲z̲' \
1000 "${MBOX}"
1001 cksum_test content:008 "${MBOX}" '3872015771 288'
1003 # Single word (overlong line split -- bad standard! Requires injection of
1004 # artificial data!! Bad can be prevented by using RFC 2047 encoding)
1005 ${rm} -f "${MBOX}"
1006 i=`LC_ALL=C ${awk} 'BEGIN{for(i=0; i<92; ++i) printf "0123456789_"}'`
1007 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} -s "${i}" "${MBOX}"
1008 cksum_test content:009 "${MBOX}" '2048460448 1631'
1010 # Combination of encoded words, space and tabs of varying sort
1011 ${rm} -f "${MBOX}"
1012 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1013 -s "1Abrä Kaspas1 2Abra Katä b_kaspas2 \
1014 3Abrä Kaspas3 4Abrä Kaspas4 5Abrä Kaspas5 \
1015 6Abra Kaspas6 7Abrä Kaspas7 8Abra Kaspas8 \
1016 9Abra Kaspastäb4-3 10Abra Kaspas1 _ 11Abra Katäb1 \
1017 12Abra Kadabrä1 After Tab after Täb this is NUTS" \
1018 "${MBOX}"
1019 cksum_test content:010 "${MBOX}" '1272213842 504'
1021 # Overlong multibyte sequence that must be forcefully split
1022 # todo This works even before v15.0, but only by accident
1023 ${rm} -f "${MBOX}"
1024 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1025 -s "✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
1026 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
1027 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄" \
1028 "${MBOX}"
1029 cksum_test content:011 "${MBOX}" '2972351879 572'
1031 # Trailing WS
1032 ${rm} -f "${MBOX}"
1033 echo |
1034 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1035 -s "1-1 B2 B3 B4 B5 B6 B\
1036 1-2 B2 B3 B4 B5 B6 B\
1037 1-3 B2 B3 B4 B5 B6 B\
1038 1-4 B2 B3 B4 B5 B6 B\
1039 1-5 B2 B3 B4 B5 B6 B\
1040 1-6 B2 B3 B4 B5 B6 " \
1041 "${MBOX}"
1042 cksum_test content:012 "${MBOX}" '1276108207 271'
1044 # Leading and trailing WS
1045 ${rm} -f "${MBOX}"
1046 echo |
1047 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1048 -s " 2-1 B2 B3 B4 B5 B6 B\
1049 1-2 B2 B3 B4 B5 B6 B\
1050 1-3 B2 B3 B4 B5 B6 B\
1051 1-4 B2 B3 B4 B5 B6 " \
1052 "${MBOX}"
1053 cksum_test content:013 "${MBOX}" '3677630181 210'
1055 # Quick'n dirty RFC 2231 test; i had more when implementing it, but until we
1056 # have a (better) test framework materialize a quick shot
1057 ${rm} -f "${MBOX}"
1058 : > "ma'ger.txt"
1059 : > "mä'ger.txt"
1060 : > 'diet\ is \curd.txt'
1061 : > diet \"is\" curd.txt
1062 : > höde-tröge.txt
1063 : > höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt
1064 : > höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt
1065 : > hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt
1066 : > ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt
1067 echo bla |
1068 MAILRC=/dev/null "${SNAIL}" ${ARGS} -Snodot \
1069 -a "ma'ger.txt" -a "mä'ger.txt" \
1070 -a 'diet\\\ is\ \\curd.txt' -a diet \"is\" curd.txt \
1071 -a höde-tröge.txt \
1072 -a höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt \
1073 -a höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt \
1074 -a hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt \
1075 -a ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt \
1076 "${MBOX}"
1077 ${rm} -f "ma'ger.txt" "mä'ger.txt" 'diet\ is \curd.txt' \
1078 diet \"is\" curd.txt höde-tröge.txt \
1079 höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt \
1080 höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt \
1081 hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt \
1082 ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt
1083 cksum_test content:14 "${MBOX}" '1106643854 2453'
1085 ${rm} -f "${BODY}" "${MBOX}"
1088 t_all() {
1089 if have_feat DEVEL; then
1090 ARGS="${ARGS} -Smemdebug"
1091 export ARGS
1093 t_behave
1094 t_content
1097 if [ -z "${CHECK_ONLY}" ]; then
1098 cc_all_configs
1099 else
1100 t_all
1103 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
1105 exit ${ESTAT}
1106 # s-sh-mode