]> diplodocus.org Git - nmh/blob - test/oauth/test-inc
Editing of man/next.man.
[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 check_exit '-eq 1' inc -
14
15 setup_pop
16
17 #
18 # success cases
19 #
20
21 # TEST
22 start_test 'access token ready, pop server accepts message'
23
24 fake_creds <<EOF
25 access-nobody@example.com: test-access
26 expire-nobody@example.com: 2000000000
27 EOF
28
29 start_pop_xoauth
30
31 test_inc_success
32
33 # TEST
34 start_test 'expired access token, refresh works, pop server accepts message'
35
36 fake_creds <<EOF
37 access-nobody@example.com: old-access
38 refresh-nobody@example.com: test-refresh
39 expire-nobody@example.com: 1414303986
40 EOF
41
42 expect_http_post_refresh
43
44 fake_json_response <<EOF
45 {
46 "access_token": "test-access",
47 "token_type": "Bearer",
48 "expires_in": 3600
49 }
50 EOF
51
52 start_fakehttp
53 start_pop_xoauth
54
55 test_inc_success
56
57 check_http_req
58
59 #
60 # fail cases
61 #
62
63 # TEST
64 start_test 'refresh gets proper error from http'
65
66 fake_creds <<EOF
67 access-nobody@example.com: test-access
68 refresh-nobody@example.com: test-refresh
69 EOF
70
71 expect_http_post_refresh
72
73 fake_http_response '400 Bad Request' <<EOF
74 Content-Type: application/json
75
76 {
77 "error": "invalid_request"
78 }
79 EOF
80
81 start_fakehttp
82 start_pop_xoauth
83
84 test_inc 'inc: error refreshing OAuth2 token
85 inc: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'
86
87 check_http_req
88
89 # TEST
90 start_test 'pop server rejects token'
91
92 fake_creds <<EOF
93 access-nobody@example.com: wrong-access
94 expire-nobody@example.com: 2000000000
95 EOF
96
97 start_pop_xoauth
98
99 test_inc 'inc: Authentication failed: -ERR [AUTH] Invalid credentials.'
100
101 # TEST
102 start_test "pop server doesn't support oauth"
103
104 fake_creds <<EOF
105 access-nobody@example.com: test-access
106 expire-nobody@example.com: 2000000000
107 EOF
108
109 start_pop testuser testpass
110
111 test_inc 'inc: POP server does not support SASL'
112
113 clean_fakehttp
114 finish_test
115
116 exit ${failed:-0}