Drop SEND_TOFLTR, S-nail passes raw data through to spam filter
[s-mailx.git] / cc-test.sh
blob02731d23a1b87cd8936252ff6d5bf9897d48c41b
1 #!/bin/sh -
2 #@ Usage: ./cc-test.sh [--check-only [s-nail-binary]]
4 SNAIL=./s-nail
5 CONF=./conf.rc
6 BODY=./.cc-body.txt
7 MBOX=./.cc-test.mbox
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`}
18 ## -- >8 -- 8< -- ##
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!)
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 = 0; j < i; ++j) {
64 for (k = 0; 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"
69 printf "\n"
71 for (k = 0; k < j; ++k)
72 printf data[k] "=0 "
73 for (k = j; k < i; ++k)
74 printf data[k] "=1 "
75 printf "WANT_AUTOCC=1\n"
76 printf "\n"
79 ' | while read c; do
80 printf "\n\n##########\n$c\n"
81 printf "\n\n##########\n$c\n" >&2
82 sh -c "${MAKE} ${c}"
83 t_all
84 ${MAKE} distclean
85 done
88 # cksum_test()
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
91 cksum_test() {
92 tid=$1 f=$2 s=$3
93 printf "${tid}: "
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
98 printf 'ok\n'
99 else
100 ESTAT=1
101 printf 'error: checksum mismatch (got %s)\n' "${csum}"
105 have_feat() {
107 echo 'feat' |
108 MAILRC=/dev/null "${SNAIL}" -n -# |
109 ${grep} ${1}
110 ) >/dev/null 2>&1
113 # t_behave()
114 # Basic (easily testable) behaviour tests
115 t_behave() {
116 # Test for [d1f1a19]
117 ${rm} -f "${MBOX}"
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
126 __behave_ifelse
128 have_feat DEBUG && have_feat SSL/TLS && have_feat S/MIME &&
129 __behave_smime
132 __behave_ifelse() {
133 # Nestable conditions test
134 ${rm} -f "${MBOX}"
135 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
136 if 0
137 echo 1.err
138 else
139 echo 1.ok
140 endif
141 if 1
142 echo 2.ok
143 else
144 echo 2.err
145 endif
146 if $dietcurd
147 echo 3.err
148 else
149 echo 3.ok
150 endif
151 set dietcurd=yoho
152 if $dietcurd
153 echo 4.ok
154 else
155 echo 4.err
156 endif
157 if $dietcurd == 'yoho'
158 echo 5.ok
159 else
160 echo 5.err
161 endif
162 if $dietcurd != 'yoho'
163 echo 6.err
164 else
165 echo 6.ok
166 endif
167 # Nesting
168 if 0
169 echo 7.err1
170 if 1
171 echo 7.err2
172 if 1
173 echo 7.err3
174 else
175 echo 7.err4
176 endif
177 echo 7.err5
178 endif
179 echo 7.err6
180 else
181 echo 7.ok7
182 if 1
183 echo 7.ok8
184 if 0
185 echo 7.err9
186 else
187 echo 7.ok9
188 endif
189 echo 7.ok10
190 else
191 echo 7.err11
192 if 1
193 echo 7.err12
194 else
195 echo 7.err13
196 endif
197 endif
198 echo 7.ok14
199 endif
200 if r
201 echo 8.ok1
202 if R
203 echo 8.ok2
204 else
205 echo 8.err2
206 endif
207 echo 8.ok3
208 else
209 echo 8.err1
210 endif
211 if s
212 echo 9.err1
213 else
214 echo 9.ok1
215 if S
216 echo 9.err2
217 else
218 echo 9.ok2
219 endif
220 echo 9.ok3
221 endif
222 # `elif'
223 if $dietcurd == 'yohu'
224 echo 10.err1
225 elif $dietcurd == 'yoha'
226 echo 10.err2
227 elif $dietcurd == 'yohe'
228 echo 10.err3
229 elif $dietcurd == 'yoho'
230 echo 10.ok1
231 if $dietcurd == 'yohu'
232 echo 10.err4
233 elif $dietcurd == 'yoha'
234 echo 10.err5
235 elif $dietcurd == 'yohe'
236 echo 10.err6
237 elif $dietcurd == 'yoho'
238 echo 10.ok2
239 if $dietcurd == 'yohu'
240 echo 10.err7
241 elif $dietcurd == 'yoha'
242 echo 10.err8
243 elif $dietcurd == 'yohe'
244 echo 10.err9
245 elif $dietcurd == 'yoho'
246 echo 10.ok3
247 else
248 echo 10.err10
249 endif
250 else
251 echo 10.err11
252 endif
253 else
254 echo 10.err12
255 endif
256 __EOT
257 cksum_test behave:if-normal "${MBOX}" '2760114576 119'
259 if have_feat REGEX; then
260 ${rm} -f "${MBOX}"
261 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
262 set dietcurd=yoho
263 if $dietcurd =~ '^yo.*'
264 echo 1.ok
265 else
266 echo 1.err
267 endif
268 if $dietcurd =~ '^yoho.+'
269 echo 2.err
270 else
271 echo 2.ok
272 endif
273 if $dietcurd !~ '.*ho$'
274 echo 3.err
275 else
276 echo 3.ok
277 endif
278 if $dietcurd !~ '.+yoho$'
279 echo 4.ok
280 else
281 echo 4.err
282 endif
283 __EOT
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
292 [ req ]
293 default_bits = 1024
294 default_keyfile = keyfile.pem
295 distinguished_name = req_distinguished_name
296 attributes = req_attributes
297 prompt = no
298 output_password =
300 [ req_distinguished_name ]
301 C = GB
302 ST = Over the
303 L = rainbow
304 O = S-nail
305 OU = S-nail.smime
306 CN = S-nail.test
307 emailAddress = test@localhost
309 [ req_attributes ]
310 challengePassword =
311 _EOT
312 openssl req -x509 -nodes -days 3650 -config t.conf \
313 -newkey rsa:1024 -keyout tkey.pem -out tcert.pem >/dev/null 2>&1
314 ${rm} -f t.conf
315 ${cat} tkey.pem tcert.pem > tpair.pem
317 printf "behave:s/mime:sign/verify: "
318 echo bla |
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
323 # TODO CHECK
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
331 printf 'ok\n'
332 else
333 ESTAT=1
334 printf 'error: verification failed\n'
335 ${rm} -f ./VERIFY tkey.pem tcert.pem tpair.pem
336 return
338 ${rm} -rf ./VERIFY
340 printf "behave:s/mime:encrypt/decrypt: "
341 ${cat} <<-_EOT > tsendmail.sh
342 #!/bin/sh -
343 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
344 _EOT
345 chmod 0755 tsendmail.sh
347 echo bla |
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
355 # TODO CHECK
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
366 printf 'ok\n'
367 else
368 ESTAT=1
369 printf 'error: decryption+verification failed\n'
371 ${rm} -f ./tsendmail.sh ./ENCRYPT ./DECRYPT tkey.pem tcert.pem tpair.pem
374 # t_content()
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
379 t_content() {
380 ${rm} -f "${BODY}" "${MBOX}"
382 # MIME CTE (QP) stress message body
383 printf \
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"\
401 ".\r\n"\
402 "Die letzte Zeile war nur ein Punkt.\r\n"\
403 "..\r\n"\
404 "Das waren deren zwei.\r\n"\
405 " \r\n"\
406 "Die letzte Zeile war ein Leerschritt.\n"\
407 "=VIER = EQUAL SIGNS=ON A LINE=\r\n"\
408 "Prösterchen.\r\n"\
409 ".\n"\
410 "Die letzte Zeile war nur ein Punkt, mit Unix Zeilenende.\n"\
411 "..\n"\
412 "Das waren deren zwei. ditto.\n"\
413 "Prösterchen.\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"\
417 "ditto.\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"\
420 "\n"\
421 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
422 "\n"\
423 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
424 "3\n"\
425 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
426 "34\n"\
427 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
428 "345\n"\
429 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
430 "3456\n"\
431 "=VIER = EQUAL SIGNS=ON A LINE=\n"\
432 " \n"\
433 "Die letzte Zeile war ein Leerschritt.\n"\
434 ' '\
435 > "${BODY}"
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'\
451 'gggggggggggggggg'
453 # Three tests for MIME-CTE and (a bit) content classification.
454 # At the same time testing -q FILE, < FILE and -t FILE
455 ${rm} -f "${MBOX}"
456 < "${BODY}" MAILRC=/dev/null \
457 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
458 cksum_test content:1 "${MBOX}" '2606934084 5649'
460 ${rm} -f "${MBOX}"
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'
466 ${rm} -f "${MBOX}"
467 ( echo "To: ${MBOX}" && echo "Subject: ${SUB}" && echo &&
468 ${cat} "${BODY}"
469 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
470 cksum_test content:3 "${MBOX}" '799758423 5648'
472 # Test for [260e19d] (Juergen Daubert)
473 ${rm} -f "${MBOX}"
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
478 ${rm} -f "${MBOX}"
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" &&
481 echo x
482 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
483 cksum_test content:5 "${MBOX}" '2028749685 277'
485 ## $BODY CHANGED
487 # "Test for" [d6f316a] (Gavin Troy)
488 ${rm} -f "${MBOX}"
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}"
498 t_all() {
499 t_behave
500 t_content
503 if [ -z "${CHECK_ONLY}" ]; then
504 cc_all_configs
505 else
506 t_all
509 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
511 exit ${ESTAT}
512 # vim:set fenc=utf-8:s-it-mode