def test_generate_payload_no_query_string(self): vp = ValidationPayload( method='GET', path='https://api.twilio.com/', query_string='', signed_headers=['headerb', 'headera'], all_headers={'head': 'toe', 'Headerb': 'valb', 'yeezy': 'weezy'}, body='me=letop&you=leworst' ) expected_payload = '\n'.join([ 'GET', 'https://api.twilio.com/', '', 'headerb:valb', '', 'headera;headerb', '{}'.format(ClientValidationJwt._hash('me=letop&you=leworst')) ]) expected_payload = ClientValidationJwt._hash(expected_payload) jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp) actual_payload = jwt._generate_payload() self.assertEqual('headera;headerb', actual_payload['hrh']) self.assertEqual(expected_payload, actual_payload['rqh'])
def test_generate_payload_no_req_body(self): vp = ValidationPayload( method='GET', path='https://api.twilio.com/', query_string='q1=v1', signed_headers=['headerb', 'headera'], all_headers={'head': 'toe', 'headera': 'vala', 'headerb': 'valb'}, body='' ) expected_payload = '\n'.join([ 'GET', 'https://api.twilio.com/', 'q1=v1', 'headera:vala', 'headerb:valb', '', 'headera;headerb', '' ]) expected_payload = ClientValidationJwt._hash(expected_payload) jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp) actual_payload = jwt._generate_payload() self.assertEqual('headera;headerb', actual_payload['hrh']) self.assertEqual(expected_payload, actual_payload['rqh'])
def test_generate_payload_no_headers(self): vp = ValidationPayload(method='GET', path='https://api.twilio.com/', query_string='q1=v1', signed_headers=['headerb', 'headera'], all_headers={}, body='me=letop&you=leworst') expected_payload = '\n'.join([ 'GET', 'https://api.twilio.com/', 'q1=v1', '', 'headera;headerb', '{}'.format(ClientValidationJwt._hash('me=letop&you=leworst')) ]) expected_payload = ClientValidationJwt._hash(expected_payload) jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp) actual_payload = jwt._generate_payload() self.assertEqual('headera;headerb', actual_payload['hrh']) self.assertEqual(expected_payload, actual_payload['rqh'])
def test_generate_payload_complex(self): vp = ValidationPayload(method='GET', path='https://api.twilio_code.com/', query_string='q1=v1&q2=v2&a=b', signed_headers=['headerb', 'headera'], all_headers={ 'head': 'toe', 'Headerb': 'valb', 'yeezy': 'weezy' }, body='me=letop&you=leworst') expected_payload = '\n'.join([ 'GET', 'https://api.twilio_code.com/', 'a=b&q1=v1&q2=v2', 'headerb:valb', '', 'headera;headerb', '{}'.format(ClientValidationJwt._hash('me=letop&you=leworst')) ]) expected_payload = ClientValidationJwt._hash(expected_payload) jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp) actual_payload = jwt._generate_payload() self.assertEqual('headera;headerb', actual_payload['hrh']) self.assertEqual(expected_payload, actual_payload['rqh'])
def test_generate_payload_no_req_body(self): vp = ValidationPayload(method='GET', path='https://api.twilio.com/', query_string='q1=v1', signed_headers=['headerb', 'headera'], all_headers={ 'head': 'toe', 'headera': 'vala', 'headerb': 'valb' }, body='') expected_payload = '\n'.join([ 'GET', 'https://api.twilio.com/', 'q1=v1', 'headera:vala', 'headerb:valb', '', 'headera;headerb', '' ]) expected_payload = ClientValidationJwt._hash(expected_payload) jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp) actual_payload = jwt._generate_payload() self.assertEqual('headera;headerb', actual_payload['hrh']) self.assertEqual(expected_payload, actual_payload['rqh'])