mk-conf.sh: adjust fixed CONFIG=urations for mandatory options
[s-mailx.git] / cc-test.sh
blob40a8d32de6d438d7f93596ae503fca0c85b480d3
1 #!/bin/sh -
2 #@ Usage: ./cc-test.sh [--check-only [s-nail-binary]]
4 SNAIL=./s-nail
5 CONF=./make.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"
70 for (k = 0; k < j; ++k)
71 printf data[k] "=0 "
72 for (k = j; k < i; ++k)
73 printf data[k] "=1 "
74 printf "WANT_AUTOCC=1\n"
77 ' | while read c; do
78 printf "\n\n##########\n$c\n"
79 printf "\n\n##########\n$c\n" >&2
80 sh -c "${MAKE} ${c}"
81 t_all
82 ${MAKE} distclean
83 done
86 # cksum_test()
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
89 cksum_test() {
90 tid=$1 f=$2 s=$3
91 printf "${tid}: "
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
96 printf 'ok\n'
97 else
98 ESTAT=1
99 printf 'error: checksum mismatch (got %s)\n' "${csum}"
103 have_feat() {
105 echo 'feat' |
106 MAILRC=/dev/null "${SNAIL}" -n -# |
107 ${grep} ${1}
108 ) >/dev/null 2>&1
111 # t_behave()
112 # Basic (easily testable) behaviour tests
113 t_behave() {
114 # Test for [d1f1a19]
115 ${rm} -f "${MBOX}"
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
124 __behave_ifelse
126 have_feat DEBUG && have_feat SSL/TLS && have_feat S/MIME &&
127 __behave_smime
130 __behave_ifelse() {
131 # Nestable conditions test
132 ${rm} -f "${MBOX}"
133 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
134 if 0
135 echo 1.err
136 else
137 echo 1.ok
138 endif
139 if 1
140 echo 2.ok
141 else
142 echo 2.err
143 endif
144 if $dietcurd
145 echo 3.err
146 else
147 echo 3.ok
148 endif
149 set dietcurd=yoho
150 if $dietcurd
151 echo 4.ok
152 else
153 echo 4.err
154 endif
155 if $dietcurd == 'yoho'
156 echo 5.ok
157 else
158 echo 5.err
159 endif
160 if $dietcurd != 'yoho'
161 echo 6.err
162 else
163 echo 6.ok
164 endif
165 # Nesting
166 if 0
167 echo 7.err1
168 if 1
169 echo 7.err2
170 if 1
171 echo 7.err3
172 else
173 echo 7.err4
174 endif
175 echo 7.err5
176 endif
177 echo 7.err6
178 else
179 echo 7.ok7
180 if 1
181 echo 7.ok8
182 if 0
183 echo 7.err9
184 else
185 echo 7.ok9
186 endif
187 echo 7.ok10
188 else
189 echo 7.err11
190 if 1
191 echo 7.err12
192 else
193 echo 7.err13
194 endif
195 endif
196 echo 7.ok14
197 endif
198 if r
199 echo 8.ok1
200 if R
201 echo 8.ok2
202 else
203 echo 8.err2
204 endif
205 echo 8.ok3
206 else
207 echo 8.err1
208 endif
209 if s
210 echo 9.err1
211 else
212 echo 9.ok1
213 if S
214 echo 9.err2
215 else
216 echo 9.ok2
217 endif
218 echo 9.ok3
219 endif
220 # `elif'
221 if $dietcurd == 'yohu'
222 echo 10.err1
223 elif $dietcurd == 'yoha'
224 echo 10.err2
225 elif $dietcurd == 'yohe'
226 echo 10.err3
227 elif $dietcurd == 'yoho'
228 echo 10.ok1
229 if $dietcurd == 'yohu'
230 echo 10.err4
231 elif $dietcurd == 'yoha'
232 echo 10.err5
233 elif $dietcurd == 'yohe'
234 echo 10.err6
235 elif $dietcurd == 'yoho'
236 echo 10.ok2
237 if $dietcurd == 'yohu'
238 echo 10.err7
239 elif $dietcurd == 'yoha'
240 echo 10.err8
241 elif $dietcurd == 'yohe'
242 echo 10.err9
243 elif $dietcurd == 'yoho'
244 echo 10.ok3
245 else
246 echo 10.err10
247 endif
248 else
249 echo 10.err11
250 endif
251 else
252 echo 10.err12
253 endif
254 __EOT
255 cksum_test behave:if-normal "${MBOX}" '2760114576 119'
257 if have_feat REGEX; then
258 ${rm} -f "${MBOX}"
259 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" -n -# > "${MBOX}"
260 set dietcurd=yoho
261 if $dietcurd =~ '^yo.*'
262 echo 1.ok
263 else
264 echo 1.err
265 endif
266 if $dietcurd =~ '^yoho.+'
267 echo 2.err
268 else
269 echo 2.ok
270 endif
271 if $dietcurd !~ '.*ho$'
272 echo 3.err
273 else
274 echo 3.ok
275 endif
276 if $dietcurd !~ '.+yoho$'
277 echo 4.ok
278 else
279 echo 4.err
280 endif
281 __EOT
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
290 [ req ]
291 default_bits = 1024
292 default_keyfile = keyfile.pem
293 distinguished_name = req_distinguished_name
294 attributes = req_attributes
295 prompt = no
296 output_password =
298 [ req_distinguished_name ]
299 C = GB
300 ST = Over the
301 L = rainbow
302 O = S-nail
303 OU = S-nail.smime
304 CN = S-nail.test
305 emailAddress = test@localhost
307 [ req_attributes ]
308 challengePassword =
309 _EOT
310 openssl req -x509 -nodes -days 3650 -config t.conf \
311 -newkey rsa:1024 -keyout tkey.pem -out tcert.pem >/dev/null 2>&1
312 ${rm} -f t.conf
313 ${cat} tkey.pem tcert.pem > tpair.pem
315 printf "behave:s/mime:sign/verify: "
316 echo bla |
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
321 # TODO CHECK
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
329 printf 'ok\n'
330 else
331 ESTAT=1
332 printf 'error: verification failed\n'
333 ${rm} -f ./VERIFY tkey.pem tcert.pem tpair.pem
334 return
336 ${rm} -rf ./VERIFY
338 printf "behave:s/mime:encrypt/decrypt: "
339 ${cat} <<-_EOT > tsendmail.sh
340 #!/bin/sh -
341 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
342 _EOT
343 chmod 0755 tsendmail.sh
345 echo bla |
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
353 # TODO CHECK
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
364 printf 'ok\n'
365 else
366 ESTAT=1
367 printf 'error: decryption+verification failed\n'
369 ${rm} -f ./tsendmail.sh ./ENCRYPT ./DECRYPT tkey.pem tcert.pem tpair.pem
372 # t_content()
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
377 t_content() {
378 ${rm} -f "${BODY}" "${MBOX}"
380 # MIME CTE (QP) stress message body
381 printf \
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"\
399 ".\r\n"\
400 "Die letzte Zeile war nur ein Punkt.\r\n"\
401 "..\r\n"\
402 "Das waren deren zwei.\r\n"\
403 " \r\n"\
404 "Die letzte Zeile war ein Leerschritt.\n"\
405 "=VIER = EQUAL SIGNS=ON A LINE=\r\n"\
406 "Prösterchen.\r\n"\
407 ".\n"\
408 "Die letzte Zeile war nur ein Punkt, mit Unix Zeilenende.\n"\
409 "..\n"\
410 "Das waren deren zwei. ditto.\n"\
411 "Prösterchen.\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"\
415 "ditto.\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"\
418 "\n"\
419 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
420 "\n"\
421 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
422 "3\n"\
423 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
424 "34\n"\
425 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
426 "345\n"\
427 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
428 "3456\n"\
429 "=VIER = EQUAL SIGNS=ON A LINE=\n"\
430 " \n"\
431 "Die letzte Zeile war ein Leerschritt.\n"\
432 ' '\
433 > "${BODY}"
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'\
449 'gggggggggggggggg'
451 # Three tests for MIME-CTE and (a bit) content classification.
452 # At the same time testing -q FILE, < FILE and -t FILE
453 ${rm} -f "${MBOX}"
454 < "${BODY}" MAILRC=/dev/null \
455 "${SNAIL}" -nSstealthmua -a "${BODY}" -s "${SUB}" "${MBOX}"
456 cksum_test content:1 "${MBOX}" '2606934084 5649'
458 ${rm} -f "${MBOX}"
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'
464 ${rm} -f "${MBOX}"
465 ( echo "To: ${MBOX}" && echo "Subject: ${SUB}" && echo &&
466 ${cat} "${BODY}"
467 ) | MAILRC=/dev/null "${SNAIL}" -nSstealthmua -a "${BODY}" -t
468 cksum_test content:3 "${MBOX}" '799758423 5648'
470 # Test for [260e19d] (Juergen Daubert)
471 ${rm} -f "${MBOX}"
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
476 ${rm} -f "${MBOX}"
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" &&
479 echo x
480 ) | MAILRC=/dev/null "${SNAIL}" -n#Sstealthmua
481 cksum_test content:5 "${MBOX}" '2028749685 277'
483 ## $BODY CHANGED
485 # "Test for" [d6f316a] (Gavin Troy)
486 ${rm} -f "${MBOX}"
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?
494 ${rm} -f "${MBOX}"
495 LC_ALL=C ${awk} 'BEGIN{
496 for(i = 0; i < 100; ++i)
497 printf "\xF0\x90\x87\x90"
498 }' |
499 MAILRC=/dev/null "${SNAIL}" -nSstealthmua -s TestSubject "${MBOX}"
500 cksum_test content:7 "${MBOX}" '395042486 1361'
502 ${rm} -f "${BODY}" "${MBOX}"
505 t_all() {
506 t_behave
507 t_content
510 if [ -z "${CHECK_ONLY}" ]; then
511 cc_all_configs
512 else
513 t_all
516 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
518 exit ${ESTAT}
519 # s-it-mode