2 #@ Usage: ./cc-test.sh [--check-only [s-nail-binary]]
9 MAKE
="${MAKE:-`command -v make`}"
10 awk=${awk:-`command -v awk`}
11 cat=${cat:-`command -v cat`}
12 # TODO cksum not fixated via mk-conf.sh, mk.mk should export variables!!
13 cksum=${cksum:-`command -v cksum`}
14 rm=${rm:-`command -v rm`}
15 sed=${sed:-`command -v sed`}
16 grep=${grep:-`command -v grep`}
20 export SNAIL 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!)
27 LC_ALL
=${LC} LANG
=${LC}
29 export LC_ALL LANG ttycharset
34 echo >&2 "Usage: ./cc-test.sh [--check-only [s-nail-binary]]"
40 [ "${1}" = --check-only ] || usage
41 [ ${#} -gt 2 ] && usage
42 [ ${#} -eq 2 ] && SNAIL
="${2}"
43 [ -x "${SNAIL}" ] || usage
48 # Test all configs TODO doesn't cover all *combinations*, stupid!
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 =
57 $1 = substr($1, 1, index($1, "=") - 1)
58 if ($1 == "WANT_AUTOCC")
63 for (j = 0; j < i; ++j) {
64 for (k = 0; k < j; ++k)
66 for (k = j; k < i; ++k)
68 printf "WANT_AUTOCC=1\n"
70 for (k = 0; k < j; ++k)
72 for (k = j; k < i; ++k)
74 printf "WANT_AUTOCC=1\n"
78 printf "\n\n##########\n$c\n"
79 printf "\n\n##########\n$c\n" >&2
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
90 tid
=${1} f=${2} s=${3}
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
99 printf 'error: checksum mismatch (got %s)\n' "${csum}"
106 MAILRC
=/dev
/null
"${SNAIL}" -n -# |
112 # Basic (easily testable) behaviour tests
116 printf 'echo +nix\nset folder=/\necho +nix\nset nofolder\necho +nix\nx' |
117 MAILRC
=/dev
/null
"${SNAIL}" -n -# -SPAGER="${cat}" > "${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
126 have_feat SSL
/TLS
&& have_feat S
/MIME
&& __behave_smime
130 # Nestable conditions test
132 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
154 if $dietcurd == 'yoho'
159 if $dietcurd != 'yoho'
220 if $dietcurd == 'yohu'
222 elif $dietcurd == 'yoha'
224 elif $dietcurd == 'yohe'
226 elif $dietcurd == 'yoho'
228 if $dietcurd == 'yohu'
230 elif $dietcurd == 'yoha'
232 elif $dietcurd == 'yohe'
234 elif $dietcurd == 'yoho'
236 if $dietcurd == 'yohu'
238 elif $dietcurd == 'yoha'
240 elif $dietcurd == 'yohe'
242 elif $dietcurd == 'yoho'
254 cksum_test behave:if-normal "${MBOX}" '2760114576 119'
256 if have_feat REGEX; then
258 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
260 if $dietcurd =~
'^yo.*'
265 if $dietcurd =~
'^yoho.+'
270 if $dietcurd !~
'.*ho$'
275 if $dietcurd !~
'.+yoho$'
281 cksum_test behave
:if-regex
"${MBOX}" '3930005258 20'
285 __behave_smime
() { # FIXME add test/ dir, unroll tests therein, regular enable!
286 printf 'behave:s/mime: .. generating test key and certificate ..\n'
287 ${cat} <<-_EOT > ./t.conf
290 default_keyfile = keyfile.pem
291 distinguished_name = req_distinguished_name
292 attributes = req_attributes
296 [ req_distinguished_name ]
303 emailAddress = test@localhost
308 openssl req
-x509 -nodes -days 3650 -config .
/t.conf \
309 -newkey rsa
:1024 -keyout .
/tkey.pem
-out .
/tcert.pem
>/dev
/null
2>&1
311 ${cat} .
/tkey.pem .
/tcert.pem
> .
/tpair.pem
313 printf "behave:s/mime:sign/verify: "
315 MAILRC
=/dev
/null .
/s-nail
-n# \
316 -Ssmime-ca-file=.
/tcert.pem
-Ssmime-sign-cert=.
/tpair.pem \
317 -Ssmime-sign -Sfrom=test@localhost \
318 -s 'S/MIME test' .
/VERIFY
320 printf 'verify\nx\n' |
321 MAILRC
=/dev
/null .
/s-nail
-n# \
322 -Ssmime-ca-file=.
/tcert.pem
-Ssmime-sign-cert=.
/tpair.pem \
323 -Ssmime-sign -Sfrom=test@localhost \
324 -Sbatch-exit-on-error -R \
325 -f .
/VERIFY
>/dev
/null
2>&1
326 if [ $?
-eq 0 ]; then
330 printf 'error: verification failed\n'
331 ${rm} -f .
/VERIFY .
/tkey.pem .
/tcert.pem .
/tpair.pem
336 printf "behave:s/mime:encrypt/decrypt: "
337 ${cat} <<-_EOT > ./tsendmail.sh
339 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
341 chmod 0755 .
/tsendmail.sh
344 MAILRC
=/dev
/null .
/s-nail
-n# \
345 -Ssmime-force-encryption \
346 -Ssmime-encrypt-recei@ver.com
=.
/tpair.pem \
347 -Ssendmail=.
/tsendmail.sh \
348 -Ssmime-ca-file=.
/tcert.pem
-Ssmime-sign-cert=.
/tpair.pem \
349 -Ssmime-sign -Sfrom=test@localhost \
350 -s 'S/MIME test' recei@ver.com
352 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
353 MAILRC
=/dev
/null .
/s-nail
-n# \
354 -Ssmime-force-encryption \
355 -Ssmime-encrypt-recei@ver.com
=.
/tpair.pem \
356 -Ssendmail=.
/tsendmail.sh \
357 -Ssmime-ca-file=.
/tcert.pem
-Ssmime-sign-cert=.
/tpair.pem \
358 -Ssmime-sign -Sfrom=test@localhost \
359 -Sbatch-exit-on-error -R \
360 -f .
/ENCRYPT
>/dev
/null
2>&1
361 if [ $?
-eq 0 ]; then
365 printf 'error: decryption+verification failed\n'
367 ${rm} -f .
/tsendmail.sh .
/ENCRYPT .
/DECRYPT \
368 .
/tkey.pem .
/tcert.pem .
/tpair.pem
372 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
373 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
374 # Note we unfortunately need to place some statements without proper
375 # indentation because of continuation problems
377 ${rm} -f "${BODY}" "${MBOX}"
379 # MIME CTE (QP) stress message body
381 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
382 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
383 "wasde willst
, gelle
, gelle
, gelle
, gelle
, gelle.
\r\n"\
384 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
\r\n"\
385 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1\r\n"\
386 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12\r\n"\
387 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123\r\n"\
388 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234\r\n"\
389 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345\r\n"\
390 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456\r\n"\
391 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234567\r\n"\
392 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345678\r\n"\
393 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456789\r\n"\
394 "Unn ausserdem habe ich trailing SP
/HT
/SP
/HT whitespace
\r\n"\
395 "Unn ausserdem habe ich trailing HT
/SP
/HT
/SP whitespace
\r\n"\
396 "auf den zeilen vorher.
\r\n"\
397 "From am Zeilenbeginn und From der Mitte gibt es auch.
\r\n"\
399 "Die letzte Zeile war nur ein Punkt.
\r\n"\
401 "Das waren deren zwei.
\r\n"\
403 "Die letzte Zeile war ein Leerschritt.
\n"\
404 "=VIER
= EQUAL SIGNS
=ON A LINE
=\r\n"\
407 "Die letzte Zeile war nur ein Punkt
, mit Unix Zeilenende.
\n"\
409 "Das waren deren zwei. ditto.
\n"\
411 "Unn ausseerdem habe ich trailing SP
/HT
/SP
/HT whitespace
\n"\
412 "Unn ausseerdem habe ich trailing HT
/SP
/HT
/SP whitespace
\n"\
413 "auf den zeilen vorher.
\n"\
415 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende.
\n"\
416 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.1"\
418 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
420 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
422 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
424 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
426 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
428 "=VIER
= EQUAL SIGNS
=ON A LINE
=\n"\
430 "Die letzte Zeile war ein Leerschritt.
\n"\
434 # MIME CTE (QP) stress message subject
435 SUB="Äbrä Kä?dä
=brö Fü?di
=bus? \
436 adadaddsssssssddddddddddddddddddddd\
437 ddddddddddddddddddddddddddddddddddd\
438 ddddddddddddddddddddddddddddddddddd\
439 dddddddddddddddddddd Hallelulja? Od\
440 er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
441 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
442 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f\
443 fffffffffffffffffffffffffffffffffff\
444 fffffffffffffffffffff ggggggggggggg\
445 ggggggggggggggggggggggggggggggggggg\
446 ggggggggggggggggggggggggggggggggggg\
447 ggggggggggggggggggggggggggggggggggg\
450 # Three tests for MIME-CTE and (a bit) content classification.
451 # At the same time testing -q FILE, < FILE and -t FILE
453 < "${BODY}" MAILRC=/dev/null \
454 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
455 cksum_test content:001 "${MBOX}" '2289641826 5632'
458 < /dev/null MAILRC=/dev/null \
459 "${SNAIL}" -n#Sstealthmua -a "${BODY}" -s "${SUB}" \
460 -q "${BODY}" "${MBOX}"
461 cksum_test content:002 "${MBOX}" '2289641826 5632'
464 ( echo "To
: ${MBOX}" && echo "Subject
: ${SUB}" && echo &&
466 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
467 cksum_test content:003 "${MBOX}" '2898659780 5631'
469 # Test for [260e19d] (Juergen Daubert)
471 echo body | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua "${MBOX}"
472 cksum_test content:004 "${MBOX}" '506144051 104'
474 # Sending of multiple mails in a single invocation
476 ( printf "m
${MBOX}\n~s subject1
\nE
-Mail Körper
1\n.
\n" &&
477 printf "m
${MBOX}\n~s subject2
\nEmail body
2\n.
\n" &&
479 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
480 cksum_test content:005 "${MBOX}" '2028749685 277'
484 # "Test
for" [d6f316a] (Gavin Troy)
486 printf "m
${MBOX}\n~s subject1
\nEmail body
\n.
\nfi
${MBOX}\np
\nx
\n" |
487 MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua \
488 -SPAGER="${cat}" -Spipe-text/plain="${cat}" > "${BODY}"
489 ${sed} -e 1d < "${BODY}" > "${MBOX}"
490 cksum_test content
:006 "${MBOX}" '1520300594 138'
492 # "Test for" [c299c45] (Peter Hofmann) TODO shouldn't end up QP-encoded?
494 LC_ALL
=C
${awk} 'BEGIN{
495 for(i = 0; i < 10000; ++i)
497 #printf "\xF0\x90\x87\x90"
499 MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua -s TestSubject
"${MBOX}"
500 cksum_test content
:007 "${MBOX}" '2747333583 61729'
502 ## Test some more corner cases for header bodies (as good as we can today) ##
507 MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua \
508 -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̲' \
510 cksum_test content
:008 "${MBOX}" '1428748699 320'
512 # Single word (overlong line split -- bad standard! Requires injection of
513 # artificial data!! Bad can be prevented by using RFC 2047 encoding)
515 i
=`LC_ALL=C ${awk} 'BEGIN{for(i=0; i<92; ++i) printf "0123456789_"}'`
516 echo | MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua -s "${i}" "${MBOX}"
517 cksum_test content
:009 "${MBOX}" '141403131 1663'
519 # Combination of encoded words, space and tabs of varying sort
521 echo | MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua \
522 -s "1Abrä Kaspas1 2Abra Katä b_kaspas2 \
523 3Abrä Kaspas3 4Abrä Kaspas4 5Abrä Kaspas5 \
524 6Abra Kaspas6 7Abrä Kaspas7 8Abra Kaspas8 \
525 9Abra Kaspastäb4-3 10Abra Kaspas1 _ 11Abra Katäb1 \
526 12Abra Kadabrä1 After Tab after Täb this is NUTS" \
528 cksum_test content
:010 "${MBOX}" '2324198710 536'
530 # Overlong multibyte sequence that must be forcefully split
531 # todo This works even before v15.0, but only by accident
533 echo | MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua \
534 -s "✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
535 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
536 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄" \
538 cksum_test content
:011 "${MBOX}" '3085014590 604'
543 MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua \
544 -s "1-1 B2 B3 B4 B5 B6 B\
545 1-2 B2 B3 B4 B5 B6 B\
546 1-3 B2 B3 B4 B5 B6 B\
547 1-4 B2 B3 B4 B5 B6 B\
548 1-5 B2 B3 B4 B5 B6 B\
549 1-6 B2 B3 B4 B5 B6 " \
551 cksum_test content
:012 "${MBOX}" '2868799725 303'
553 # Leading and trailing WS
556 MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua \
557 -s " 2-1 B2 B3 B4 B5 B6 B\
558 1-2 B2 B3 B4 B5 B6 B\
559 1-3 B2 B3 B4 B5 B6 B\
560 1-4 B2 B3 B4 B5 B6 " \
562 cksum_test content
:013 "${MBOX}" '3962521045 243'
564 ${rm} -f "${BODY}" "${MBOX}"
572 if [ -z "${CHECK_ONLY}" ]; then
578 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'