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