8000 Update video grant by jingming · Pull Request #313 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Update video grant #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to y 10000 our account

Merged
merged 1 commit into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions tests/unit/jwt/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import (
ConversationsGrant,
IpMessagingGrant,
SyncGrant,
VoiceGrant,
Expand Down Expand Up @@ -80,30 +79,17 @@ def test_identity(self):
'identity': 'test@twilio.com'
}, decoded_token.payload['grants'])

def test_conversations_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))

token = scat.to_jwt()
assert_is_not_none(token)
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(1, len(decoded_token.payload['grants']))
assert_equal({
'configuration_profile_sid': 'CP123'
}, decoded_token.payload['grants']['rtc'])

def test_video_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(VideoGrant(configuration_profile_sid='CP123'))
scat.add_grant(VideoGrant(room='CP123'))

token = scat.to_jwt()
assert_is_not_none(token)
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(1, len(decoded_token.payload['grants']))
assert_equal({
'configuration_profile_sid': 'CP123'
'room': 'CP123'
}, decoded_token.payload['grants']['video'])

def test_ip_messaging_grant(self):
Expand Down Expand Up @@ -138,15 +124,15 @@ def test_sync_grant(self):

def test_grants(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant())
scat.add_grant(VideoGrant())
scat.add_grant(IpMessagingGrant())

token = scat.to_jwt()
assert_is_not_none(token)
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(2, len(decoded_token.payload['grants']))
assert_equal({}, decoded_token.payload['grants']['rtc'])
assert_equal({}, decoded_token.payload['grants']['video'])
assert_equal({}, decoded_token.payload['grants']['ip_messaging'])

def test_programmable_voice_grant(self):
Expand Down Expand Up @@ -176,7 +162,7 @@ def test_programmable_voice_grant(self):

def test_pass_grants_in_constructor(self):
grants = [
ConversationsGrant(),
VideoGrant(),
IpMessagingGrant()
]
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret', grants=grants)
Expand All @@ -187,15 +173,15 @@ def test_pass_grants_in_constructor(self):
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert_equal(2, len(decoded_token.payload['grants']))
assert_equal({}, decoded_token.payload['grants']['rtc'])
assert_equal({}, decoded_token.payload['grants']['video'])
assert_equal({}, decoded_token.payload['grants']['ip_messaging'])

def test_constructor_validates_grants(self):
grants = [ConversationsGrant, 'GrantMeAccessToEverything']
grants = [VideoGrant, 'GrantMeAccessToEverything']
self.assertRaises(ValueError, AccessToken, ACCOUNT_SID, SIGNING_KEY_SID, 'secret',
grants=grants)

def test_add_grant_validates_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant())
scat.add_grant(VideoGrant())
self.assertRaises(ValueError, scat.add_grant, 'GrantRootAccess')
25 changes: 4 additions & 21 deletions twilio/jwt/access_token/grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,6 @@ def to_payload(self):
return grant


class ConversationsGrant(AccessTokenGrant):
"""Grant to access Twilio Conversations"""
def __init__(self, configuration_profile_sid=None):
self.configuration_profile_sid = configuration_profile_sid

@property
def key(self):
return "rtc"

def to_payload(self):
grant = {}
if self.configuration_profile_sid:
grant['configuration_profile_sid'] = self.configuration_profile_sid

return grant


class VoiceGrant(AccessTokenGrant):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not doing these anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope.

"""Grant to access Twilio Programmable Voice"""
def __init__(self,
Expand Down Expand Up @@ -105,16 +88,16 @@ def to_payload(self):

class VideoGrant(AccessTokenGrant):
"""Grant to access Twilio Video"""
def __init__(self, configuration_profile_sid=None):
self.configuration_profile_sid = configuration_profile_sid
def __init__(self, room=None):
self.room = room

@property
def key(self):
return "video"

def to_payload(self):
grant = {}
if self.configuration_profile_sid:
grant['configuration_profile_sid'] = self.configuration_profile_sid
if self.room:
grant['room'] = self.room

return grant
0