]> diplodocus.org Git - nmh/blob - test/imap/test-bad-fetch-body
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-bad-fetch-body
1 #!/bin/sh
2
3 # TODO FIX uh oh this and the inc missing msg cases passed by accident after inc uses ESEARCH
4 # and now switching inc to leave mailbox open has broken it completely!
5
6 # TODO figure out how to get a server to send a BAD response so we have an accurate fake
7
8 if test -z "$MH_OBJ_DIR"; then
9 srcdir=`dirname "$0"`/../..
10 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
11 fi
12
13 . "$MH_OBJ_DIR/test/common.sh"
14
15 # common.sh sets this to something crazy; did i do that?!
16 testname=${0#$srcdir/}
17
18 setup_test_without_data Mail
19
20 imap_cleanup() {
21 #### Save exit status to use as status for this program.
22 status=$?
23 set +e
24
25 rm -f "$imapd"
26
27 [ -n "$imapd_pid" ] && kill $imapd_pid
28 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
29
30 # TODO have cleanup allow additional cleanup registration?
31 # Or just allow it to accept status as argument.
32 (exit $status)
33 cleanup
34 }
35 trap imap_cleanup 0
36
37 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
38 install -d "$covdir"
39 export LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw"
40
41 imapd="$MH_TEST_DIR/$$.imapd"
42 start_fakeinetd "$imapd"
43 imapd_pid=$fakeinetd_pid
44
45 cat >> "$MH" <<EOF
46 Managed-Folders: imap
47 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
48 imap-socket: $MH_TEST_DIR/Mail/imap.d/socket
49 imap-db: $MH_TEST_DIR/Mail/imap.d
50 imap-host: 127.0.0.1
51 imap-port: $fakeinetd_port
52 imap-tls: don't protect my data i know what i'm doing
53 imap-auth: PREAUTH
54 imap-mailbox-root: test/
55 EOF
56 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
57 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
58 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
59 fi
60
61 start_test 'unrecoverable error: BAD FETCH'
62
63 cat > "$imapd" <<EOSCRIPT
64 #!/bin/sh
65 cat <<EOF
66 * PREAUTH [CAPABILITY IMAP4REV1 UIDPLUS] authenticated
67 * LIST (\NoInferiors \UnMarked) "/" test/fold
68 1 OK LIST completed
69 * 1 EXISTS
70 * OK [UIDVALIDITY 1603585238] UID validity status
71 * OK [UIDNEXT 12] Predicted next UID
72 1 OK [READ-WRITE] SELECT completed
73 * SEARCH 11
74 1 OK UID SEARCH completed
75 fetch11 BAD fake fake fakey fake
76 EOF
77 while read line; do :; done
78 EOSCRIPT
79 chmod 755 "$imapd"
80
81 # TODO plumb this error out to inc
82
83 check_exit '-eq 1' inc +imap
84 if ! grep -q 'BAD.*fake fake fakey fake' "$MH_TEST_DIR/$profile/imap.d/stderr"; then
85 cat "$MH_TEST_DIR/$profile/imap.d/stderr" >&2
86 fail "BAD response not in $MH_TEST_DIR/$profile/imap.d/stderr"
87 fi
88
89 finish_test
90 exit ${failed:-0}