@@ -19,7 +19,7 @@ class ClientValidationJwtTest(unittest.TestCase):
19
19
def test_generate_payload_basic (self ):
20
20
vp = ValidationPayload (
21
21
method = 'GET' ,
22
- url = 'https://api.twilio.com/' ,
22
+ path = 'https://api.twilio.com/' ,
23
23
query_string = 'q1=v1' ,
24
24
signed_headers = ['headerb' , 'headera' ],
25
25
all_headers = {'head' : 'toe' , 'headera' : 'vala' , 'headerb' : 'valb' },
@@ -47,7 +47,7 @@ def test_generate_payload_basic(self):
47
47
def test_generate_payload_complex (self ):
48
48
vp = ValidationPayload (
49
49
method = 'GET' ,
50
- url = 'https://api.twilio.com/' ,
50
+ path = 'https://api.twilio.com/' ,
51
51
query_string = 'q1=v1&q2=v2&a=b' ,
52
52
signed_headers = ['headerb' , 'headera' ],
53
53
all_headers = {'head' : 'toe' , 'Headerb' : 'valb' , 'yeezy' : 'weezy' },
@@ -74,7 +74,7 @@ def test_generate_payload_complex(self):
74
74
def test_generate_payload_no_query_string (self ):
75
75
vp = ValidationPayload (
76
76
method = 'GET' ,
77
- url = 'https://api.twilio.com/' ,
77
+ path = 'https://api.twilio.com/' ,
78
78
query_string = '' ,
79
79
signed_headers = ['headerb' , 'headera' ],
80
80
all_headers = {'head' : 'toe' , 'Headerb' : 'valb' , 'yeezy' : 'weezy' },
@@ -101,11 +101,11 @@ def test_generate_payload_no_query_string(self):
101
101
def test_generate_payload_no_req_body (self ):
102
102
vp = ValidationPayload (
103
103
method = 'GET' ,
104
- url = 'https://api.twilio.com/' ,
104
+ path = 'https://api.twilio.com/' ,
105
105
query_string = 'q1=v1' ,
106
106
signed_headers = ['headerb' , 'headera' ],
107
107
all_headers = {'head' : 'toe' , 'headera' : 'vala' , 'headerb' : 'valb' },
108
- body = None
108
+ body = ''
109
109
)
110
110
111
111
expected_payload = '\n ' .join ([
@@ -116,6 +116,7 @@ def test_generate_payload_no_req_body(self):
116
116
'headerb:valb' ,
117
117
'' ,
118
118
'headera;headerb' ,
119
+ ''
119
120
])
120
121
expected_payload = ClientValidationJwt ._hash (expected_payload )
121
122
@@ -128,7 +129,7 @@ def test_generate_payload_no_req_body(self):
128
129
def test_generate_payload_header_keys_lowercased (self ):
129
130
vp = ValidationPayload (
130
131
method = 'GET' ,
131
- url = 'https://api.twilio.com/' ,
132
+ path = 'https://api.twilio.com/' ,
132
133
query_string = 'q1=v1' ,
133
134
signed_headers = ['headerb' , 'headera' ],
134
135
all_headers = {'head' : 'toe' , 'Headera' : 'vala' , 'Headerb' : 'valb' },
@@ -156,7 +157,7 @@ def test_generate_payload_header_keys_lowercased(self):
156
157
def test_generate_payload_no_headers (self ):
157
158
vp = ValidationPayload (
158
159
method = 'GET' ,
159
- url = 'https://api.twilio.com/' ,
160
+ path = 'https://api.twilio.com/' ,
160
161
query_string = 'q1=v1' ,
161
162
signed_headers = ['headerb' , 'headera' ],
162
163
all_headers = {},
@@ -179,11 +180,11 @@ def test_generate_payload_no_headers(self):
179
180
self .assertEqual ('headera;headerb' , actual_payload ['hrh' ])
180
181
self .assertEqual (expected_payload , actual_payload ['rqh' ])
181
182
182
- def test_generate_payload_schema_correct (self ):
183
+ def test_generate_payload_schema_correct_1 (self ):
183
184
"""Test against a known good rqh payload hash"""
184
185
vp = ValidationPayload (
185
186
method = 'GET' ,
186
- url = '/Messages' ,
187
+ path = '/Messages' ,
187
188
query_string = 'PageSize=5&Limit=10' ,
188
189
signed_headers = ['authorization' , 'host' ],
189
190
all_headers = {'authorization' : 'foobar' , 'host' : 'api.twilio.com' },
@@ -198,10 +199,29 @@ def test_generate_payload_schema_correct(self):
198
199
self .assertEqual ('authorization;host' , actual_payload ['hrh' ])
199
200
self .assertEqual (expected_hash , actual_payload ['rqh' ])
200
201
202
+ def test_generate_payload_schema_correct_2 (self ):
203
+ """Test against a known good rqh payload hash"""
204
+ vp = ValidationPayload (
205
+ method = 'POST' ,
206
+ path = '/Messages' ,
207
+ query_string = '' ,
208
+ signed_headers = ['authorization' , 'host' ],
209
+ all_headers = {'authorization' : 'foobar' , 'host' : 'api.twilio.com' },
210
+ body = 'testbody'
211
+ )
212
+
213
+ expected_hash = 'bd792c967c20d546c738b94068f5f72758a10d26c12979677501e1eefe58c65a'
214
+
215
+ jwt = ClientValidationJwt ('AC123' , 'SK123' , 'CR123' , 'secret' , vp )
216
+
217
+ actual_payload = jwt ._generate_payload ()
218
+ self .assertEqual ('authorization;host' , actual_payload ['hrh' ])
219
+ self .assertEqual (expected_hash , actual_payload ['rqh' ])
220
+
201
221
def test_jwt_payload (self ):
202
222
vp = ValidationPayload (
203
223
method = 'GET' ,
204
- url = '/Messages' ,
224
+ path = '/Messages' ,
205
225
query_string = 'PageSize=5&Limit=10' ,
206
226
signed_headers = ['authorization' , 'host' ],
207
227
all_headers = {'authorization' : 'foobar' , 'host' : 'api.twilio.com' },
@@ -229,7 +249,7 @@ def test_jwt_payload(self):
229
249
def test_jwt_signing (self ):
230
250
vp = ValidationPayload (
231
251
method = 'GET' ,
232
- url = '/Messages' ,
252
+ path = '/Messages' ,
233
253
query_string = 'PageSize=5&Limit=10' ,
234
254
signed_headers = ['authorization' , 'host' ],
235
255
all_headers = {'authorization' : 'foobar' , 'host' : 'api.twilio.com' },
0 commit comments