]> diplodocus.org Git - nmh/blob - test/imap/test-astring
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-astring
1 #!/bin/sh
2
3 # Test astring handling.
4 # For now only in LIST response.
5 # Gmail encodes all mailbox names in quotes and embedded quotes like "foo \" bar"
6 # Panda encodes them using literals.
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 # TODO no need for xoauth in this test
14 . "${srcdir}/test/oauth/common.sh"
15
16 # common.sh sets this to something crazy; did i do that?!
17 testname=${0#$srcdir/}
18
19 # coverage notes
20 # (
21 # set -ex
22 # . ~/.cargo/env
23 # covdir="$builddir/test/covdata/${MH_COVERAGE_PROFILE:-default}/test/cargo"
24 # install -d "$covdir"
25 # export LLVM_PROFILE_FILE="$covdir/%m-%p.profraw"
26 # export CARGO_TARGET_DIR=$builddir/target
27 # export RUSTC_BOOTSTRAP=1
28 # export RUSTFLAGS="-Zinstrument-coverage"
29 # cargo t -- --test-threads=1
30 # make cargo
31 # MH_IMAP_TEST_SERVER=panda make check 'TESTS=test/imap/test-astring'
32 # )
33 #grcov .o/clang10 -s . --binary-path .o/clang10/target/debug/ -t html --branch --ignore-not-existing -o /coverage/default > covlog 2>&1
34
35 setup_test_without_data Mail
36
37 setup_service
38 fake_creds <<EOF
39 access-testuser: test-access
40 refresh-testuser: test-refresh
41 expire-testuser: 2000000000
42 EOF
43
44 imap_cleanup() {
45 #### Save exit status to use as status for this program.
46 status=$?
47 set +e
48
49 rm -f "$imapd"
50
51 [ -n "$imapd_pid" ] && kill $imapd_pid
52 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
53
54 # TODO have cleanup allow additional cleanup registration?
55 # Or just allow it to accept status as argument.
56 (exit $status)
57 cleanup
58 }
59 trap imap_cleanup 0
60
61 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
62 install -d "$covdir"
63 export LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw"
64
65 imapd="$MH_TEST_DIR/$$.imapd"
66 start_fakeinetd "$imapd"
67 imapd_pid=$fakeinetd_pid
68
69 cat >> "$MH" <<EOF
70 Managed-Folders: imap
71 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
72 imap-socket: $MH_TEST_DIR/Mail/imap.d/socket
73 imap-db: $MH_TEST_DIR/Mail/imap.d
74 imap-host: 127.0.0.1
75 imap-port: $fakeinetd_port
76 imap-tls: don't protect my data i know what i'm doing
77 imap-auth: SASL
78 imap-user: testuser
79 imap-saslmech: xoauth2
80 imap-authservice: test
81 EOF
82 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
83 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
84 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/Mail/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
85 fi
86
87 # Test astring and nstring handling with some faked up but legal responses.
88 # I don't know whether any implementations return nil or quoted in these FETCH
89 # respones, but it is legal, so it's a fair test.
90 # TODO removed nstring testing for now
91
92 cat > "$imapd" <<EOSCRIPT
93 #!/bin/sh
94 cat <<EOF
95 * OK [CAPABILITY IMAP4REV1 SASL-IR AUTH=PLAIN AUTH=XOAUTH2] greeting
96 1 OK [CAPABILITY IMAP4REV1 UIDPLUS] authenticated
97 * LIST () "/" "embedded quote \" gmail style"
98 * LIST () "/" {28}
99 embedded quote " panda style
100 1 OK LIST completed
101 * 0 EXISTS
102 * OK [UIDVALIDITY 1603585238] UID validity status
103 * OK [UIDNEXT 1] Predicted next UID
104 1 OK [READ-WRITE] SELECT completed
105 1 OK ESEARCH
106 * 0 EXISTS
107 * OK [UIDVALIDITY 1603585238] UID validity status
108 * OK [UIDNEXT 1] Predicted next UID
109 * 7 FETCH ()
110 * 7 FETCH (UID 1 FLAGS (\Seen))
111 1 OK [READ-WRITE] SELECT completed
112 1 OK ESEARCH
113 EOF
114 while read line; do :; done
115 EOSCRIPT
116 chmod 755 "$imapd"
117
118 check_exit '-eq 0' inc +imap
119
120 finish_test
121 exit ${failed:-0}