]> diplodocus.org Git - nmh/blob - test/imap/test-xoauth
expect this commit to be force-replaced periodically
[nmh] / test / imap / test-xoauth
1 #!/bin/sh
2
3 # TODO fold into test-login?
4
5 if test -z "$MH_OBJ_DIR"; then
6 srcdir=`dirname "$0"`/../..
7 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
8 fi
9
10 . "${srcdir}/test/oauth/common.sh"
11
12 # common.sh sets this to something crazy; did i do that?!
13 testname=${0#$srcdir/}
14
15 setup_test_without_data Mail
16
17 setup_service
18 fake_creds <<EOF
19 access-testuser: test-access
20 refresh-testuser: test-refresh
21 expire-testuser: 2000000000
22 EOF
23
24 imap_cleanup() {
25 #### Save exit status to use as status for this program.
26 status=$?
27 set +e
28
29 rm -f "$imapd"
30
31 [ -n "$imapd_pid" ] && kill $imapd_pid
32 "$MH_OBJ_DIR/target/debug/mhimap" imap shutdown
33
34 # TODO have cleanup allow additional cleanup registration?
35 # Or just allow it to accept status as argument.
36 (exit $status)
37 cleanup
38 }
39 trap imap_cleanup 0
40
41 covdir="$MH_OBJ_DIR/covdata/${MH_COVERAGE_PROFILE:-default}/$testname"
42 install -d "$covdir"
43 export LLVM_PROFILE_FILE="$covdir/$profile-%m.profraw"
44
45 imapd="$MH_TEST_DIR/$$.imapd"
46 start_fakeinetd "$imapd"
47 imapd_pid=$fakeinetd_pid
48
49 cat >> "$MH" <<EOF
50 Managed-Folders: imap
51 imap-manager: $MH_OBJ_DIR/target/debug/imap-folder-manager
52 imap-socket: $MH_TEST_DIR/Mail/imap.d/socket
53 imap-db: $MH_TEST_DIR/Mail/imap.d
54 imap-host: 127.0.0.1
55 imap-port: $fakeinetd_port
56 imap-tls: don't protect my data i know what i'm doing
57 imap-auth: SASL
58 imap-user: testuser
59 imap-saslmech: xoauth2
60 imap-authservice: test
61 EOF
62 if [ -n "$MH_TEST_IMAP_LOG_LEVEL" ]; then
63 echo "imap-log-level: $MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
64 echo "imap-log-$MH_TEST_IMAP_LOG_LEVEL-to: $MH_TEST_DIR/$profile/imap.d/log.$MH_TEST_IMAP_LOG_LEVEL" >> "$MH"
65 fi
66
67 # TODO OAUTHBEARER? oooooh
68 # TODO when imlementing capability put this after the greeting
69 # * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH
70 # 1 OK
71 cat > "$imapd" <<EOSCRIPT
72 #!/bin/sh
73 cat <<EOF
74 * OK Gimap ready for requests
75 * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH
76 1 OK capability response
77 * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584
78 1 OK authenticate response
79 1 OK LIST completed
80 EOF
81 while read line; do :; done
82 EOSCRIPT
83 chmod 755 "$imapd"
84
85 # TODO lighter-weight command? Just trying to show auth worked.
86 check_exit '-eq 0' inc +imap
87
88 finish_test
89 exit ${failed:-0}