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}"
106 # Basic (easily testable) behaviour tests
110 printf 'echo +nix\nset folder=/\necho +nix\nset nofolder\necho +nix\nx' |
111 MAILRC
=/dev
/null
"${SNAIL}" -n -# -SPAGER="${cat}" > "${MBOX}"
112 cksum_test behave
:1 "${MBOX}" '4214021069 15'
114 # POSIX: setting *noprompt*/prompt='' shall prevent prompting TODO
115 # TODO for this to be testable we need a way to echo a variable
116 # TODO or to force echo of the prompt
120 FEAT
=`printf 'feat\n' | MAILRC=/dev/null "${SNAIL}" -n -#`
121 if { i
=${FEAT}; echo "${i}"; } |
${grep} -q DEBUG
&&
122 { i
=${FEAT}; echo "${i}"; } |
${grep} -q 'SSL/TLS' &&
123 { i
=${FEAT}; echo "${i}"; } |
${grep} -q 'S/MIME'; then
129 # Nestable conditions test
131 cat <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
153 if $dietcurd == 'yoho'
158 if $dietcurd != 'yoho'
219 cksum_test behave
:2 "${MBOX}" '1909382116 98'
222 __behave_smime
() { # FIXME add test/ dir, unroll tests therein, regular enable!
223 echo WARNING
: behave_smime is yet debug only and not generalized
224 printf 'behave:s/mime: .. generating test key and certificate ..\n'
228 default_keyfile = keyfile.pem
229 distinguished_name = req_distinguished_name
230 attributes = req_attributes
234 [ req_distinguished_name ]
241 emailAddress = test@localhost
246 openssl req
-x509 -nodes -days 3650 -config t.conf \
247 -newkey rsa
:1024 -keyout tkey.pem
-out tcert.pem
>/dev
/null
2>&1
249 cat tkey.pem tcert.pem
> tpair.pem
251 printf "behave:s/mime:sign/verify: "
253 MAILRC
=/dev
/null .
/s-nail
-n# \
254 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
255 -Ssmime-sign -Sfrom=test@localhost \
256 -s 'S/MIME test' .
/VERIFY
258 printf 'verify\nx\n' |
259 MAILRC
=/dev
/null .
/s-nail
-n# \
260 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
261 -Ssmime-sign -Sfrom=test@localhost \
262 -Sbatch-exit-on-error -R \
263 -f .
/VERIFY
>/dev
/null
2>&1
264 if [ $?
-eq 0 ]; then
268 printf 'error: verification failed\n'
269 rm -f .
/VERIFY tkey.pem tcert.pem tpair.pem
274 printf "behave:s/mime:encrypt/decrypt: "
275 cat <<-_EOT > tsendmail.sh
277 (echo 'From S-Postman Thu May 10 20:40:54 2012' && cat) > ./ENCRYPT
279 chmod 0755 tsendmail.sh
282 MAILRC
=/dev
/null .
/s-nail
-n# \
283 -Ssmime-force-encryption \
284 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
285 -Ssendmail=.
/tsendmail.sh \
286 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
287 -Ssmime-sign -Sfrom=test@localhost \
288 -s 'S/MIME test' recei@ver.com
290 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
291 MAILRC
=/dev
/null .
/s-nail
-n# \
292 -Ssmime-force-encryption \
293 -Ssmime-encrypt-recei@ver.com
=tpair.pem \
294 -Ssendmail=.
/tsendmail.sh \
295 -Ssmime-ca-file=tcert.pem
-Ssmime-sign-cert=tpair.pem \
296 -Ssmime-sign -Sfrom=test@localhost \
297 -Sbatch-exit-on-error -R \
298 -f .
/ENCRYPT
>/dev
/null
2>&1
299 if [ $?
-eq 0 ]; then
303 printf 'error: decryption+verification failed\n'
305 rm -f .
/tsendmail.sh .
/ENCRYPT .
/DECRYPT tkey.pem tcert.pem tpair.pem
309 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
310 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
311 # Note we unfortunately need to place some statements without proper
312 # indentation because of continuation problems
314 ${rm} -f "${BODY}" "${MBOX}"
316 # MIME CTE (QP) stress message body
318 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
319 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
320 "wasde willst
, gelle
, gelle
, gelle
, gelle
, gelle.
\r\n"\
321 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
\r\n"\
322 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1\r\n"\
323 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12\r\n"\
324 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123\r\n"\
325 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234\r\n"\
326 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345\r\n"\
327 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456\r\n"\
328 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
1234567\r\n"\
329 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
12345678\r\n"\
330 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst
123456789\r\n"\
331 "Unn ausserdem habe ich trailing SP
/HT
/SP
/HT whitespace
\r\n"\
332 "Unn ausserdem habe ich trailing HT
/SP
/HT
/SP whitespace
\r\n"\
333 "auf den zeilen vorher.
\r\n"\
334 "From am Zeilenbeginn und From der Mitte gibt es auch.
\r\n"\
336 "Die letzte Zeile war nur ein Punkt.
\r\n"\
338 "Das waren deren zwei.
\r\n"\
340 "Die letzte Zeile war ein Leerschritt.
\n"\
341 "=VIER
= EQUAL SIGNS
=ON A LINE
=\r\n"\
344 "Die letzte Zeile war nur ein Punkt
, mit Unix Zeilenende.
\n"\
346 "Das waren deren zwei. ditto.
\n"\
348 "Unn ausseerdem habe ich trailing SP
/HT
/SP
/HT whitespace
\n"\
349 "Unn ausseerdem habe ich trailing HT
/SP
/HT
/SP whitespace
\n"\
350 "auf den zeilen vorher.
\n"\
352 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende.
\n"\
353 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.1"\
355 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
357 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
359 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
361 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
363 "Ich bin eine ziemlich lange
, steile
, scharfe Zeile mit Unix Zeilenende
.12"\
365 "=VIER
= EQUAL SIGNS
=ON A LINE
=\n"\
367 "Die letzte Zeile war ein Leerschritt.
\n"\
371 # MIME CTE (QP) stress message subject
372 SUB='Äbrä Kä?dä=brö Fü?di=bus? '\
373 'adadaddsssssssddddddddddddddddddddd'\
374 'ddddddddddddddddddddddddddddddddddd'\
375 'ddddddddddddddddddddddddddddddddddd'\
376 'dddddddddddddddddddd Hallelulja? Od'\
377 'er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
378 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'\
379 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f'\
380 'fffffffffffffffffffffffffffffffffff'\
381 'fffffffffffffffffffff ggggggggggggg'\
382 'ggggggggggggggggggggggggggggggggggg'\
383 'ggggggggggggggggggggggggggggggggggg'\
384 'ggggggggggggggggggggggggggggggggggg'\
387 # Three tests for MIME-CTE and (a bit) content classification.
388 # At the same time testing -q FILE, < FILE and -t FILE
390 < "${BODY}" MAILRC=/dev/null \
391 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
392 cksum_test content:1 "${MBOX}" '2606934084 5649'
395 < /dev/null MAILRC=/dev/null \
396 "${SNAIL}" -n#Sstealthmua -a "${BODY}" -s "${SUB}" \
397 -q "${BODY}" "${MBOX}"
398 cksum_test content:2 "${MBOX}" '2606934084 5649'
401 ( echo "To
: ${MBOX}" && echo "Subject
: ${SUB}" && echo &&
403 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
404 cksum_test content:3 "${MBOX}" '799758423 5648'
406 # Test for [260e19d] (Juergen Daubert)
408 echo body | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua "${MBOX}"
409 cksum_test content:4 "${MBOX}" '506144051 104'
411 # Sending of multiple mails in a single invocation
413 ( printf "m
${MBOX}\n~s subject1
\nE
-Mail Körper
1\n.
\n" &&
414 printf "m
${MBOX}\n~s subject2
\nEmail body
2\n.
\n" &&
416 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
417 cksum_test content:5 "${MBOX}" '2028749685 277'
421 # "Test
for" [d6f316a] (Gavin Troy)
423 printf "m
${MBOX}\n~s subject1
\nEmail body
\n.
\nfi
${MBOX}\np
\nx
\n" |
424 MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua \
425 -SPAGER="${cat}" -Spipe-text/plain="${cat}" > "${BODY}"
426 ${sed} -e 1d < "${BODY}" > "${MBOX}"
427 cksum_test content
:6 "${MBOX}" '1520300594 138'
429 ${rm} -f "${BODY}" "${MBOX}"
437 if [ -z "${CHECK_ONLY}" ]; then
443 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
446 # vim:set fenc=utf8:s-it-mode