#!/bin/sh testname=${0#$srcdir/} if test -z "$MH_OBJ_DIR"; then srcdir=`dirname "$0"`/../.. MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR fi . "$MH_OBJ_DIR/test/common.sh" if [ $(uname) != FreeBSD ]; then test_skip 'imap/test-login only working on FreeBSD for now' fi # common.sh sets this to something crazy; did i do that?! testname=${0#$srcdir/} imap_cleanup() { #### Save exit status to use as status for this program. status=$? set +e rm -f "$imapd" "$actual" [ -n "$imapd_pid" ] && kill $imapd_pid # TODO have cleanup allow additional cleanup registration? # Or just allow it to accept status as argument. (exit $status) cleanup } trap imap_cleanup 0 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname" install -d "$covdir" cat > "$MH_TEST_DIR/netrc" < "$actual" 2>&1 || status=$? } ################################################################################ # Tests with nothing even listening. start_test 'connection refused, explicit TLS' arith_eval $arith_val + 1 setup_test_without_data profile$arith_val trap imap_cleanup 0 cat >> "$MH" <> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi start if ! grep -q 'Connection to "127.0.0.1:255" failed: Connection refused' "$actual"; then cat "$actual" >&2 fail 'ECONN not reported' fi # Use fakeinetd for tests of the parts of explicit TLS handling before TLS negotiation. start_fakeinetd "$imapd" imapd_pid=$fakeinetd_pid arith_eval $arith_val + 1 setup_test_without_data profile$arith_val trap imap_cleanup 0 cat >> "$MH" <> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi ################################################################################ start_test 'rudely close pre-greeting, explicit TLS' cat > "$imapd" <&2 fail 'EOF error not reported' fi ################################################################################ start_test 'protocol violation in greeting, explicit TLS' # Greets with simply "trash\r\n". cat > "$imapd" <&2 fail 'protocol error not reported' fi ################################################################################ start_test 'STARTTLS capability not offered' cat > "$imapd" <&2 fail 'missing STARTTLS not reported' fi ################################################################################ start_test 'STARTTLS capability not offered after capabilities requested' cat > "$imapd" <&2 fail 'missing STARTTLS not reported' fi ################################################################################ start_test 'rudely closed after STARTTLS' cat > "$imapd" <&2 fail 'EOF not reported' fi ################################################################################ start_test 'trash response to STARTTLS' cat > "$imapd" <&2 fail 'protocol error not reported' fi kill $imapd_pid imapd_pid= ################################################################################ start_test 'connection refused, implicit TLS' arith_eval $arith_val + 1 setup_test_without_data profile$arith_val trap imap_cleanup 0 cat >> "$MH" <> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi start if ! grep -q 'Connection to "127.0.0.1:255" failed: Connection refused' "$actual"; then cat "$actual" >&2 fail 'ECONN not reported' fi ################################################################################ # Start the server for the rest. start_stunnel imap "$imapd" arith_eval $arith_val + 1 setup_test_without_data profile$arith_val trap imap_cleanup 0 cat >> "$MH" <> "$MH" echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH" fi ################################################################################ start_test 'rudely close pre-greeting, implicit TLS' cat > "$imapd" <&2 fail 'EOF error not reported' fi ################################################################################ start_test 'no SASL-IR capability' cat > "$imapd" <&2 fail 'missing SASL-IR not reported' fi ################################################################################ start_test 'no UIDPLUS capability' cat > "$imapd" <&2 fail 'missing UIDPLUS not reported' fi ################################################################################ start_test 'protocol violation in greeting, implicit TLS' # Greets with simply "trash\r\n". cat > "$imapd" <&2 fail 'protocol error not reported' fi ################################################################################ start_test 'protocol violation in AUTHENTICATE response' # Responds to the AUTHENTICATE command with simply "trash\r\n". cat > "$imapd" <&2 fail 'protocol error not reported' fi finish_test exit $failed