5 if test -z "$MH_OBJ_DIR"; then
6 srcdir
=`dirname "$0"`/..
/..
7 MH_OBJ_DIR
=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
10 .
"$MH_OBJ_DIR/test/common.sh"
12 if [ $
(uname
) != FreeBSD
]; then
13 test_skip
'imap/test-login only working on FreeBSD for now'
16 # common.sh sets this to something crazy; did i do that?!
17 testname
=${0#$srcdir/}
20 #### Save exit status to use as status for this program.
24 rm -f "$imapd" "$actual"
25 [ -n "$imapd_pid" ] && kill $imapd_pid
27 # TODO have cleanup allow additional cleanup registration?
28 # Or just allow it to accept status as argument.
34 covdir
="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
37 cat > "$MH_TEST_DIR/netrc" <<EOF
38 machine 127.0.0.1 login testuser password password
41 actual
="$MH_TEST_DIR/$$.actual"
43 imapd
="$MH_TEST_DIR/$$.imapd"
48 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
50 LLVM_PROFILE_FILE
="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start
> "$actual" 2>&1 || status
=$?
53 ################################################################################
54 # Tests with nothing even listening.
56 start_test
'connection refused, explicit TLS'
58 arith_eval
$arith_val + 1
59 setup_test_without_data profile
$arith_val
63 credentials: file-nopermcheck:$MH_TEST_DIR/netrc
66 imap-log-error-to: $MH_TEST_DIR/error
67 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
68 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
69 imap-db: $MH_TEST_DIR/$profile/imap.d
71 imap-mailbox-root: test/
73 imap-tls: explicit but don't verify the cert i already did out of band
77 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
78 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
79 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
83 if ! grep -q 'Connection to "127.0.0.1:255" failed: Connection refused' "$actual"; then
85 fail
'ECONN not reported'
88 # Use fakeinetd for tests of the parts of explicit TLS handling before TLS negotiation.
89 start_fakeinetd
"$imapd"
90 imapd_pid
=$fakeinetd_pid
92 arith_eval
$arith_val + 1
93 setup_test_without_data profile
$arith_val
97 credentials: file-nopermcheck:$MH_TEST_DIR/netrc
100 imap-log-error-to: $MH_TEST_DIR/error
101 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
102 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
103 imap-db: $MH_TEST_DIR/$profile/imap.d
105 imap-mailbox-root: test/
106 imap-port: $fakeinetd_port
107 imap-tls: explicit but don't verify the cert i already did out of band
111 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
112 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
113 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
116 ################################################################################
117 start_test
'rudely close pre-greeting, explicit TLS'
119 cat > "$imapd" <<EOSCRIPT
126 if ! grep -q 'Received EOF on network read' "$actual"; then
128 fail
'EOF error not reported'
131 ################################################################################
132 start_test
'protocol violation in greeting, explicit TLS'
134 # Greets with simply "trash\r\n".
136 cat > "$imapd" <<EOSCRIPT
141 while read line; do :; done
145 if ! grep -q 'protocol error: no space in response' "$actual"; then
147 fail
'protocol error not reported'
150 ################################################################################
151 start_test
'STARTTLS capability not offered'
153 cat > "$imapd" <<EOSCRIPT
156 * OK [CAPABILITY IMAP4REV1 AUTH=PLAIN UIDPLUS]
158 while read line; do :; done
162 if ! grep -q "server doesn't offer STARTTLS" "$actual"; then
164 fail
'missing STARTTLS not reported'
167 ################################################################################
168 start_test
'STARTTLS capability not offered after capabilities requested'
170 cat > "$imapd" <<EOSCRIPT
174 1 OK [CAPABILITY IMAP4REV1 AUTH=PLAIN UIDPLUS] CAPABILITY response
176 while read line; do :; done
180 if ! grep -q "server doesn't offer STARTTLS" "$actual"; then
182 fail
'missing STARTTLS not reported'
185 ################################################################################
186 start_test
'rudely closed after STARTTLS'
188 cat > "$imapd" <<EOSCRIPT
191 * OK [CAPABILITY IMAP4REV1 STARTTLS] greeting
197 if ! grep -q 'Received EOF on network read' "$actual"; then
199 fail
'EOF not reported'
202 ################################################################################
203 start_test
'trash response to STARTTLS'
205 cat > "$imapd" <<EOSCRIPT
208 * OK [CAPABILITY IMAP4REV1 STARTTLS] greeting
211 while read line; do :; done
215 if ! grep -q 'protocol error: no space in response' "$actual"; then
217 fail
'protocol error not reported'
223 ################################################################################
224 start_test
'connection refused, implicit TLS'
226 arith_eval
$arith_val + 1
227 setup_test_without_data profile
$arith_val
231 credentials: file-nopermcheck:$MH_TEST_DIR/netrc
232 Managed-Folders: imap
233 imap-log-level: error
234 imap-log-error-to: $MH_TEST_DIR/error
235 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
236 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
237 imap-db: $MH_TEST_DIR/$profile/imap.d
239 imap-mailbox-root: test/
241 imap-tls: implicit but don't verify the cert i already did out of band
245 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
246 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
247 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
251 if ! grep -q 'Connection to "127.0.0.1:255" failed: Connection refused' "$actual"; then
253 fail
'ECONN not reported'
256 ################################################################################
257 # Start the server for the rest.
259 start_stunnel imap
"$imapd"
261 arith_eval
$arith_val + 1
262 setup_test_without_data profile
$arith_val
266 credentials: file-nopermcheck:$MH_TEST_DIR/netrc
267 Managed-Folders: imap
268 imap-log-level: error
269 imap-log-error-to: $MH_TEST_DIR/error
270 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
271 imap-socket: $MH_TEST_DIR/$profile/imap.d/socket
272 imap-db: $MH_TEST_DIR/$profile/imap.d
274 imap-mailbox-root: test/
275 imap-port: $fakeinetd_port
276 imap-tls: implicit but don't verify the cert i already did out of band
280 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
281 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
282 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
285 ################################################################################
286 start_test
'rudely close pre-greeting, implicit TLS'
288 cat > "$imapd" <<EOSCRIPT
294 if ! grep -q 'TLS peer closed remote connection' "$actual"; then
296 fail
'EOF error not reported'
299 ################################################################################
300 start_test
'no SASL-IR capability'
302 cat > "$imapd" <<EOSCRIPT
305 * OK [CAPABILITY IMAP4REV1 AUTH=PLAIN]
307 while read line; do :; done
311 if ! grep -q "server doesn't offer SASL-IR; let us know and we'll support this configuration" "$actual"; then
313 fail
'missing SASL-IR not reported'
316 ################################################################################
317 start_test
'no UIDPLUS capability'
319 cat > "$imapd" <<EOSCRIPT
322 * OK [CAPABILITY IMAP4REV1 SASL-IR AUTH=PLAIN] greeting
323 1 OK [CAPABILITY IMAP4REV1] AUTENTICATE response
325 while read line; do :; done
329 if ! grep -q "server doesn't offer required capability UIDPLUS" "$actual"; then
331 fail
'missing UIDPLUS not reported'
334 ################################################################################
335 start_test
'protocol violation in greeting, implicit TLS'
337 # Greets with simply "trash\r\n".
339 cat > "$imapd" <<EOSCRIPT
344 while read line; do :; done
348 if ! grep -q 'protocol error: no space in response' "$actual"; then
350 fail
'protocol error not reported'
353 ################################################################################
354 start_test
'protocol violation in AUTHENTICATE response'
356 # Responds to the AUTHENTICATE command with simply "trash\r\n".
358 cat > "$imapd" <<EOSCRIPT
361 * OK [CAPABILITY IMAP4REV1 SASL-IR AUTH=PLAIN] greeting
364 while read line; do :; done
368 if ! grep -q 'protocol error: no space in response' "$actual"; then
370 fail
'protocol error not reported'