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"
71 for (k = 0; k < j; ++k)
73 for (k = j; k < i; ++k)
75 printf "WANT_AUTOCC=1\n"
80 printf "\n\n##########\n$c\n"
81 printf "\n\n##########\n$c\n" >&2
89 # Read mailbox $2, strip non-constant headers and MIME boundaries, query the
90 # cksum(1) of the resulting data and compare against the checksum $3
94 csum
="`${sed} -e '/^From /d' -e '/^Date: /d' \
95 -e '/^ boundary=/d' -e '/^--=_/d' < \"${f}\" \
96 -e '/^\[-- Message/d' | ${cksum}`";
97 if [ "${csum}" = "${s}" ]; then
101 printf 'error: checksum mismatch (got %s)\n' "${csum}"
108 MAILRC
=/dev
/null
"${SNAIL}" -n -# |
114 # Basic (easily testable) behaviour tests
118 printf 'echo +nix\nset folder=/\necho +nix\nset nofolder\necho +nix\nx' |
119 MAILRC
=/dev
/null
"${SNAIL}" -n -# -SPAGER="${cat}" > "${MBOX}"
120 cksum_test behave
:1 "${MBOX}" '4214021069 15'
122 # POSIX: setting *noprompt*/prompt='' shall prevent prompting TODO
123 # TODO for this to be testable we need a way to echo a variable
124 # TODO or to force echo of the prompt
128 have_feat DEBUG
&& have_feat SSL
/TLS
&& have_feat S
/MIME
&&
133 # Nestable conditions test
135 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
157 if $dietcurd == 'yoho'
162 if $dietcurd != 'yoho'
223 if $dietcurd == 'yohu'
225 elif $dietcurd == 'yoha'
227 elif $dietcurd == 'yohe'
229 elif $dietcurd == 'yoho'
231 if $dietcurd == 'yohu'
233 elif $dietcurd == 'yoha'
235 elif $dietcurd == 'yohe'
237 elif $dietcurd == 'yoho'
239 if $dietcurd == 'yohu'
241 elif $dietcurd == 'yoha'
243 elif $dietcurd == 'yohe'
245 elif $dietcurd == 'yoho'
257 cksum_test behave:if-normal "${MBOX}" '2760114576 119'
259 if have_feat REGEX; then
261 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
263 if $dietcurd =~
'^yo.*'
268 if $dietcurd =~
'^yoho.+'
273 if $dietcurd !~
'.*ho$'
278 if $dietcurd !~
'.+yoho$'
284 cksum_test behave
:if-regex
"${MBOX}" '3930005258 20'
288 __behave_smime
() { # FIXME add test/ dir, unroll tests therein, regular enable!
289 echo WARNING
: behave_smime is yet debug only and not generalized
290 printf 'behave:s/mime: .. generating test key and certificate ..\n'
291 ${cat} <<-_EOT > t.conf
294 default_keyfile = keyfile.pem
295 distinguished_name = req_distinguished_name
296 attributes = req_attributes
300 [ req_distinguished_name ]
307 emailAddress = test@localhost
312 openssl req
-x509 -nodes -days 3650 -config t.conf \
313 -newkey rsa
:1024 -keyout tkey.pem
-out tcert.pem
>/dev
/null
2>&1
315 ${cat} tkey.pem tcert.pem
> tpair.pem
317 printf "behave:s/mime:sign/verify: "
319 MAILRC
=/dev
/null .
/s-nail
-n# \
320 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
321 -Ssmime-sign -Sfrom=test@localhost \
322 -s 'S/MIME test' .
/VERIFY
324 printf 'verify\nx\n' |
325 MAILRC
=/dev
/null .
/s-nail
-n# \
326 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
327 -Ssmime-sign -Sfrom=test@localhost \
328 -Sbatch-exit-on-error -R \
329 -f .
/VERIFY
>/dev
/null
2>&1
330 if [ $?
-eq 0 ]; then
334 printf 'error: verification failed\n'
335 ${rm} -f .
/VERIFY tkey.pem tcert.pem tpair.pem
340 printf "behave:s/mime:encrypt/decrypt: "
341 ${cat} <<-_EOT > tsendmail.sh
343 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
345 chmod 0755 tsendmail.sh
348 MAILRC
=/dev
/null .
/s-nail
-n# \
349 -Ssmime-force-encryption \
350 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
351 -Ssendmail=.
/tsendmail.sh \
352 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
353 -Ssmime-sign -Sfrom=test@localhost \
354 -s 'S/MIME test' recei@ver.com
356 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
357 MAILRC
=/dev
/null .
/s-nail
-n# \
358 -Ssmime-force-encryption \
359 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
360 -Ssendmail=.
/tsendmail.sh \
361 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
362 -Ssmime-sign -Sfrom=test@localhost \
363 -Sbatch-exit-on-error -R \
364 -f .
/ENCRYPT
>/dev
/null
2>&1
365 if [ $?
-eq 0 ]; then
369 printf 'error: decryption+verification failed\n'
371 ${rm} -f .
/tsendmail.sh .
/ENCRYPT .
/DECRYPT tkey.pem tcert.pem tpair.pem
375 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
376 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
377 # Note we unfortunately need to place some statements without proper
378 # indentation because of continuation problems
380 ${rm} -f "${BODY}" "${MBOX}"
382 # MIME CTE (QP) stress message body
384 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
385 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
386 "wasde willst
, gelle
, gelle
, gelle
, gelle
, gelle.
\r\n"\
387 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
\r\n"\
388 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1\r\n"\
389 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12\r\n"\
390 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123\r\n"\
391 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234\r\n"\
392 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345\r\n"\
393 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456\r\n"\
394 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234567\r\n"\
395 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345678\r\n"\
396 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456789\r\n"\
397 "Unn ausserdem habe ich trailing SP
/HT
/SP
/HT whitespace
\r\n"\
398 "Unn ausserdem habe ich trailing HT
/SP
/HT
/SP whitespace
\r\n"\
399 "auf den zeilen vorher.
\r\n"\
400 "From am Zeilenbeginn und From der Mitte gibt es auch.
\r\n"\
402 "Die letzte Zeile war nur ein Punkt.
\r\n"\
404 "Das waren deren zwei.
\r\n"\
406 "Die letzte Zeile war ein Leerschritt.
\n"\
407 "=VIER
= EQUAL SIGNS
=ON A LINE
=\r\n"\
410 "Die letzte Zeile war nur ein Punkt
, mit Unix Zeilenende.
\n"\
412 "Das waren deren zwei. ditto.
\n"\
414 "Unn ausseerdem habe ich trailing SP
/HT
/SP
/HT whitespace
\n"\
415 "Unn ausseerdem habe ich trailing HT
/SP
/HT
/SP whitespace
\n"\
416 "auf den zeilen vorher.
\n"\
418 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende.
\n"\
419 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.1"\
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 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
431 "=VIER
= EQUAL SIGNS
=ON A LINE
=\n"\
433 "Die letzte Zeile war ein Leerschritt.
\n"\
437 # MIME CTE (QP) stress message subject
438 SUB='Äbrä Kä?dä=brö Fü?di=bus? '\
439 'adadaddsssssssddddddddddddddddddddd'\
440 'ddddddddddddddddddddddddddddddddddd'\
441 'ddddddddddddddddddddddddddddddddddd'\
442 'dddddddddddddddddddd Hallelulja? Od'\
443 'er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
444 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
445 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f'\
446 'fffffffffffffffffffffffffffffffffff'\
447 'fffffffffffffffffffff ggggggggggggg'\
448 'ggggggggggggggggggggggggggggggggggg'\
449 'ggggggggggggggggggggggggggggggggggg'\
450 'ggggggggggggggggggggggggggggggggggg'\
453 # Three tests for MIME-CTE and (a bit) content classification.
454 # At the same time testing -q FILE, < FILE and -t FILE
456 < "${BODY}" MAILRC=/dev/null \
457 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
458 cksum_test content:1 "${MBOX}" '2606934084 5649'
461 < /dev/null MAILRC=/dev/null \
462 "${SNAIL}" -n#Sstealthmua -a "${BODY}" -s "${SUB}" \
463 -q "${BODY}" "${MBOX}"
464 cksum_test content:2 "${MBOX}" '2606934084 5649'
467 ( echo "To
: ${MBOX}" && echo "Subject
: ${SUB}" && echo &&
469 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
470 cksum_test content:3 "${MBOX}" '799758423 5648'
472 # Test for [260e19d] (Juergen Daubert)
474 echo body | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua "${MBOX}"
475 cksum_test content:4 "${MBOX}" '506144051 104'
477 # Sending of multiple mails in a single invocation
479 ( printf "m
${MBOX}\n~s subject1
\nE
-Mail Körper
1\n.
\n" &&
480 printf "m
${MBOX}\n~s subject2
\nEmail body
2\n.
\n" &&
482 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
483 cksum_test content:5 "${MBOX}" '2028749685 277'
487 # "Test
for" [d6f316a] (Gavin Troy)
489 printf "m
${MBOX}\n~s subject1
\nEmail body
\n.
\nfi
${MBOX}\np
\nx
\n" |
490 MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua \
491 -SPAGER="${cat}" -Spipe-text/plain="${cat}" > "${BODY}"
492 ${sed} -e 1d < "${BODY}" > "${MBOX}"
493 cksum_test content
:6 "${MBOX}" '1520300594 138'
495 ${rm} -f "${BODY}" "${MBOX}"
503 if [ -z "${CHECK_ONLY}" ]; then
509 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
512 # vim:set fenc=utf-8:s-it-mode