Skip to content
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
15 changes: 10 additions & 5 deletions pubnub/endpoints/access/grant_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from pubnub.enums import HttpMethod, PNOperationType
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
from pubnub.models.consumer.v3.channel import Channel
from pubnub.models.consumer.v3.group import Group
from pubnub.models.consumer.v3.space import Space
from pubnub.models.consumer.v3.user import User
from pubnub.models.consumer.v3.uuid import UUID
from pubnub.structures import Envelope


Expand Down Expand Up @@ -55,23 +60,23 @@ def authorized_user(self, user) -> 'GrantToken':
self._authorized_uuid = user
return self

def spaces(self, spaces: Union[str, List[str]]) -> 'GrantToken':
def spaces(self, spaces: List[Space]) -> 'GrantToken':
self._channels = spaces
return self

def users(self, users: Union[str, List[str]]) -> 'GrantToken':
def users(self, users: List[User]) -> 'GrantToken':
self._uuids = users
return self

def channels(self, channels: Union[str, List[str]]) -> 'GrantToken':
def channels(self, channels: List[Channel]) -> 'GrantToken':
self._channels = channels
return self

def groups(self, groups: Union[str, List[str]]) -> 'GrantToken':
def groups(self, groups: List[Group]) -> 'GrantToken':
self._groups = groups
return self

def uuids(self, uuids: Union[str, List[str]]) -> 'GrantToken':
def uuids(self, uuids: List[UUID]) -> 'GrantToken':
self._uuids = uuids
return self

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "POST",
"uri": "https://ps.pndsn.com/v3/pam/{PN_KEY_PAM_SUBSCRIBE}/grant",
"body": {
"pickle": "gASVKgEAAAAAAABYIwEAAHsidHRsIjogNjAsICJwZXJtaXNzaW9ucyI6IHsicmVzb3VyY2VzIjogeyJjaGFubmVscyI6IHsic29tZV9zcGFjZV9pZCI6IDN9LCAiZ3JvdXBzIjoge30sICJ1dWlkcyI6IHt9LCAidXNlcnMiOiB7fSwgInNwYWNlcyI6IHsic29tZV9zcGFjZV9pZCI6IDN9fSwgInBhdHRlcm5zIjogeyJjaGFubmVscyI6IHsic29tZV8qIjogM30sICJncm91cHMiOiB7fSwgInV1aWRzIjoge30sICJ1c2VycyI6IHt9LCAic3BhY2VzIjogeyJzb21lXyoiOiAzfX0sICJtZXRhIjoge30sICJ1dWlkIjogInNvbWVfdXNlcl9pZCJ9fZQu"
},
"headers": {
"host": [
"ps.pndsn.com"
],
"accept": [
"*/*"
],
"accept-encoding": [
"gzip, deflate"
],
"connection": [
"keep-alive"
],
"user-agent": [
"PubNub-Python/10.1.0"
],
"content-type": [
"application/json"
],
"content-length": [
"291"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Date": [
"Tue, 11 Feb 2025 20:46:28 GMT"
],
"Content-Type": [
"text/javascript; charset=UTF-8"
],
"Transfer-Encoding": [
"chunked"
],
"Connection": [
"keep-alive"
],
"cache-control": [
"no-cache, no-store, must-revalidate"
],
"content-encoding": [
"gzip"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Access-Control-Expose-Headers": [
"*"
]
},
"body": {
"pickle": "gASVKQEAAAAAAAB9lIwGc3RyaW5nlEIWAQAAH4sIAAAAAAAA/1WQTY+CMBiE/8qmZzcBzBrlRuTD1VCzJfJ12ZRScWmhSosKxv++dTcePL2ZeWcyyXMDJVYY2DfQUClxRYENop4QLcAEKMFoq52T51sO842goZ0akFuukAzcq0uaeDzuUI0DvxeJORaWydMpvGQJ5KnFmWPAlrTL6uvhzXxFrIXK48VIAr/W95g70C1TOAgPmWXCmfB0Lo04CqDIktkhb+G5SOL9poJuPl1f9F93ty/+ax+pPEWHpy5W/zmd4YTrPd3HSZl9rjfzGDrSDDtzNhfZ9jpEYv8dLwvxXgbFLmTVh0GYS+tTA+4TIGl3/iEPNs4fmrcQt5pVpxFJhVUvgW0Zxv0XP0RQKE0BAACUcy4="
}
}
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "POST",
"uri": "https://ps.pndsn.com/v3/pam/{PN_KEY_PAM_SUBSCRIBE}/grant",
"body": {
"pickle": "gASVhAEAAAAAAABYfQEAAHsidHRsIjogNjAsICJwZXJtaXNzaW9ucyI6IHsicmVzb3VyY2VzIjogeyJjaGFubmVscyI6IHsic29tZV9jaGFubmVsX2lkIjogMjM5fSwgImdyb3VwcyI6IHsic29tZV9ncm91cF9pZCI6IDV9LCAidXVpZHMiOiB7InNvbWVfdXVpZCI6IDEwNH0sICJ1c2VycyI6IHsic29tZV91dWlkIjogMTA0fSwgInNwYWNlcyI6IHsic29tZV9jaGFubmVsX2lkIjogMjM5fX0sICJwYXR0ZXJucyI6IHsiY2hhbm5lbHMiOiB7InNvbWVfKiI6IDd9LCAiZ3JvdXBzIjogeyJzb21lXyoiOiAxfSwgInV1aWRzIjogeyJzb21lXyoiOiAzMn0sICJ1c2VycyI6IHsic29tZV8qIjogMzJ9LCAic3BhY2VzIjogeyJzb21lXyoiOiA3fX0sICJtZXRhIjoge30sICJ1dWlkIjogInNvbWVfdXVpZCJ9fZQu"
},
"headers": {
"host": [
"ps.pndsn.com"
],
"accept": [
"*/*"
],
"accept-encoding": [
"gzip, deflate"
],
"connection": [
"keep-alive"
],
"user-agent": [
"PubNub-Python/10.1.0"
],
"content-type": [
"application/json"
],
"content-length": [
"381"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Date": [
"Tue, 11 Feb 2025 20:46:03 GMT"
],
"Content-Type": [
"text/javascript; charset=UTF-8"
],
"Transfer-Encoding": [
"chunked"
],
"Connection": [
"keep-alive"
],
"cache-control": [
"no-cache, no-store, must-revalidate"
],
"content-encoding": [
"gzip"
],
"Access-Control-Allow-Credentials": [
"true"
],
"Access-Control-Expose-Headers": [
"*"
]
},
"body": {
"pickle": "gASVVwEAAAAAAAB9lIwGc3RyaW5nlEJEAQAAH4sIAAAAAAAA/2WRyW6DMBRFf6XyOgsGNS2RugglOE1UKkBgYBOZyaQMTmIDGZR/rwlIVdWl77PPebq+gRRzDBY3UGeMYZKBBXDbJBEHMAOcllkjkuPKVJalKcE6O/GeG+naYdA4G0ntXw+e842h2VKkXWNFrgLFoiF6biN0zjGywxfJapLmvYgDq4uRn0fqpksDfZiZtmr14dzsEkXjka89OHHts0CpSvilGWlgXSiqRq7qywMPrxw5RVX5PxeswK0cOPjnRdSMvi1JDeHsKYrG+xeqT9569L4edcmSE3X7+6YgxFkPXPdvBuUqhXCaOYdp78c+gnmIZEL63NppHtEVT2IfuudT7O6L1rR3utGsN6zOSmnZbu2wyNkbuM8Ay07dPhl6Xz5qf/rEjfiHk6ifccxbBhaKJN1/AJLBBPipAQAAlHMu"
}
}
}
]
}

