]> diplodocus.org Git - nmh/blob - test/oauth/test-inc
Replace getcpy() with mh_xstrdup() where the string isn't NULL.
[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 start_test 'access token ready, pop server accepts message'
21
22 fake_creds <<EOF
23 access-nobody@example.com: test-access
24 expire-nobody@example.com: 2000000000
25 EOF
26
27 start_pop_xoauth
28
29 test_inc_success
30
31 # TEST
32 start_test 'expired access token, refresh works, pop server accepts message'
33
34 fake_creds <<EOF
35 access-nobody@example.com: old-access
36 refresh-nobody@example.com: test-refresh
37 expire-nobody@example.com: 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 start_fakehttp
51 start_pop_xoauth
52
53 test_inc_success
54
55 check_http_req
56
57 #
58 # fail cases
59 #
60
61 # TEST
62 start_test 'refresh gets proper error from http'
63
64 fake_creds <<EOF
65 access-nobody@example.com: test-access
66 refresh-nobody@example.com: test-refresh
67 EOF
68
69 expect_http_post_refresh
70
71 fake_http_response '400 Bad Request' <<EOF
72 Content-Type: application/json
73
74 {
75 "error": "invalid_request"
76 }
77 EOF
78
79 start_fakehttp
80 start_pop_xoauth
81
82 test_inc 'inc: error refreshing OAuth2 token
83 inc: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'
84
85 check_http_req
86
87 # TEST
88 start_test 'pop server rejects token'
89
90 fake_creds <<EOF
91 access-nobody@example.com: wrong-access
92 expire-nobody@example.com: 2000000000
93 EOF
94
95 start_pop_xoauth
96
97 test_inc 'inc: Authentication failed: -ERR [AUTH] Invalid credentials.'
98
99 # TEST
100 start_test "pop server doesn't support oauth"
101
102 fake_creds <<EOF
103 access-nobody@example.com: test-access
104 expire-nobody@example.com: 2000000000
105 EOF
106
107 start_pop testuser testpass
108
109 test_inc 'inc: POP server does not support SASL'
110
111 clean_fakehttp
112 finish_test
113
114 exit ${failed:-0}