File: test-inc

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (116 lines) | stat: -rwxr-xr-x 1,914 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
#
# Test the XOAUTH2 support in inc
#

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname "$0"`/../..
    MH_OBJ_DIR=`cd "${srcdir}" && pwd`; export MH_OBJ_DIR
fi

. "${srcdir}/test/oauth/common.sh"

check_exit '-eq 1' inc -

setup_pop

#
# success cases
#

# TEST
start_test 'access token ready, pop server accepts message'

fake_creds <<EOF
access-nobody@example.com: test-access
expire-nobody@example.com: 2000000000
EOF

start_pop_xoauth

test_inc_success

# TEST
start_test 'expired access token, refresh works, pop server accepts message'

fake_creds <<EOF
access-nobody@example.com: old-access
refresh-nobody@example.com: test-refresh
expire-nobody@example.com: 1414303986
EOF

expect_http_post_refresh

fake_json_response <<EOF
{
  "access_token": "test-access",
  "token_type": "Bearer",
  "expires_in": 3600
}
EOF

start_fakehttp
start_pop_xoauth

test_inc_success

check_http_req

#
# fail cases
#

# TEST
start_test 'refresh gets proper error from http'

fake_creds <<EOF
access-nobody@example.com: test-access
refresh-nobody@example.com: test-refresh
EOF

expect_http_post_refresh

fake_http_response '400 Bad Request' <<EOF
Content-Type: application/json

{
  "error": "invalid_request"
}
EOF

start_fakehttp
start_pop_xoauth

test_inc 'inc: error refreshing OAuth2 token
inc: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'

check_http_req

# TEST
start_test 'pop server rejects token'

fake_creds <<EOF
access-nobody@example.com: wrong-access
expire-nobody@example.com: 2000000000
EOF

start_pop_xoauth

test_inc 'inc: Authentication failed: -ERR [AUTH] Invalid credentials.'

# TEST
start_test "pop server doesn't support oauth"

fake_creds <<EOF
access-nobody@example.com: test-access
expire-nobody@example.com: 2000000000
EOF

start_pop testuser testpass

test_inc 'inc: POP server does not support SASL'

clean_fakehttp
finish_test

exit ${failed:-0}