This file was deleted.

30 changes: 20 additions & 10 deletions tests/integrational/native_sync/test_grant_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,43 @@
from pubnub.pubnub import PubNub
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
from pubnub.models.consumer.v3.channel import Channel
from pubnub.models.consumer.v3.group import Group
from pubnub.models.consumer.v3.uuid import UUID
from pubnub.models.consumer.v3.space import Space
from tests.helper import pnconf_pam_copy
from tests.helper import pnconf_pam_env_copy
from tests.integrational.vcr_helper import pn_vcr

pubnub = PubNub(pnconf_pam_copy())
pubnub = PubNub(pnconf_pam_env_copy())
pubnub.config.uuid = "test_grant"


@pn_vcr.use_cassette(
'tests/integrational/fixtures/native_sync/pam/grant_token_with_uuid_and_channels.yaml',
'tests/integrational/fixtures/native_sync/pam/grant_token_with_uuid_and_channels.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
)
def test_grant_auth_key_with_uuid_and_channels():
envelope = pubnub.grant_token()\
.ttl(60)\
.authorized_uuid('some_uuid')\
envelope = pubnub.grant_token() \
.ttl(60) \
.authorized_uuid('some_uuid') \
.channels([
Channel().id('some_channel_id').read().write(),
Channel().pattern('some_*').read().write()
])\
Channel().id('some_channel_id').read().write().manage().delete().get().update().join(),
Channel().pattern('some_*').read().write().manage()
]) \
.groups([
Group().id('some_group_id').read().manage(),
Group().pattern('some_*').read(),
]) \
.uuids([
UUID().id('some_uuid').get().update().delete(),
UUID().pattern('some_*').get()
]) \
.sync()
assert isinstance(envelope.result, PNGrantTokenResult)
assert envelope.result.token


@pn_vcr.use_cassette(
'tests/integrational/fixtures/native_sync/pam/grant_token_user_space.yaml',
'tests/integrational/fixtures/native_sync/pam/grant_token_user_space.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']
)
def test_grant_auth_key_with_user_id_and_spaces():
Expand Down
Loading