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
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
:1 "${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 DEBUG
&& have_feat SSL
/TLS
&& have_feat S
/MIME
&&
131 # Nestable conditions test
133 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
155 if $dietcurd == 'yoho'
160 if $dietcurd != 'yoho'
221 if $dietcurd == 'yohu'
223 elif $dietcurd == 'yoha'
225 elif $dietcurd == 'yohe'
227 elif $dietcurd == 'yoho'
229 if $dietcurd == 'yohu'
231 elif $dietcurd == 'yoha'
233 elif $dietcurd == 'yohe'
235 elif $dietcurd == 'yoho'
237 if $dietcurd == 'yohu'
239 elif $dietcurd == 'yoha'
241 elif $dietcurd == 'yohe'
243 elif $dietcurd == 'yoho'
255 cksum_test behave:if-normal "${MBOX}" '2760114576 119'
257 if have_feat REGEX; then
259 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
261 if $dietcurd =~
'^yo.*'
266 if $dietcurd =~
'^yoho.+'
271 if $dietcurd !~
'.*ho$'
276 if $dietcurd !~
'.+yoho$'
282 cksum_test behave
:if-regex
"${MBOX}" '3930005258 20'
286 __behave_smime
() { # FIXME add test/ dir, unroll tests therein, regular enable!
287 echo WARNING
: behave_smime is yet debug only and not generalized
288 printf 'behave:s/mime: .. generating test key and certificate ..\n'
289 ${cat} <<-_EOT > t.conf
292 default_keyfile = keyfile.pem
293 distinguished_name = req_distinguished_name
294 attributes = req_attributes
298 [ req_distinguished_name ]
305 emailAddress = test@localhost
310 openssl req
-x509 -nodes -days 3650 -config t.conf \
311 -newkey rsa
:1024 -keyout tkey.pem
-out tcert.pem
>/dev
/null
2>&1
313 ${cat} tkey.pem tcert.pem
> tpair.pem
315 printf "behave:s/mime:sign/verify: "
317 MAILRC
=/dev
/null .
/s-nail
-n# \
318 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
319 -Ssmime-sign -Sfrom=test@localhost \
320 -s 'S/MIME test' .
/VERIFY
322 printf 'verify\nx\n' |
323 MAILRC
=/dev
/null .
/s-nail
-n# \
324 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
325 -Ssmime-sign -Sfrom=test@localhost \
326 -Sbatch-exit-on-error -R \
327 -f .
/VERIFY
>/dev
/null
2>&1
328 if [ $?
-eq 0 ]; then
332 printf 'error: verification failed\n'
333 ${rm} -f .
/VERIFY tkey.pem tcert.pem tpair.pem
338 printf "behave:s/mime:encrypt/decrypt: "
339 ${cat} <<-_EOT > tsendmail.sh
341 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
343 chmod 0755 tsendmail.sh
346 MAILRC
=/dev
/null .
/s-nail
-n# \
347 -Ssmime-force-encryption \
348 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
349 -Ssendmail=.
/tsendmail.sh \
350 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
351 -Ssmime-sign -Sfrom=test@localhost \
352 -s 'S/MIME test' recei@ver.com
354 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
355 MAILRC
=/dev
/null .
/s-nail
-n# \
356 -Ssmime-force-encryption \
357 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
358 -Ssendmail=.
/tsendmail.sh \
359 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
360 -Ssmime-sign -Sfrom=test@localhost \
361 -Sbatch-exit-on-error -R \
362 -f .
/ENCRYPT
>/dev
/null
2>&1
363 if [ $?
-eq 0 ]; then
367 printf 'error: decryption+verification failed\n'
369 ${rm} -f .
/tsendmail.sh .
/ENCRYPT .
/DECRYPT tkey.pem tcert.pem tpair.pem
373 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
374 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
375 # Note we unfortunately need to place some statements without proper
376 # indentation because of continuation problems
378 ${rm} -f "${BODY}" "${MBOX}"
380 # MIME CTE (QP) stress message body
382 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
383 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
384 "wasde willst
, gelle
, gelle
, gelle
, gelle
, gelle.
\r\n"\
385 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
\r\n"\
386 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1\r\n"\
387 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12\r\n"\
388 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123\r\n"\
389 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234\r\n"\
390 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345\r\n"\
391 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456\r\n"\
392 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234567\r\n"\
393 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345678\r\n"\
394 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456789\r\n"\
395 "Unn ausserdem habe ich trailing SP
/HT
/SP
/HT whitespace
\r\n"\
396 "Unn ausserdem habe ich trailing HT
/SP
/HT
/SP whitespace
\r\n"\
397 "auf den zeilen vorher.
\r\n"\
398 "From am Zeilenbeginn und From der Mitte gibt es auch.
\r\n"\
400 "Die letzte Zeile war nur ein Punkt.
\r\n"\
402 "Das waren deren zwei.
\r\n"\
404 "Die letzte Zeile war ein Leerschritt.
\n"\
405 "=VIER
= EQUAL SIGNS
=ON A LINE
=\r\n"\
408 "Die letzte Zeile war nur ein Punkt
, mit Unix Zeilenende.
\n"\
410 "Das waren deren zwei. ditto.
\n"\
412 "Unn ausseerdem habe ich trailing SP
/HT
/SP
/HT whitespace
\n"\
413 "Unn ausseerdem habe ich trailing HT
/SP
/HT
/SP whitespace
\n"\
414 "auf den zeilen vorher.
\n"\
416 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende.
\n"\
417 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.1"\
419 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
421 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
423 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
425 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
427 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
429 "=VIER
= EQUAL SIGNS
=ON A LINE
=\n"\
431 "Die letzte Zeile war ein Leerschritt.
\n"\
435 # MIME CTE (QP) stress message subject
436 SUB='Äbrä Kä?dä=brö Fü?di=bus? '\
437 'adadaddsssssssddddddddddddddddddddd'\
438 'ddddddddddddddddddddddddddddddddddd'\
439 'ddddddddddddddddddddddddddddddddddd'\
440 'dddddddddddddddddddd Hallelulja? Od'\
441 'er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
442 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
443 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f'\
444 'fffffffffffffffffffffffffffffffffff'\
445 'fffffffffffffffffffff ggggggggggggg'\
446 'ggggggggggggggggggggggggggggggggggg'\
447 'ggggggggggggggggggggggggggggggggggg'\
448 'ggggggggggggggggggggggggggggggggggg'\
451 # Three tests for MIME-CTE and (a bit) content classification.
452 # At the same time testing -q FILE, < FILE and -t FILE
454 < "${BODY}" MAILRC=/dev/null \
455 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
456 cksum_test content:1 "${MBOX}" '2606934084 5649'
459 < /dev/null MAILRC=/dev/null \
460 "${SNAIL}" -n#Sstealthmua -a "${BODY}" -s "${SUB}" \
461 -q "${BODY}" "${MBOX}"
462 cksum_test content:2 "${MBOX}" '2606934084 5649'
465 ( echo "To
: ${MBOX}" && echo "Subject
: ${SUB}" && echo &&
467 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
468 cksum_test content:3 "${MBOX}" '799758423 5648'
470 # Test for [260e19d] (Juergen Daubert)
472 echo body | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua "${MBOX}"
473 cksum_test content:4 "${MBOX}" '506144051 104'
475 # Sending of multiple mails in a single invocation
477 ( printf "m
${MBOX}\n~s subject1
\nE
-Mail Körper
1\n.
\n" &&
478 printf "m
${MBOX}\n~s subject2
\nEmail body
2\n.
\n" &&
480 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
481 cksum_test content:5 "${MBOX}" '2028749685 277'
485 # "Test
for" [d6f316a] (Gavin Troy)
487 printf "m
${MBOX}\n~s subject1
\nEmail body
\n.
\nfi
${MBOX}\np
\nx
\n" |
488 MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua \
489 -SPAGER="${cat}" -Spipe-text/plain="${cat}" > "${BODY}"
490 ${sed} -e 1d < "${BODY}" > "${MBOX}"
491 cksum_test content
:6 "${MBOX}" '1520300594 138'
493 # "Test for" [c299c45] (Peter Hofmann) TODO shouldn't end up QP-encoded?
495 LC_ALL
=C
${awk} 'BEGIN{
496 for(i = 0; i < 100; ++i)
497 printf "\xF0\x90\x87\x90"
499 MAILRC
=/dev
/null
"${SNAIL}" -nSstealthmua -s TestSubject
"${MBOX}"
500 cksum_test content
:7 "${MBOX}" '395042486 1361'
502 ${rm} -f "${BODY}" "${MBOX}"
510 if [ -z "${CHECK_ONLY}" ]; then
516 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'