]> diplodocus.org Git - nmh/blob - test/oauth/test-inc
Merge branch 'master' into xoauth
[nmh] / test / oauth / test-inc
1 #!/bin/sh
2 #
3 # Test the XOAUTH2 support in inc
4 #
5
6 if test -z "${MH_OBJ_DIR}"; then
7 srcdir=`dirname "$0"`/../..
8 MH_OBJ_DIR=`cd "${srcdir}" && pwd`; export MH_OBJ_DIR
9 fi
10
11 . "${srcdir}/test/oauth/common.sh"
12
13 setup_pop
14
15 #
16 # success cases
17 #
18
19 # TEST
20 echo 'access token ready, pop server accepts message'
21
22 fake_creds <<EOF
23 access: test-access
24 expire: 2000000000
25 EOF
26
27 start_pop_xoauth
28
29 test_inc_success
30
31 # TEST
32 echo 'expired access token, refresh works, pop server accepts message'
33
34 fake_creds <<EOF
35 access: old-access
36 refresh: test-refresh
37 expire: 1414303986
38 EOF
39
40 expect_http_post_refresh
41
42 fake_json_response <<EOF
43 {
44 "access_token": "test-access",
45 "token_type": "Bearer",
46 "expires_in": 3600
47 }
48 EOF
49
50 expect_creds <<EOF
51 access: test-access
52 refresh: test-refresh
53 expire:
54 EOF
55
56 start_fakehttp
57 start_pop_xoauth
58
59 test_inc_success
60
61 check_http_req
62
63 #
64 # fail cases
65 #
66
67 # TEST
68 echo 'refresh gets proper error from http'
69
70 fake_creds <<EOF
71 access: test-access
72 refresh: test-refresh
73 EOF
74
75 expect_http_post_refresh
76
77 fake_http_response '400 Bad Request' <<EOF
78 Content-Type: application/json
79
80 {
81 "error": "invalid_request"
82 }
83 EOF
84
85 start_fakehttp
86
87 test_inc 'inc: error refreshing OAuth2 token
88 inc: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'
89
90 check_http_req
91
92 # TEST
93 echo 'pop server rejects token'
94
95 fake_creds <<EOF
96 access: wrong-access
97 expire: 2000000000
98 EOF
99
100 start_pop_xoauth
101
102 test_inc 'inc: -ERR [AUTH] Invalid credentials.'
103
104 # TEST
105 echo "pop server doesn't support oauth"
106
107 fake_creds <<EOF
108 access: test-access
109 expire: 2000000000
110 EOF
111
112 start_pop testuser testpass
113
114 test_inc 'inc: POP server does not support SASL'
115
116 exit ${failed:-0}