]> diplodocus.org Git - nmh/blob - test/imap/test-folder-create-disallowed
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-folder-create-disallowed
1 #!/bin/sh
2
3 # Errors: can't live with 'em can't live without 'em
4 # - Priorities:
5 # 0. db integrity
6 # 1. report comprehensible error to user
7 # 2. comprehensible log (good enough for a quality bug report)
8 # 3. clean close of IMAP connection
9 # - If db open:
10 # 1. clean close if at all possible
11 # 2. if not, report failure along with the original failure
12 # - If nmh connection open:
13 # 1. write blind error
14 # 2. if that write failed log but ignore
15 # 3. Else close the socket, log+ignore error here too
16 # - If IMAP connection is open:
17 # 1. write a blind LOGOUT
18 # 2. if that write failed log but ignore
19 # 3. Else close the socket, log+ignore error here too
20 # - If error is detected at layer that has both nmh and IMAP connection
21 # available, handle nmh first; we fight for the users
22 # - In any case, finally error!(it)
23 # Types:
24 # Environmental
25 # - read/write error
26 # - open error (except ENOENT)
27 # Action: report, log, clean shutdown
28 # Protocol
29 # - either the bytes received were bytes expected or they weren't;
30 # context for logging is useful, but we don't need fine-grained types
31 # - this goes for nmh-folder-manager and IMAP protocols
32 # Action: report, log, clean shutdown
33 # Invalid request
34 # A request is valid or not regardless of the state of the system.
35 # - E.g.
36 # - UID FETCH without mailbox open - protocol violation: EXAMINE first
37 # - UID FETCH fred - `fred` is not a valid UID
38 # - In theory, this maps to IMAP `BAD response code, but can we rely on it?
39 # Action: Internal error, below
40 # Illegal request
41 # A request must be valid before its legality may be judged.
42 # - E.g.
43 # - FETCH 10 on mailbox with 9 messages - NO such message
44 # - EXAMINE nosuchmailbox - NO mailbox by that name exists
45 # - In theory, this maps to IMAP `NO response code, but can we rely on it?
46 # - These SHOULD only be caused by user action, e.g. create folder that already exists.
47 # Action: report, log, NO SHUTDOWN
48 # Internal
49 # Action: report, log, clean shutdown
50
51 testname=${0#$srcdir/}
52
53 if test -z "$MH_OBJ_DIR"; then
54 srcdir=`dirname "$0"`/../..
55 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
56 fi
57
58 . "$MH_OBJ_DIR/test/common.sh"
59
60 rm -rf "$MH_TEST_DIR/panda"
61
62 imap_cleanup() {
63 #### Save exit status to use as status for this program.
64 status=$?
65 set +e
66
67 [ -n "$imapd_pid" ] && kill $imapd_pid
68
69 # TODO uh oops don't need two profiles for this one
70 for i in 1 2; do
71 set_mh_profile profile$i
72 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
73 done
74
75 # TODO have cleanup allow additional cleanup registration?
76 # Or just allow it to accept status as argument.
77 (exit $status)
78 cleanup
79 }
80
81 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
82 install -d "$covdir"
83
84 mkdir "$MH_TEST_DIR/panda"
85 mkdir "$MH_TEST_DIR/panda/test"
86
87 expected="$MH_TEST_DIR/$$.expected"
88 actual="$MH_TEST_DIR/$$.actual"
89
90 start_fakeinetd env "HOME=$MH_TEST_DIR/panda" "$PANDA_IMAPD"
91 imapd_pid=$fakeinetd_pid
92
93 start() {
94 rm -f "$MH_TEST_DIR/$profile/imap.d/socket"
95 status=0
96 LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw" "$MH_OBJ_DIR/target/debug/mhimap" imap start > "$actual" 2>&1 || status=$?
97 }
98
99 # setup profile 2 and 1, leaving 1 as active profile
100 for i in 2 1; do
101 setup_test_without_data profile$i
102 trap imap_cleanup 0
103 cat >> "$MH" <<EOF
104 Managed-Folders: imap
105 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
106 imap-socket: $MH_TEST_DIR/profile$i/imap.d/socket
107 imap-db: $MH_TEST_DIR/profile$i/imap.d
108 imap-host: 127.0.0.1
109 imap-port: $fakeinetd_port
110 imap-tls: don't protect my data i know what i'm doing
111 imap-auth: PREAUTH
112 imap-mailbox-root: test/
113 EOF
114 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
115 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
116 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
117 fi
118 start
119 done
120
121 ################################################################################
122 start_test 'profile1: folder +imap/fold -create'
123 check_exit '-eq 0' folder +imap/fold -create
124
125 ################################################################################
126 start_test 'profile2: folder +imap/fold -create'
127
128 set_mh_profile profile2
129
130 # TODO Oops folder -create when folder is already known LOCALLY to exist tries to create over IMAP!
131
132 cat > "$expected" <<EOF
133 folder: failed to create folder imap/fold: Can't create mailbox node $MH_TEST_DIR/panda/test/fold: File exists
134 EOF
135
136 exitcode=1
137 folder +imap/fold -create > "$actual" 2>&1 || exitcode=$?
138 check "$actual" "$expected"
139 if [ $exitcode -ne 1 ]; then
140 fail "folder exited $exitcode rather than 1"
141 fi
142
143 ################################################################################
144 start_test 'profile2: inc +imap leaves imap/fold SELECTed'
145 inc +imap
146
147 ################################################################################
148 start_test 'profile1: rmf +imap/fold fails because profile1 has it SELECTED'
149
150 set_mh_profile profile1
151
152 rmf +imap/fold -nointeractive || status=$?
153 if ! grep -q 'NO Mailbox test/fold is in use by another process' "$MH_TEST_DIR/$profile/imap.d/stderr"; then
154 cat "$MH_TEST_DIR/$profile/imap.d/stderr" >&2
155 fail 'mailbox deletion not disallowed'
156 fi
157
158 finish_test
159 exit ${failed:-0}