8000 merged the jwt tests · alexcchan/twilio-python@3997bcc · GitHub
[go: up one dir, main page]

Skip to content

Commit 3997bcc

Browse files
committed
merged the jwt tests
1 parent ee137b3 commit 3997bcc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

tests/test_jwt.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from twilio import jwt
23
import sys
34
if sys.version_info < (2, 7):
@@ -7,7 +8,7 @@
78

89
from twilio.util import TwilioCapability
910

10-
class TokenTest(unittest.TestCase):
11+
class JwtTest(unittest.TestCase):
1112

1213
def assertIn(self, foo, bar, msg=None):
1314
"""backport for 2.6"""
@@ -80,3 +81,43 @@ def test_decode(self):
8081
self.assertIn(outgoing_uri, scope)
8182
self.assertIn(incoming_uri, scope)
8283
self.assertIn(event_uri, scope)
84+
85+
def setUp(self):
86+
self.payload = {"iss": "jeff", "exp": int(time.time()), "claim": "insanity"}
87+
88+
def test_encode_decode(self):
89+
secret = 'secret'
90+
jwt_message = jwt.encode(self.payload, secret)
91+
decoded_payload = jwt.decode(jwt_message, secret)
92+
self.assertEqual(decoded_payload, self.payload)
93+
94+
def test_bad_secret(self):
95+
right_secret = 'foo'
96+
bad_secret = 'bar'
97+
jwt_message = jwt.encode(self.payload, right_secret)
98+
self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message, bad_secret)
99+
100+
def test_decodes_valid_jwt(self):
101+
example_payload = {"hello": "world"}
102+
example_secret = "secret"
103+
example_jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJoZWxsbyI6ICJ3b3JsZCJ9.tvagLDLoaiJKxOKqpBXSEGy7SYSifZhjntgm9ctpyj8"
104+
decoded_payload = jwt.decode(example_jwt, example_secret)
105+
self.assertEqual(decoded_payload, example_payload)
106+
107+
def test_allow_skip_verification(self):
108+
right_secret = 'foo'
109+
bad_secret = 'bar'
110+
jwt_message = jwt.encode(self.payload, right_secret)
111+
decoded_payload = jwt.decode(jwt_message, verify=False)
112+
self.assertEqual(decoded_payload, self.payload)
113+
114+
def test_no_secret(self):
115+
right_secret = 'foo'
116+
bad_secret = 'bar'
117+
jwt_message = jwt.encode(self.payload, right_secret)
118+
self.assertRaises(jwt.DecodeError, jwt.decode, jwt_message)
119+
120+
def test_invalid_crypto_alg(self):
121+
self.assertRaises(NotImplementedError, jwt.encode, self.payload, "secret", "HS1024")
122+
123+

tests/test_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_validation(self):
5252
self.assertTrue(validator.validate(uri, params, expected))
5353

5454
@unittest.skip("utf 8 support still a work in progress")
55-
def test_international_sms(self):
55+
def te_st_international_sms(self):
5656

5757
token = os.environ["TWILIO_AUTH_TOKEN"]
5858
validator = RequestValidator(token)

0 commit comments

Comments
 (0)
0