2
2
3
3
from nose .tools import assert_equal
4
4
from twilio .jwt import decode
5
- from twilio .access_token import AccessToken
5
+ from twilio .access_token import AccessToken , ConversationsGrant , IpMessagingGrant
6
6
7
7
ACCOUNT_SID = 'AC123'
8
8
SIGNING_KEY_SID = 'SK123'
@@ -26,56 +26,45 @@ def _validate_claims(self, payload):
26
26
assert_is_not_none (payload ['grants' ])
27
27
28
28
def test_empty_grants (self ):
29
- scat = AccessToken (SIGNING_KEY_SID , ACCOUNT_SID , 'secret' )
29
+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
30
30
token = str (scat )
31
- assert_is_not_none (token )
32
- payload = decode (token , 'secret' )
33
- self ._validate_claims (payload )
34
- assert_equal ([], payload ['grants' ])
35
31
36
- def test_single_grant (self ):
37
- scat = AccessToken (SIGNING_KEY_SID , ACCOUNT_SID , 'secret' )
38
- scat .add_grant ('https://api.twilio.com/**' )
39
- token = str (scat )
40
32
assert_is_not_none (token )
41
33
payload = decode (token , 'secret' )
42
34
self ._validate_claims (payload )
43
- assert_equal (1 , len (payload ['grants' ]))
44
- assert_equal ('https://api.twilio.com/**' , payload ['grants' ][0 ]['res' ])
45
- assert_equal (['*' ], payload ['grants' ][0 ]['act' ])
35
+ assert_equal ({}, payload ['grants' ])
36
+
37
+ def test_conversations_grant (self ):
38
+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
39
+ scat .add_grant (ConversationsGrant ())
46
40
47
- def test_endpoint_grant (self ):
48
- scat = AccessToken (SIGNING_KEY_SID , ACCOUNT_SID , 'secret' )
49
- scat .add_endpoint_grant ('bob' )
50
41
token = str (scat )
51
42
assert_is_not_none (token )
52
43
payload = decode (token , 'secret' )
53
44
self ._validate_claims (payload )
54
45
assert_equal (1 , len (payload ['grants' ]))
55
- assert_equal ('sip:bob@AC123.endpoint.twilio.com' ,
56
- payload ['grants' ][0 ]['res' ])
57
- assert_equal (['listen' , 'invite' ], payload ['grants' ][0 ]['act' ])
46
+ assert_equal ({}, payload ['grants' ]['rtc' ])
47
+
48
+ def test_ip_messaging_grant (self ):
49
+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
50
+ scat .add_grant (IpMessagingGrant ())
58
51
59
- def test_rest_grant (self ):
60
- scat = AccessToken (SIGNING_KEY_SID , ACCOUNT_SID , 'secret' )
61
- scat .add_rest_grant ('/Apps' )
62
52
token = str (scat )
63
53
assert_is_not_none (token )
64
54
payload = decode (token , 'secret' )
65
55
self ._validate_claims (payload )
66
56
assert_equal (1 , len (payload ['grants' ]))
67
- assert_equal ('https://api.twilio.com/2010-04-01/Accounts/AC123/Apps' ,
68
- payload ['grants' ][0 ]['res' ])
69
- assert_equal (['*' ], payload ['grants' ][0 ]['act' ])
57
+ assert_equal ({}, payload ['grants' ]['ip_messaging' ])
58
+
59
+ def test_grants (self ):
60
+ scat = AccessToken (ACCOUNT_SID , SIGNING_KEY_SID , 'secret' )
61
+ scat .add_grant (ConversationsGrant ())
62
+ scat .add_grant (IpMessagingGrant ())
70
63
71
- def test_enable_nts (self ):
72
- scat = AccessToken (SIGNING_KEY_SID , ACCOUNT_SID , 'secret' )
73
- scat .enable_nts ()
74
64
token = str (scat )
75
65
assert_is_not_none (token )
76
66
payload = decode (token , 'secret' )
77
67
self ._validate_claims (payload )
78
- assert_equal (1 , len (payload ['grants' ]))
79
- assert_equal ('https://api.twilio.com/2010-04-01/Accounts/AC123/Tokens.json' ,
80
- payload ['grants' ][0 ]['res' ])
81
- assert_equal (['POST' ], payload ['grants' ][0 ]['act' ])
68
+ assert_equal (2 , len (payload ['grants' ]))
69
+ assert_equal ({}, payload ['grants' ]['rtc' ])
70
+ assert_equal ({}, payload ['grants' ]['ip_messaging' ])
0 commit comments