diff --git a/.pubnub.yml b/.pubnub.yml index c9815bbd..5a43ae14 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,21 @@ name: python -version: 4.1.7 +version: 4.1.8 schema: 1 scm: github.com/pubnub/python changelog: + - version: v4.1.8 + date: Dec 24, 2019 + changes: + - type: improvement + text: Introduced delete permission to Grant endpoint. Migrated to v2 enpdoints for old PAM methods. + - type: feature + text: Added TokenManager and GrantToken method. + - type: improvement + text: Resolved warnings caused by the use of deprecated methods. + - type: bug + text: Removed Audit tests. + - type: bug + text: Resolved incorrectly reported SDK version. - version: v4.1.7 date: Dec 2, 2019 changes: @@ -137,6 +150,10 @@ changelog: features: access: - ACCESS-GRANT + - ACCESS-GRANT-MANAGE + - ACCESS-GRANT-DELETE + - ACCESS-GRANT-V3 + - ACCESS-TOKEN-MANAGEMENT - ACCESS-SECRET-KEY-ALL-ACCESS channel-groups: - CHANNEL-GROUPS-ADD-CHANNELS @@ -159,8 +176,10 @@ features: - PUBLISH-RAW-JSON - PUBLISH-WITH-METADATA - PUBLISH-GET + - PUBLISH-POST - PUBLISH-ASYNC - PUBLISH-FIRE + - PUBLISH-REPLICATION-FLAG storage: - STORAGE-REVERSE - STORAGE-INCLUDE-TIMETOKEN @@ -195,6 +214,8 @@ features: - OBJECTS-UPDATE-SPACE - OBJECTS-DELETE-SPACE - OBJECTS-GET-MEMBERSHIPS + - OBJECTS-MANAGE-MEMBERSHIPS + - OBJECTS-MANAGE-MEMBERS - OBJECTS-JOIN-SPACES - OBJECTS-UPDATE-MEMBERSHIPS - OBJECTS-LEAVE-SPACES diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd6443e..02370111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [4.1.8](https://github.com/pubnub/python/tree/v4.1.8) + + [Full Changelog](https://github.com/pubnub/python/compare/v4.1.7...v4.1.8) + +- 🌟 Introduced delete permission to Grant endpoint. Migrated to v2 enpdoints for old PAM methods. +- 🌟 Added TokenManager and GrantToken method. +- 🌟Resolved warnings caused by the use of deprecated methods. +- 🐛Removed Audit tests. +- 🐛Resolved incorrectly reported SDK version. + ## [4.1.7](https://github.com/pubnub/python/tree/v4.1.7) [Full Changelog](https://github.com/pubnub/python/compare/v4.1.6...v4.1.7) diff --git a/pubnub/endpoints/access/audit.py b/pubnub/endpoints/access/audit.py index 935958b0..f3347440 100644 --- a/pubnub/endpoints/access/audit.py +++ b/pubnub/endpoints/access/audit.py @@ -5,7 +5,7 @@ class Audit(Endpoint): - AUDIT_PATH = "/v1/auth/audit/sub-key/%s" + AUDIT_PATH = "/v2/auth/audit/sub-key/%s" def __init__(self, pubnub): Endpoint.__init__(self, pubnub) diff --git a/pubnub/endpoints/access/grant.py b/pubnub/endpoints/access/grant.py index 64dbff1a..1ebe70ae 100644 --- a/pubnub/endpoints/access/grant.py +++ b/pubnub/endpoints/access/grant.py @@ -7,7 +7,7 @@ class Grant(Endpoint): - GRANT_PATH = "/v1/auth/grant/sub-key/%s" + GRANT_PATH = "/v2/auth/grant/sub-key/%s" def __init__(self, pubnub): Endpoint.__init__(self, pubnub) @@ -17,6 +17,7 @@ def __init__(self, pubnub): self._read = None self._write = None self._manage = None + self._delete = None self._ttl = None self._sort_params = True @@ -45,6 +46,10 @@ def manage(self, flag): self._manage = flag return self + def delete(self, flag): + self._delete = flag + return self + def ttl(self, ttl): self._ttl = ttl return self @@ -58,6 +63,8 @@ def custom_params(self): params['w'] = '1' if self._write is True else '0' if self._manage is not None: params['m'] = '1' if self._manage is True else '0' + if self._delete is not None: + params['d'] = '1' if self._delete is True else '0' if len(self._auth_keys) > 0: params['auth'] = utils.join_items_and_encode(self._auth_keys) diff --git a/pubnub/endpoints/access/grant_token.py b/pubnub/endpoints/access/grant_token.py new file mode 100644 index 00000000..ae588073 --- /dev/null +++ b/pubnub/endpoints/access/grant_token.py @@ -0,0 +1,120 @@ +from pubnub import utils +from pubnub.endpoints.endpoint import Endpoint +from pubnub.errors import PNERR_RESOURCES_MISSING, PNERR_TTL_MISSING, PNERR_INVALID_META +from pubnub.exceptions import PubNubException +from pubnub.enums import HttpMethod, PNOperationType +from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult + + +class GrantToken(Endpoint): + GRANT_TOKEN_PATH = "/v3/pam/%s/grant" + + READ = 1 + WRITE = 2 + MANAGE = 4 + DELETE = 8 + CREATE = 16 + + def __init__(self, pubnub): + Endpoint.__init__(self, pubnub) + self._ttl = None + self._meta = None + self._channelList = [] + self._groupList = [] + self._userList = [] + self._spaceList = [] + + self._sort_params = True + + def ttl(self, ttl): + self._ttl = ttl + return self + + def meta(self, meta): + self._meta = meta + return self + + def users(self, users): + self._userList = users + return self + + def spaces(self, spaces): + self._spaceList = spaces + return self + + def custom_params(self): + return {} + + def build_data(self): + params = {'ttl': str(int(self._ttl))} + + permissions = {} + resources = {} + patterns = {} + + utils.parse_resources(self._channelList, "channels", resources, patterns) + utils.parse_resources(self._groupList, "groups", resources, patterns) + utils.parse_resources(self._userList, "users", resources, patterns) + utils.parse_resources(self._spaceList, "spaces", resources, patterns) + + permissions['resources'] = resources + permissions['patterns'] = patterns + + if self._meta is not None: + if isinstance(self._meta, dict): + permissions['meta'] = self._meta + else: + raise PubNubException(pn_error=PNERR_INVALID_META) + else: + permissions['meta'] = {} + + params['permissions'] = permissions + + return utils.write_value_as_string(params) + + def build_path(self): + return GrantToken.GRANT_TOKEN_PATH % self.pubnub.config.subscribe_key + + def http_method(self): + return HttpMethod.POST + + def validate_params(self): + self.validate_subscribe_key() + self.validate_secret_key() + self.validate_ttl() + self.validate_resources() + + def create_response(self, envelope): + return PNGrantTokenResult.from_json(envelope['data']) + + def is_auth_required(self): + return False + + def affected_channels(self): + # generate a list of channels when they become supported in PAMv3 + return None + + def affected_channels_groups(self): + # generate a list of groups when they become supported in PAMv3 + return None + + def request_timeout(self): + return self.pubnub.config.non_subscribe_request_timeout + + def connect_timeout(self): + return self.pubnub.config.connect_timeout + + def operation_type(self): + return PNOperationType.PNAccessManagerGrantToken + + def name(self): + return "Grant Token" + + def validate_resources(self): + if (self._userList is None or len(self._userList) == 0) and \ + (self._spaceList is None or len(self._spaceList) == 0): + raise PubNubException(pn_error=PNERR_RESOURCES_MISSING) + + def validate_ttl(self): + if self._ttl is None: + raise PubNubException(pn_error=PNERR_TTL_MISSING) diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 9848d950..92d870e7 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -1,5 +1,7 @@ from abc import ABCMeta, abstractmethod +import logging + from pubnub import utils from pubnub.enums import PNStatusCategory, PNOperationType from pubnub.errors import PNERR_SUBSCRIBE_KEY_MISSING, PNERR_PUBLISH_KEY_MISSING, PNERR_CHANNEL_OR_GROUP_MISSING, \ @@ -9,6 +11,8 @@ from pubnub.models.consumer.pn_error_data import PNErrorData from ..structures import RequestOptions, ResponseInfo +logger = logging.getLogger("pubnub") + class Endpoint(object): SERVER_RESPONSE_SUCCESS = 200 @@ -90,7 +94,6 @@ def options(self): def sync(self): self.validate_params() - envelope = self.pubnub.request_sync(self.options()) if envelope.status.is_error(): @@ -154,22 +157,17 @@ def callback(params_to_merge): if self.is_auth_required() and self.pubnub.config.auth_key is not None: custom_params['auth'] = self.pubnub.config.auth_key - if self.pubnub.config.secret_key is not None: - custom_params['timestamp'] = str(self.pubnub.timestamp()) - signed_input = (self.pubnub.config.subscribe_key + "\n" + self.pubnub.config.publish_key + "\n") - - if operation_type == PNOperationType.PNAccessManagerAudit: - signed_input += 'audit\n' - elif operation_type == PNOperationType.PNAccessManagerGrant or \ - operation_type == PNOperationType.PNAccessManagerRevoke: - signed_input += 'grant\n' - else: - signed_input += self.build_path() + "\n" + if self.pubnub.config.disable_token_manager is False and self.pubnub.config.auth_key is None: + tms_properties = self.get_tms_properties() + if tms_properties is not None: + token = self.pubnub.get_token(tms_properties) + if token is not None: + custom_params['auth'] = token + else: + logger.warning("No token found for: " + str(tms_properties)) - signed_input += utils.prepare_pam_arguments(custom_params) - signature = utils.sign_sha256(self.pubnub.config.secret_key, signed_input) - - custom_params['signature'] = signature + if self.pubnub.config.secret_key is not None: + utils.sign_request(self, self.pubnub, custom_params, self.http_method(), self.build_data()) # REVIEW: add encoder map to not hardcode encoding here if operation_type == PNOperationType.PNPublishOperation and 'meta' in custom_params: @@ -248,3 +246,6 @@ def create_exception(self, category, response, response_info, exception): exception.status = status return exception + + def get_tms_properties(self): + return None diff --git a/pubnub/endpoints/membership/get_members.py b/pubnub/endpoints/membership/get_members.py index 2a8027cb..a5af63e8 100644 --- a/pubnub/endpoints/membership/get_members.py +++ b/pubnub/endpoints/membership/get_members.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.membership import PNGetMembersResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -98,3 +99,9 @@ def operation_type(self): def name(self): return 'Get members' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._space_id if self._space_id is not None else "" + ) diff --git a/pubnub/endpoints/membership/get_space_memberships.py b/pubnub/endpoints/membership/get_space_memberships.py index a0ffe566..eff67584 100644 --- a/pubnub/endpoints/membership/get_space_memberships.py +++ b/pubnub/endpoints/membership/get_space_memberships.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.membership import PNGetSpaceMembershipsResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -98,3 +99,9 @@ def operation_type(self): def name(self): return 'Get space membership' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._user_id if self._user_id is not None else "" + ) diff --git a/pubnub/endpoints/membership/manage_members.py b/pubnub/endpoints/membership/manage_members.py index e5cad199..57a0b898 100644 --- a/pubnub/endpoints/membership/manage_members.py +++ b/pubnub/endpoints/membership/manage_members.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.membership import PNManageMembersResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -108,3 +109,9 @@ def operation_type(self): def name(self): return 'Update members' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._space_id if self._space_id is not None else "" + ) diff --git a/pubnub/endpoints/membership/manage_memberships.py b/pubnub/endpoints/membership/manage_memberships.py index 66a28cd1..d2cc82f4 100644 --- a/pubnub/endpoints/membership/manage_memberships.py +++ b/pubnub/endpoints/membership/manage_memberships.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.membership import PNManageMembershipsResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -108,3 +109,9 @@ def operation_type(self): def name(self): return 'Update space memberships' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._user_id if self._user_id is not None else "" + ) diff --git a/pubnub/endpoints/space/create_space.py b/pubnub/endpoints/space/create_space.py index f65efc48..6459183d 100644 --- a/pubnub/endpoints/space/create_space.py +++ b/pubnub/endpoints/space/create_space.py @@ -1,7 +1,8 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.space import PNCreateSpaceResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -61,3 +62,9 @@ def operation_type(self): def name(self): return 'Create space' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._data['id'] if self._data is not None else "" + ) diff --git a/pubnub/endpoints/space/delete_space.py b/pubnub/endpoints/space/delete_space.py index e1f04a1e..a2d4eae6 100644 --- a/pubnub/endpoints/space/delete_space.py +++ b/pubnub/endpoints/space/delete_space.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.space import PNDeleteSpaceResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -52,3 +53,9 @@ def operation_type(self): def name(self): return 'Delete space' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._space_id if self._space_id is not None else "" + ) diff --git a/pubnub/endpoints/space/get_space.py b/pubnub/endpoints/space/get_space.py index 39c5b347..2b8c286f 100644 --- a/pubnub/endpoints/space/get_space.py +++ b/pubnub/endpoints/space/get_space.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.space import PNGetSpaceResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -57,3 +58,9 @@ def operation_type(self): def name(self): return 'Get space' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._space_id if self._space_id is not None else "" + ) diff --git a/pubnub/endpoints/space/get_spaces.py b/pubnub/endpoints/space/get_spaces.py index b02af49f..823f0a92 100644 --- a/pubnub/endpoints/space/get_spaces.py +++ b/pubnub/endpoints/space/get_spaces.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.space import PNGetSpacesResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType class GetSpaces(Endpoint): @@ -86,3 +87,9 @@ def operation_type(self): def name(self): return 'Get spaces' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id="" + ) diff --git a/pubnub/endpoints/space/update_space.py b/pubnub/endpoints/space/update_space.py index c480c587..bc03eeab 100644 --- a/pubnub/endpoints/space/update_space.py +++ b/pubnub/endpoints/space/update_space.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.space import PNUpdateSpaceResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -69,3 +70,9 @@ def operation_type(self): def name(self): return 'Update space' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.SPACE, + resource_id=self._space_id if self._space_id is not None else "" + ) diff --git a/pubnub/endpoints/users/create_user.py b/pubnub/endpoints/users/create_user.py index c28359ce..6c7579c5 100644 --- a/pubnub/endpoints/users/create_user.py +++ b/pubnub/endpoints/users/create_user.py @@ -1,7 +1,8 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.user import PNCreateUserResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -61,3 +62,9 @@ def operation_type(self): def name(self): return 'Create user' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._data['id'] if self._data is not None else "" + ) diff --git a/pubnub/endpoints/users/delete_user.py b/pubnub/endpoints/users/delete_user.py index 5b6bf12f..5bebc46f 100644 --- a/pubnub/endpoints/users/delete_user.py +++ b/pubnub/endpoints/users/delete_user.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.user import PNDeleteUserResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -52,3 +53,9 @@ def operation_type(self): def name(self): return 'Delete user' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._user_id if self._user_id is not None else "" + ) diff --git a/pubnub/endpoints/users/get_user.py b/pubnub/endpoints/users/get_user.py index fbaca447..cfb95545 100644 --- a/pubnub/endpoints/users/get_user.py +++ b/pubnub/endpoints/users/get_user.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.user import PNGetUserResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -57,3 +58,9 @@ def operation_type(self): def name(self): return 'Get user' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._user_id if self._user_id is not None else "" + ) diff --git a/pubnub/endpoints/users/get_users.py b/pubnub/endpoints/users/get_users.py index 984f0601..9a4fe294 100644 --- a/pubnub/endpoints/users/get_users.py +++ b/pubnub/endpoints/users/get_users.py @@ -1,8 +1,9 @@ import six from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.user import PNGetUsersResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType class GetUsers(Endpoint): @@ -86,3 +87,9 @@ def operation_type(self): def name(self): return 'Get users' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id="" + ) diff --git a/pubnub/endpoints/users/update_user.py b/pubnub/endpoints/users/update_user.py index c9756974..93d9a10c 100644 --- a/pubnub/endpoints/users/update_user.py +++ b/pubnub/endpoints/users/update_user.py @@ -2,8 +2,9 @@ from pubnub import utils from pubnub.endpoints.endpoint import Endpoint +from pubnub.managers import TokenManagerProperties from pubnub.models.consumer.user import PNUpdateUserResult -from pubnub.enums import HttpMethod, PNOperationType +from pubnub.enums import HttpMethod, PNOperationType, PNResourceType from pubnub.exceptions import PubNubException @@ -69,3 +70,9 @@ def operation_type(self): def name(self): return 'Update user' + + def get_tms_properties(self): + return TokenManagerProperties( + resource_type=PNResourceType.USER, + resource_id=self._user_id if self._user_id is not None else "" + ) diff --git a/pubnub/enums.py b/pubnub/enums.py index 570754eb..6d7ef510 100644 --- a/pubnub/enums.py +++ b/pubnub/enums.py @@ -80,6 +80,8 @@ class PNOperationType(object): PNManageMembersOperation = 39 PNManageMembershipsOperation = 40 + PNAccessManagerGrantToken = 41 + class PNHeartbeatNotificationOptions(object): NONE = 1 @@ -97,3 +99,15 @@ class PNPushType(object): APNS = 1 MPNS = 2 GCM = 3 + + +class PNResourceType(object): + CHANNEL = "channel" + GROUP = "group" + USER = "user" + SPACE = "space" + + +class PNMatchType(object): + RESOURCE = "resource" + PATTERN = "pattern" diff --git a/pubnub/errors.py b/pubnub/errors.py index fb677338..2f3eaa6d 100644 --- a/pubnub/errors.py +++ b/pubnub/errors.py @@ -28,3 +28,8 @@ PNERR_PUSH_DEVICE_MISSING = "Device ID is missing for push operation" PNERROR_PUSH_TYPE_MISSING = "Push Type is missing" PNERR_PAM_NO_FLAGS = "At least one flag should be specified" +PNERR_RESOURCES_MISSING = "Resources missing" +PNERR_TTL_MISSING = "TTL missing" +PNERR_INVALID_META = "Invalid meta parameter" +PNERR_PERMISSION_MISSING = "Permission missing" +PNERR_INVALID_ACCESS_TOKEN = "Invalid access token" diff --git a/pubnub/managers.py b/pubnub/managers.py index 88e40810..1c51cc26 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -4,14 +4,18 @@ import math import time import copy +import base64 +from cbor2 import loads from . import utils -from .enums import PNStatusCategory, PNReconnectionPolicy, PNOperationType +from .enums import PNStatusCategory, PNReconnectionPolicy, PNOperationType, PNResourceType, PNMatchType from .models.consumer.common import PNStatus from .models.server.subscribe import SubscribeEnvelope from .dtos import SubscribeOperation, UnsubscribeOperation from .callbacks import SubscribeCallback, ReconnectionCallback from .models.subscription_item import SubscriptionItem +from .errors import PNERR_INVALID_ACCESS_TOKEN +from .exceptions import PubNubException logger = logging.getLogger("pubnub") @@ -478,6 +482,127 @@ def endpoint_name_for_operation(operation_type): PNOperationType.PNGetSpaceMembershipsOperation: 'obj', PNOperationType.PNManageMembersOperation: 'obj', PNOperationType.PNManageMembershipsOperation: 'obj', + + PNOperationType.PNAccessManagerGrantToken: 'pamv3', }[operation_type] return endpoint + + +class TokenManager(object): + + def __init__(self): + self._map = {} + self.init_map() + + def init_map(self): + resources = [PNResourceType.USER, PNResourceType.SPACE] + + for resource in resources: + skeleton_map = { + PNMatchType.RESOURCE: {}, + PNMatchType.PATTERN: {} + } + self._map[resource] = skeleton_map + + def set_token(self, token): + unwrapped_token = self.unwrap_token(token) + self.store_token(unwrapped_token, token) + + def set_tokens(self, tokens): + for token in tokens: + self.set_token(token) + + def get_token(self, tms_properties): + resource_token = self.get_token_by_match(tms_properties, PNMatchType.RESOURCE) + + if resource_token is None: + return self.get_token_by_match(tms_properties, PNMatchType.PATTERN) + + return resource_token + + def get_tokens(self): + return self._map + + def get_tokens_by_resource(self, resource_type): + return self._map[resource_type] + + def store_token(self, unwrapped_token, token): + match_types = [ + PNMatchType.RESOURCE, + PNMatchType.PATTERN + ] + + for asset in match_types: + short_match_type = self.get_shortened_match_type(asset) + + if short_match_type in unwrapped_token: + res_object = unwrapped_token[short_match_type] + + for r_type in res_object.keys(): + single_res_object = res_object[r_type] + for r_name in single_res_object.keys(): + if asset == PNMatchType.PATTERN: + self._map[self.get_extended_resource_type(r_type)][asset].clear() + + self._map[self.get_extended_resource_type(r_type)][asset][r_name] = token + + def unwrap_token(self, token): + raw = token + + raw = raw.replace("_", "/").replace("-", "+") + byte_array = base64.b64decode(raw) + + try: + unwrapped_obj = loads(byte_array) + decoded_obj = utils.decode_utf8_dict(unwrapped_obj) + + return decoded_obj + except Exception: + raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN) + + def get_token_by_match(self, tms_properties, match_type): + if tms_properties is None or tms_properties.resource_type is None or tms_properties.resource_id is None: + return None + + if match_type != PNMatchType.PATTERN: + if tms_properties.resource_id in self._map[tms_properties.resource_type][match_type]: + token = self._map[tms_properties.resource_type][match_type][tms_properties.resource_id] + if token is not None: + return token + else: + string_token_wrapper_dict = self._map[tms_properties.resource_type][match_type] + if len(string_token_wrapper_dict.keys()) > 0: + first_key = list(string_token_wrapper_dict.keys())[0] + return string_token_wrapper_dict[first_key] + + return None + + def get_extended_resource_type(self, r_type_abbr): + if r_type_abbr == "chan": + return PNResourceType.CHANNEL + if r_type_abbr == "grp": + return PNResourceType.GROUP + if r_type_abbr == "usr": + return PNResourceType.USER + if r_type_abbr == "spc": + return PNResourceType.SPACE + + return r_type_abbr + + def get_shortened_match_type(self, match_type): + if match_type == PNMatchType.RESOURCE: + return "res" + if match_type == PNMatchType.PATTERN: + return "pat" + + return match_type + + +class TokenManagerProperties: + def __init__(self, resource_type, resource_id): + self.resource_type = resource_type + self.resource_id = resource_id + + def __str__(self): + return "resource_type: " + self.resource_type + ", resource_id: " + self.resource_id diff --git a/pubnub/models/consumer/access_manager.py b/pubnub/models/consumer/access_manager.py index 470cfb1f..800c68c5 100644 --- a/pubnub/models/consumer/access_manager.py +++ b/pubnub/models/consumer/access_manager.py @@ -5,7 +5,7 @@ class _PAMResult(object): - def __init__(self, level, subscribe_key, channels, groups, ttl=None, r=None, w=None, m=None): + def __init__(self, level, subscribe_key, channels, groups, ttl=None, r=None, w=None, m=None, d=None): self.level = level self.subscribe_key = subscribe_key self.channels = channels @@ -14,12 +14,13 @@ def __init__(self, level, subscribe_key, channels, groups, ttl=None, r=None, w=N self.read_enabled = r self.write_enabled = w self.manage_enabled = m + self.delete_enabled = d @classmethod def from_json(cls, json_input): constructed_channels = {} constructed_groups = {} - r, w, m, ttl = fetch_permissions(json_input) + r, w, m, d, ttl = fetch_permissions(json_input) if 'channel' in json_input: channel_name = json_input['channel'] @@ -74,41 +75,43 @@ def from_json(cls, json_input): r=r, w=w, m=m, + d=d, ttl=ttl, ) class PNAccessManagerAuditResult(_PAMResult): def __str__(self): - return "Current permissions are valid for %d minutes: read %s, write %s, manage: %s" % \ - (self.ttl or 0, self.read_enabled, self.write_enabled, self.manage_enabled) + return "Current permissions are valid for %d minutes: read %s, write %s, manage: %s, delete: %s" % \ + (self.ttl or 0, self.read_enabled, self.write_enabled, self.manage_enabled, self.delete_enabled) class PNAccessManagerGrantResult(_PAMResult): def __str__(self): - return "New permissions are set for %d minutes: read %s, write %s, manage: %s" % \ - (self.ttl or 0, self.read_enabled, self.write_enabled, self.manage_enabled) + return "New permissions are set for %d minutes: read %s, write %s, manage: %s, delete: %s" % \ + (self.ttl or 0, self.read_enabled, self.write_enabled, self.manage_enabled, self.delete_enabled) class _PAMEntityData(object): - def __init__(self, name, auth_keys=None, r=None, w=None, m=None, ttl=None): + def __init__(self, name, auth_keys=None, r=None, w=None, m=None, d=None, ttl=None): self.name = name self.auth_keys = auth_keys self.read_enabled = r self.write_enabled = w self.manage_enabled = m + self.delete_enabled = d self.ttl = ttl @classmethod def from_json(cls, name, json_input): - r, w, m, ttl = fetch_permissions(json_input) + r, w, m, d, ttl = fetch_permissions(json_input) constructed_auth_keys = {} if 'auths' in json_input: for auth_key, value in json_input['auths'].items(): constructed_auth_keys[auth_key] = PNAccessManagerKeyData.from_json(value) - return cls(name, constructed_auth_keys, r, w, m) + return cls(name, constructed_auth_keys, r, w, m, d, ttl) class PNAccessManagerChannelData(_PAMEntityData): @@ -120,22 +123,24 @@ class PNAccessManagerChannelGroupData(_PAMEntityData): class PNAccessManagerKeyData(object): - def __init__(self, r, w, m, ttl=None): + def __init__(self, r, w, m, d, ttl=None): self.read_enabled = r self.write_enabled = w self.manage_enabled = m + self.delete_enabled = d self.ttl = ttl @classmethod def from_json(cls, json_input): - r, w, m, ttl = fetch_permissions(json_input) - return PNAccessManagerKeyData(r, w, m, ttl) + r, w, m, d, ttl = fetch_permissions(json_input) + return PNAccessManagerKeyData(r, w, m, d, ttl) def fetch_permissions(json_input): r = None w = None m = None + d = None ttl = None if 'r' in json_input: @@ -147,7 +152,10 @@ def fetch_permissions(json_input): if 'm' in json_input: m = json_input['m'] == 1 + if 'd' in json_input: + d = json_input['d'] == 1 + if 'ttl' in json_input: ttl = json_input['ttl'] - return r, w, m, ttl + return r, w, m, d, ttl diff --git a/pubnub/models/consumer/v3/__init__.py b/pubnub/models/consumer/v3/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pubnub/models/consumer/v3/access_manager.py b/pubnub/models/consumer/v3/access_manager.py new file mode 100644 index 00000000..5f49a17d --- /dev/null +++ b/pubnub/models/consumer/v3/access_manager.py @@ -0,0 +1,23 @@ +""" +Possible responses of PAMv3 request +""" + + +class _PAMv3Result(object): + def __init__(self, token): + self.token = token + + @classmethod + def from_json(cls, json_input): + return cls( + token=json_input['token'] + ) + + +class PNGrantTokenResult(_PAMv3Result): + def __str__(self): + return "Grant token: %s" % \ + (self.token) + + def get_token(self): + return self.token diff --git a/pubnub/models/consumer/v3/channel.py b/pubnub/models/consumer/v3/channel.py new file mode 100644 index 00000000..74ef05e5 --- /dev/null +++ b/pubnub/models/consumer/v3/channel.py @@ -0,0 +1,29 @@ +from pubnub.models.consumer.v3.pn_resource import PNResource + + +class Channel(PNResource): + + def __init__(self, resource_name=None, resource_pattern=None): + super(Channel, self).__init__(resource_name, resource_pattern) + + @staticmethod + def id(channel_id): + channel = Channel(resource_name=channel_id) + return channel + + @staticmethod + def pattern(channel_pattern): + channel = Channel(resource_pattern=channel_pattern) + return channel + + def read(self): + self._read = True + return self + + def write(self): + self._write = True + return self + + def delete(self): + self._delete = True + return self diff --git a/pubnub/models/consumer/v3/group.py b/pubnub/models/consumer/v3/group.py new file mode 100644 index 00000000..2012ae80 --- /dev/null +++ b/pubnub/models/consumer/v3/group.py @@ -0,0 +1,25 @@ +from pubnub.models.consumer.v3.pn_resource import PNResource + + +class Group(PNResource): + + def __init__(self, resource_name=None, resource_pattern=None): + super(Group, self).__init__(resource_name, resource_pattern) + + @staticmethod + def id(group_id): + group = Group(resource_name=group_id) + return group + + @staticmethod + def pattern(group_pattern): + group = Group(resource_pattern=group_pattern) + return group + + def read(self): + self._read = True + return self + + def manage(self): + self._manage = True + return self diff --git a/pubnub/models/consumer/v3/pn_resource.py b/pubnub/models/consumer/v3/pn_resource.py new file mode 100644 index 00000000..3f2a3aa8 --- /dev/null +++ b/pubnub/models/consumer/v3/pn_resource.py @@ -0,0 +1,34 @@ +class PNResource(object): + + def __init__(self, resource_name=None, resource_pattern=None): + self._resource_name = resource_name + self._resource_pattern = resource_pattern + self._read = False + self._write = False + self._create = False + self._manage = False + self._delete = False + + def is_pattern_resource(self): + return self._resource_pattern is not None + + def get_id(self): + if self.is_pattern_resource(): + return self._resource_pattern + + return self._resource_name + + def is_read(self): + return self._read + + def is_write(self): + return self._write + + def is_create(self): + return self._create + + def is_manage(self): + return self._manage + + def is_delete(self): + return self._delete diff --git a/pubnub/models/consumer/v3/space.py b/pubnub/models/consumer/v3/space.py new file mode 100644 index 00000000..f1d96fc7 --- /dev/null +++ b/pubnub/models/consumer/v3/space.py @@ -0,0 +1,37 @@ +from pubnub.models.consumer.v3.pn_resource import PNResource + + +class Space(PNResource): + + def __init__(self, resource_name=None, resource_pattern=None): + super(Space, self).__init__(resource_name, resource_pattern) + + @staticmethod + def id(space_id): + space = Space(resource_name=space_id) + return space + + @staticmethod + def pattern(space_pattern): + space = Space(resource_pattern=space_pattern) + return space + + def read(self): + self._read = True + return self + + def write(self): + self._write = True + return self + + def create(self): + self._create = True + return self + + def manage(self): + self._manage = True + return self + + def delete(self): + self._delete = True + return self diff --git a/pubnub/models/consumer/v3/user.py b/pubnub/models/consumer/v3/user.py new file mode 100644 index 00000000..949c7cb5 --- /dev/null +++ b/pubnub/models/consumer/v3/user.py @@ -0,0 +1,37 @@ +from pubnub.models.consumer.v3.pn_resource import PNResource + + +class User(PNResource): + + def __init__(self, resource_name=None, resource_pattern=None): + super(User, self).__init__(resource_name, resource_pattern) + + @staticmethod + def id(user_id): + user = User(resource_name=user_id) + return user + + @staticmethod + def pattern(user_pattern): + user = User(resource_pattern=user_pattern) + return user + + def read(self): + self._read = True + return self + + def write(self): + self._write = True + return self + + def create(self): + self._create = True + return self + + def manage(self): + self._manage = True + return self + + def delete(self): + self._delete = True + return self diff --git a/pubnub/pnconfiguration.py b/pubnub/pnconfiguration.py index ed231667..f7042e2b 100644 --- a/pubnub/pnconfiguration.py +++ b/pubnub/pnconfiguration.py @@ -26,6 +26,7 @@ def __init__(self): self.heartbeat_notification_options = PNHeartbeatNotificationOptions.FAILURES self.reconnect_policy = PNReconnectionPolicy.NONE self.daemon = False + self.disable_token_manager = False self.heartbeat_default_values = True self._presence_timeout = PNConfiguration.DEFAULT_PRESENCE_TIMEOUT diff --git a/pubnub/pubnub.py b/pubnub/pubnub.py index 08176d4f..ade34118 100644 --- a/pubnub/pubnub.py +++ b/pubnub/pubnub.py @@ -47,6 +47,9 @@ def set_request_handler(self, handler): self._request_handler = handler def request_sync(self, endpoint_call_options): + if endpoint_call_options.method_string == "POST": + self.headers['Content-type'] = "application/json" + platform_options = PlatformOptions(self.headers, self.config) self.merge_in_params(endpoint_call_options) @@ -57,6 +60,9 @@ def request_sync(self, endpoint_call_options): return self._request_handler.sync_request(platform_options, endpoint_call_options) def request_async(self, endpoint_name, endpoint_call_options, callback, cancellation_event): + if endpoint_call_options.method_string == "POST": + self.headers['Content-type'] = "application/json" + platform_options = PlatformOptions(self.headers, self.config) self.merge_in_params(endpoint_call_options) @@ -123,7 +129,7 @@ def _call_time_callback(self, resp, status): def start_polling(self): if self._pubnub.config.reconnect_policy == PNReconnectionPolicy.NONE: - logger.warn("reconnection policy is disabled, please handle reconnection manually.") + logger.warning("reconnection policy is disabled, please handle reconnection manually.") return logger.debug("reconnection manager start at: %s" % utils.datetime_now()) diff --git a/pubnub/pubnub_asyncio.py b/pubnub/pubnub_asyncio.py index 46d4b634..01461b11 100644 --- a/pubnub/pubnub_asyncio.py +++ b/pubnub/pubnub_asyncio.py @@ -155,6 +155,9 @@ def _request_helper(self, options_func, cancellation_event): options.path, options.query_string) logger.debug("%s %s %s" % (options.method_string, log_url, options.data)) + if options.method_string == "POST": + self.headers['Content-type'] = "application/json" + if AIOHTTP_V in (1, 2): from yarl import URL url = URL(url, encoded=True) @@ -287,7 +290,7 @@ def _register_heartbeat_timer(self): def start_polling(self): if self._pubnub.config.reconnect_policy == PNReconnectionPolicy.NONE: - logger.warn("reconnection policy is disabled, please handle reconnection manually.") + logger.warning("reconnection policy is disabled, please handle reconnection manually.") return self._task = asyncio.ensure_future(self._register_heartbeat_timer()) diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 13afdd38..81b231a2 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -3,13 +3,14 @@ from abc import ABCMeta, abstractmethod -from .managers import BasePathManager +from .managers import BasePathManager, TokenManager, TokenManagerProperties from .builders import SubscribeBuilder from .builders import UnsubscribeBuilder from .endpoints.time import Time from .endpoints.history import History from .endpoints.access.audit import Audit from .endpoints.access.grant import Grant +from .endpoints.access.grant_token import GrantToken from .endpoints.access.revoke import Revoke from .endpoints.channel_groups.add_channel_to_channel_group import AddChannelToChannelGroup from .endpoints.channel_groups.list_channels_in_channel_group import ListChannelsInChannelGroup @@ -51,7 +52,7 @@ class PubNubCore: """A base class for PubNub Python API implementations""" - SDK_VERSION = "4.1.0" + SDK_VERSION = "4.1.8" SDK_NAME = "PubNub-Python" TIMESTAMP_DIVIDER = 1000 @@ -70,6 +71,7 @@ def __init__(self, config): self._publish_sequence_manager = None self._telemetry_manager = TelemetryManager() self._base_path_manager = BasePathManager(config) + self._token_manager = TokenManager() @property def base_origin(self): @@ -152,6 +154,9 @@ def publish(self): def grant(self): return Grant(self) + def grant_token(self): + return GrantToken(self) + def revoke(self): return Revoke(self) @@ -231,6 +236,24 @@ def time(self): def delete_messages(self): return HistoryDelete(self) + def set_token(self, token): + self._token_manager.set_token(token) + + def set_tokens(self, tokens): + self._token_manager.set_tokens(tokens) + + def get_token(self, tms_properties): + return self._token_manager.get_token(tms_properties) + + def get_token_by_resource(self, resource_id, resource_type): + return self._token_manager.get_token(TokenManagerProperties( + resource_id=resource_id, + resource_type=resource_type + )) + + def get_tokens_by_resource(self, resource_type): + return self._token_manager.get_tokens_by_resource(resource_type) + @staticmethod def timestamp(): return int(time.time()) diff --git a/pubnub/pubnub_tornado.py b/pubnub/pubnub_tornado.py index 7be1ea3a..d2499ab7 100644 --- a/pubnub/pubnub_tornado.py +++ b/pubnub/pubnub_tornado.py @@ -141,6 +141,9 @@ def _request_helper(self, options_func, cancellation_event): logger.debug("%s %s %s" % (options.method_string, url, options.data)) + if options.method_string == "POST": + self.headers['Content-type'] = "application/json" + start_timestamp = time.time() request = tornado.httpclient.HTTPRequest( @@ -320,7 +323,7 @@ def _register_heartbeat_timer(self): def start_polling(self): if self._pubnub.config.reconnect_policy == PNReconnectionPolicy.NONE: - logger.warn("reconnection policy is disabled, please handle reconnection manually.") + logger.warning("reconnection policy is disabled, please handle reconnection manually.") return self._pubnub.ioloop.spawn_callback(self._register_heartbeat_timer) diff --git a/pubnub/pubnub_twisted.py b/pubnub/pubnub_twisted.py index 8b999eb1..4f4eb537 100644 --- a/pubnub/pubnub_twisted.py +++ b/pubnub/pubnub_twisted.py @@ -224,6 +224,9 @@ def add_listener(self, listener): raise Exception("Subscription manager is not enabled for this instance") def request_async(self, endpoint_name, endpoint_call_options, callback, cancellation_event): + if endpoint_call_options.method_string == "POST": + self.headers['Content-type'] = "application/json" + def async_request(endpoint_call_options, cancellation_event, callback): def manage_failures(failure): # Cancelled diff --git a/pubnub/utils.py b/pubnub/utils.py index ba399084..e2737e18 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -15,9 +15,9 @@ import six -from .enums import PNStatusCategory, PNOperationType, PNPushType +from .enums import PNStatusCategory, PNOperationType, PNPushType, HttpMethod from .models.consumer.common import PNStatus -from .errors import PNERR_JSON_NOT_SERIALIZABLE +from .errors import PNERR_JSON_NOT_SERIALIZABLE, PNERR_PERMISSION_MISSING from .exceptions import PubNubException @@ -173,3 +173,108 @@ def strip_right(text, suffix): def datetime_now(): return datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") + + +def sign_request(endpoint, pn, custom_params, method, body): + custom_params['timestamp'] = str(pn.timestamp()) + + request_url = endpoint.build_path() + + encoded_query_string = prepare_pam_arguments(custom_params) + + is_v2_signature = not (request_url.startswith("/publish") and method == HttpMethod.POST) + + signed_input = "" + if not is_v2_signature: + signed_input += pn.config.subscribe_key + "\n" + signed_input += pn.config.publish_key + "\n" + signed_input += request_url + "\n" + signed_input += encoded_query_string + else: + signed_input += HttpMethod.string(method).upper() + "\n" + signed_input += pn.config.publish_key + "\n" + signed_input += request_url + "\n" + signed_input += encoded_query_string + "\n" + if body is not None: + signed_input += body + + signature = sign_sha256(pn.config.secret_key, signed_input) + if is_v2_signature: + signature = signature.rstrip("=") + signature = "v2." + signature + + custom_params['signature'] = signature + + +def parse_resources(resource_list, resource_set_name, resources, patterns): + if resource_list is not None: + for pn_resource in resource_list: + resource_object = {} + + if pn_resource.is_pattern_resource(): + determined_object = patterns + else: + determined_object = resources + + if resource_set_name in determined_object: + determined_object[resource_set_name][pn_resource.get_id()] = calculate_bitmask(pn_resource) + else: + resource_object[pn_resource.get_id()] = calculate_bitmask(pn_resource) + determined_object[resource_set_name] = resource_object + + if resource_set_name not in resources: + resources[resource_set_name] = {} + + if resource_set_name not in patterns: + patterns[resource_set_name] = {} + + +def calculate_bitmask(pn_resource): + bit_sum = 0 + from .endpoints.access.grant_token import GrantToken + + if pn_resource.is_read() is True: + bit_sum += GrantToken.READ + + if pn_resource.is_write() is True: + bit_sum += GrantToken.WRITE + + if pn_resource.is_manage() is True: + bit_sum += GrantToken.MANAGE + + if pn_resource.is_delete() is True: + bit_sum += GrantToken.DELETE + + if pn_resource.is_create() is True: + bit_sum += GrantToken.CREATE + + if bit_sum == 0: + raise PubNubException(pn_error=PNERR_PERMISSION_MISSING) + + return bit_sum + + +def decode_utf8_dict(dic): + if isinstance(dic, bytes): + return dic.decode("utf-8") + elif isinstance(dic, dict): + new_dic = {} + + for key in dic: + new_key = key + if isinstance(key, bytes): + new_key = key.decode("UTF-8") + + if new_key == "sig" and isinstance(dic[key], bytes): + new_dic[new_key] = dic[key] + else: + new_dic[new_key] = decode_utf8_dict(dic[key]) + + return new_dic + elif isinstance(dic, list): + new_l = [] + for e in dic: + new_l.append(decode_utf8_dict(e)) + return new_l + else: + return dic diff --git a/requirements-pypy-dev.txt b/requirements-pypy-dev.txt index 2c13de5d..1105ebb7 100644 --- a/requirements-pypy-dev.txt +++ b/requirements-pypy-dev.txt @@ -1,3 +1,4 @@ tornado==4.5.3 pytest==4.3.0 pytest-cov<2.6.0 +cbor2 diff --git a/requirements27-dev.txt b/requirements27-dev.txt index d2374bf1..10652ed3 100644 --- a/requirements27-dev.txt +++ b/requirements27-dev.txt @@ -3,3 +3,4 @@ tornado==4.5.3 twisted pyopenssl pytest-cov<2.6.0 +cbor2 diff --git a/requirements34-dev.txt b/requirements34-dev.txt index 8928275d..3751f6c4 100644 --- a/requirements34-dev.txt +++ b/requirements34-dev.txt @@ -4,3 +4,4 @@ pytest-cov<2.6.0 tornado==4.5.3 aiohttp==2.3.10 typing==3.6.4 +cbor2 diff --git a/requirements35-dev.txt b/requirements35-dev.txt index 709ef952..bbf2635d 100644 --- a/requirements35-dev.txt +++ b/requirements35-dev.txt @@ -3,3 +3,4 @@ pytest-asyncio tornado==4.5.3 aiohttp==2.3.10 pytest-cov<2.6.0 +cbor2 diff --git a/requirements36-dev.txt b/requirements36-dev.txt index cd949156..974b2276 100644 --- a/requirements36-dev.txt +++ b/requirements36-dev.txt @@ -3,3 +3,4 @@ pytest-asyncio tornado==4.5.3 aiohttp==2.3.10 pytest-cov +cbor2 diff --git a/requirements37-dev.txt b/requirements37-dev.txt index cd949156..974b2276 100644 --- a/requirements37-dev.txt +++ b/requirements37-dev.txt @@ -3,3 +3,4 @@ pytest-asyncio tornado==4.5.3 aiohttp==2.3.10 pytest-cov +cbor2 diff --git a/setup.py b/setup.py index 8c550088..c7e8fbd4 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pubnub', - version='4.1.7', + version='4.1.8', description='PubNub Real-time push service in the cloud', author='PubNub', author_email='support@pubnub.com', @@ -28,7 +28,8 @@ install_requires=[ 'pycryptodomex>=3.3', 'requests>=2.4', - 'six>=1.10' + 'six>=1.10', + 'cbor2' ], zip_safe=False, ) diff --git a/tests/functional/push/test_add_channels_to_push.py b/tests/functional/push/test_add_channels_to_push.py index 6248168d..e3bd8542 100644 --- a/tests/functional/push/test_add_channels_to_push.py +++ b/tests/functional/push/test_add_channels_to_push.py @@ -31,7 +31,7 @@ def test_push_add_single_channel(self): self.add_channels.channels(['ch']).push_type(pubnub.enums.PNPushType.APNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) + self.assertEqual(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) self.assertEqual(self.add_channels.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -46,7 +46,7 @@ def test_push_add_multiple_channels(self): self.add_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) + self.assertEqual(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) self.assertEqual(self.add_channels.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -61,7 +61,7 @@ def test_push_add_google(self): self.add_channels.channels(['ch1', 'ch2', 'ch3']).push_type(pubnub.enums.PNPushType.GCM).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) + self.assertEqual(self.add_channels.build_path(), AddChannelsToPush.ADD_PATH % params) self.assertEqual(self.add_channels.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/push/test_list_push_provisions.py b/tests/functional/push/test_list_push_provisions.py index 24fe27e4..94296dca 100644 --- a/tests/functional/push/test_list_push_provisions.py +++ b/tests/functional/push/test_list_push_provisions.py @@ -28,9 +28,9 @@ def setUp(self): def test_list_channel_group_apns(self): self.list_push.push_type(PNPushType.APNS).device_id('coolDevice') - self.assertEquals(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + self.assertEqual(self.list_push.build_path(), + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -41,9 +41,9 @@ def test_list_channel_group_apns(self): def test_list_channel_group_gcm(self): self.list_push.push_type(PNPushType.GCM).device_id('coolDevice') - self.assertEquals(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + self.assertEqual(self.list_push.build_path(), + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -54,9 +54,9 @@ def test_list_channel_group_gcm(self): def test_list_channel_group_mpns(self): self.list_push.push_type(PNPushType.MPNS).device_id('coolDevice') - self.assertEquals(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + self.assertEqual(self.list_push.build_path(), + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/push/test_remove_channels_from_push.py b/tests/functional/push/test_remove_channels_from_push.py index eed86d6d..c5faeca6 100644 --- a/tests/functional/push/test_remove_channels_from_push.py +++ b/tests/functional/push/test_remove_channels_from_push.py @@ -31,7 +31,7 @@ def test_push_remove_single_channel(self): self.remove_channels.channels(['ch']).push_type(pubnub.enums.PNPushType.APNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_channels.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -46,7 +46,7 @@ def test_push_remove_multiple_channels(self): self.remove_channels.channels(['ch1', 'ch2']).push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_channels.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -62,7 +62,7 @@ def test_push_remove_google(self): .device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_channels.build_path(), RemoveChannelsFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_channels.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/push/test_remove_device_from_push.py b/tests/functional/push/test_remove_device_from_push.py index 595227f9..e8d633c4 100644 --- a/tests/functional/push/test_remove_device_from_push.py +++ b/tests/functional/push/test_remove_device_from_push.py @@ -31,7 +31,7 @@ def test_remove_push_apns(self): self.remove_device.push_type(pubnub.enums.PNPushType.APNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_device.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -43,7 +43,7 @@ def test_remove_push_gcm(self): self.remove_device.push_type(pubnub.enums.PNPushType.GCM).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_device.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -55,7 +55,7 @@ def test_remove_push_mpns(self): self.remove_device.push_type(pubnub.enums.PNPushType.MPNS).device_id("coolDevice") params = (pnconf.subscribe_key, "coolDevice") - self.assertEquals(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) + self.assertEqual(self.remove_device.build_path(), RemoveDeviceFromPush.REMOVE_PATH % params) self.assertEqual(self.remove_device.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_add_channel_to_cg.py b/tests/functional/test_add_channel_to_cg.py index 350ea86f..c34bda1c 100644 --- a/tests/functional/test_add_channel_to_cg.py +++ b/tests/functional/test_add_channel_to_cg.py @@ -27,9 +27,9 @@ def setUp(self): def test_add_single_channel(self): self.add.channels('ch').channel_group('gr') - self.assertEquals(self.add.build_path(), - AddChannelToChannelGroup.ADD_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.add.build_path(), + AddChannelToChannelGroup.ADD_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.add.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -42,9 +42,9 @@ def test_add_single_channel(self): def test_add_multiple_channels(self): self.add.channels(['ch1', 'ch2']).channel_group('gr') - self.assertEquals(self.add.build_path(), - AddChannelToChannelGroup.ADD_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.add.build_path(), + AddChannelToChannelGroup.ADD_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.add.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_audit.py b/tests/functional/test_audit.py index d7429348..042f9ac3 100644 --- a/tests/functional/test_audit.py +++ b/tests/functional/test_audit.py @@ -2,6 +2,7 @@ from pubnub import utils from pubnub.endpoints.access.audit import Audit +from pubnub.enums import HttpMethod from pubnub.managers import TelemetryManager try: @@ -29,7 +30,7 @@ def setUp(self): def test_audit_channel(self): self.audit.channels('ch') - self.assertEquals(self.audit.build_path(), Audit.AUDIT_PATH % pnconf_pam.subscribe_key) + self.assertEqual(self.audit.build_path(), Audit.AUDIT_PATH % pnconf_pam.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'timestamp': 123, @@ -37,19 +38,24 @@ def test_audit_channel(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "audit\n" + pam_args + + sign_input = HttpMethod.string(self.audit.http_method()).upper() + "\n" + \ + pnconf_pam.publish_key + "\n" + \ + self.audit.build_path() + "\n" + \ + pam_args + "\n" + self.assertEqual(self.audit.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, 'timestamp': '123', 'channel': 'ch', - 'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf_pam.secret_key, sign_input).rstrip("=") }) def test_audit_channel_group(self): self.audit.channel_groups(['gr1', 'gr2']) - self.assertEquals(self.audit.build_path(), Audit.AUDIT_PATH % pnconf_pam.subscribe_key) + self.assertEqual(self.audit.build_path(), Audit.AUDIT_PATH % pnconf_pam.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'timestamp': 123, @@ -57,11 +63,14 @@ def test_audit_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "audit\n" + pam_args + sign_input = HttpMethod.string(self.audit.http_method()).upper() + "\n" + \ + pnconf_pam.publish_key + "\n" + \ + self.audit.build_path() + "\n" + \ + pam_args + "\n" self.assertEqual(self.audit.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, 'timestamp': '123', 'channel-group': 'gr1,gr2', - 'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf_pam.secret_key, sign_input).rstrip("=") }) diff --git a/tests/functional/test_get_state.py b/tests/functional/test_get_state.py index db348fc4..2101f126 100644 --- a/tests/functional/test_get_state.py +++ b/tests/functional/test_get_state.py @@ -2,7 +2,6 @@ from pubnub.endpoints.presence.get_state import GetState - try: from mock import MagicMock except ImportError: @@ -28,9 +27,9 @@ def setUp(self): def test_get_state_single_channel(self): self.get_state.channels('ch') - self.assertEquals(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, - "ch", - self.pubnub.uuid)) + self.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, + "ch", + self.pubnub.uuid)) self.assertEqual(self.get_state.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -42,9 +41,9 @@ def test_get_state_single_channel(self): def test_get_state_single_group(self): self.get_state.channel_groups('gr') - self.assertEquals(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, - ",", - self.pubnub.uuid)) + self.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, + ",", + self.pubnub.uuid)) self.assertEqual(self.get_state.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_grant.py b/tests/functional/test_grant.py index 5a735421..95a5ca3c 100644 --- a/tests/functional/test_grant.py +++ b/tests/functional/test_grant.py @@ -2,6 +2,7 @@ from pubnub import utils from pubnub.endpoints.access.grant import Grant +from pubnub.enums import HttpMethod from pubnub.managers import TelemetryManager try: @@ -29,7 +30,7 @@ def setUp(self): def test_grant_read_and_write_to_channel(self): self.grant.channels('ch').read(True).write(True).ttl(7) - self.assertEquals(self.grant.build_path(), Grant.GRANT_PATH % pnconf_pam.subscribe_key) + self.assertEqual(self.grant.build_path(), Grant.GRANT_PATH % pnconf_pam.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'r': '1', @@ -40,7 +41,10 @@ def test_grant_read_and_write_to_channel(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "grant\n" + pam_args + sign_input = HttpMethod.string(self.grant.http_method()).upper() + "\n" + \ + pnconf_pam.publish_key + "\n" + \ + self.grant.build_path() + "\n" + \ + pam_args + "\n" self.assertEqual(self.grant.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, @@ -49,13 +53,13 @@ def test_grant_read_and_write_to_channel(self): 'ttl': '7', 'timestamp': '123', 'channel': 'ch', - 'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf_pam.secret_key, sign_input).rstrip("=") }) def test_grant_read_and_write_to_channel_group(self): self.grant.channel_groups(['gr1', 'gr2']).read(True).write(True) - self.assertEquals(self.grant.build_path(), Grant.GRANT_PATH % pnconf_pam.subscribe_key) + self.assertEqual(self.grant.build_path(), Grant.GRANT_PATH % pnconf_pam.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'r': '1', @@ -65,7 +69,10 @@ def test_grant_read_and_write_to_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "grant\n" + pam_args + sign_input = HttpMethod.string(self.grant.http_method()).upper() + "\n" + \ + pnconf_pam.publish_key + "\n" + \ + self.grant.build_path() + "\n" + \ + pam_args + "\n" self.assertEqual(self.grant.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, @@ -73,5 +80,5 @@ def test_grant_read_and_write_to_channel_group(self): 'w': '1', 'timestamp': '123', 'channel-group': 'gr1,gr2', - 'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf_pam.secret_key, sign_input).rstrip("=") }) diff --git a/tests/functional/test_heartbeat.py b/tests/functional/test_heartbeat.py index cc844cfc..90b813d2 100644 --- a/tests/functional/test_heartbeat.py +++ b/tests/functional/test_heartbeat.py @@ -5,7 +5,6 @@ from pubnub.endpoints.presence.heartbeat import Heartbeat from pubnub.managers import TelemetryManager - try: from mock import MagicMock except ImportError: @@ -30,8 +29,8 @@ def setUp(self): def test_sub_single_channel(self): self.hb.channels('ch') - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.hb.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -44,8 +43,8 @@ def test_sub_single_channel(self): def test_hb_multiple_channels_using_list(self): self.hb.channels(['ch1', 'ch2', 'ch3']) - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.hb.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -58,8 +57,8 @@ def test_hb_multiple_channels_using_list(self): def test_hb_single_group(self): self.hb.channel_groups("gr") - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { 'channel-group': 'gr', @@ -73,8 +72,8 @@ def test_hb_single_group(self): def test_hb_multiple_groups_using_list(self): self.hb.channel_groups(['gr1', 'gr2', 'gr3']) - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -91,8 +90,8 @@ def test_hb_with_state(self): state = {"name": "Alex", "count": 7} self.hb.channels('ch1,ch2').state(state) - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + % (pnconf.subscribe_key, "ch1,ch2")) params = self.hb.build_params_callback()({}) params['state'] = json.loads(six.moves.urllib.parse.unquote(params['state'])) diff --git a/tests/functional/test_here_now.py b/tests/functional/test_here_now.py index 8c352efd..d9efaa42 100644 --- a/tests/functional/test_here_now.py +++ b/tests/functional/test_here_now.py @@ -3,7 +3,6 @@ from pubnub.endpoints.presence.here_now import HereNow from pubnub.managers import TelemetryManager - try: from mock import MagicMock except ImportError: @@ -27,8 +26,8 @@ def setUp(self): def test_here_now(self): self.here_now.channels("ch1") - self.assertEquals(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, "ch1")) + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH + % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -38,8 +37,8 @@ def test_here_now(self): def test_here_now_groups(self): self.here_now.channel_groups("gr1") - self.assertEquals(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.here_now.build_params_callback()({}), { 'channel-group': 'gr1', @@ -50,8 +49,8 @@ def test_here_now_groups(self): def test_here_now_with_options(self): self.here_now.channels(["ch1"]).channel_groups("gr1").include_state(True).include_uuids(False) - self.assertEquals(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, "ch1")) + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH + % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { 'channel-group': 'gr1', diff --git a/tests/functional/test_history.py b/tests/functional/test_history.py index 738a53b9..041ada67 100644 --- a/tests/functional/test_history.py +++ b/tests/functional/test_history.py @@ -30,7 +30,7 @@ def setUp(self): def test_history_basic(self): self.history.channel('ch') - self.assertEquals(self.history.build_path(), History.HISTORY_PATH % (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.history.build_path(), History.HISTORY_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -41,7 +41,7 @@ def test_history_basic(self): def test_history_full(self): self.history.channel('ch').start(100000).end(200000).reverse(False).count(3).include_timetoken(True) - self.assertEquals(self.history.build_path(), History.HISTORY_PATH % (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.history.build_path(), History.HISTORY_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_history_delete.py b/tests/functional/test_history_delete.py index 78b41084..af32baf0 100644 --- a/tests/functional/test_history_delete.py +++ b/tests/functional/test_history_delete.py @@ -30,8 +30,8 @@ def setUp(self): def test_history_delete_basic(self): self.history_delete.channel('ch') - self.assertEquals(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % - (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % + (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history_delete.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -41,8 +41,8 @@ def test_history_delete_basic(self): def test_history_delete_full(self): self.history_delete.channel('ch').start(100000).end(200000) - self.assertEquals(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % - (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % + (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history_delete.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_leave.py b/tests/functional/test_leave.py index 7a37d5cc..78d886e5 100644 --- a/tests/functional/test_leave.py +++ b/tests/functional/test_leave.py @@ -27,7 +27,7 @@ def setUp(self): def test_leave_single_channel(self): self.leave.channels('ch') - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch")) self.assertEqual(self.leave.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -39,7 +39,7 @@ def test_leave_single_channel(self): def test_leave_multiple_channels(self): self.leave.channels("ch1,ch2,ch3") - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.leave.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -51,7 +51,7 @@ def test_leave_multiple_channels(self): def test_leave_multiple_channels_using_list(self): self.leave.channels(['ch1', 'ch2', 'ch3']) - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.leave.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -63,7 +63,7 @@ def test_leave_multiple_channels_using_list(self): def test_leave_multiple_channels_using_tuple(self): self.leave.channels(('ch1', 'ch2', 'ch3')) - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.leave.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -75,8 +75,8 @@ def test_leave_multiple_channels_using_tuple(self): def test_leave_single_group(self): self.leave.channel_groups("gr") - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr', @@ -89,8 +89,8 @@ def test_leave_single_group(self): def test_leave_multiple_groups_using_string(self): self.leave.channel_groups("gr1,gr2,gr3") - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -103,8 +103,8 @@ def test_leave_multiple_groups_using_string(self): def test_leave_multiple_groups_using_list(self): self.leave.channel_groups(['gr1', 'gr2', 'gr3']) - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -117,8 +117,8 @@ def test_leave_multiple_groups_using_list(self): def test_leave_channels_and_groups(self): self.leave.channels('ch1,ch2').channel_groups(["gr1", "gr2"]) - self.assertEquals(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH + % (pnconf.subscribe_key, "ch1,ch2")) self.assertEqual(self.leave.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_list_channels_in_cg.py b/tests/functional/test_list_channels_in_cg.py index da1cd3bf..d06ed726 100644 --- a/tests/functional/test_list_channels_in_cg.py +++ b/tests/functional/test_list_channels_in_cg.py @@ -27,9 +27,9 @@ def setUp(self): def test_list_channel_group(self): self.list.channel_group('gr') - self.assertEquals(self.list.build_path(), - ListChannelsInChannelGroup.LIST_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.list.build_path(), + ListChannelsInChannelGroup.LIST_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.list.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_publish.py b/tests/functional/test_publish.py index 677464d0..e26b9750 100644 --- a/tests/functional/test_publish.py +++ b/tests/functional/test_publish.py @@ -35,8 +35,8 @@ def test_pub_message(self): self.pub.channel("ch1").message(message) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -51,8 +51,8 @@ def test_pub_list_message(self): self.pub.channel("ch1").message(message) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -68,8 +68,8 @@ def test_pub_with_meta(self): self.pub.channel("ch1").message(message).meta(meta) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -85,8 +85,8 @@ def test_pub_store(self): self.pub.channel("ch1").message(message).should_store(True) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -102,8 +102,8 @@ def test_pub_do_not_store(self): self.pub.channel("ch1").message(message).should_store(False) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -128,8 +128,8 @@ def test_pub_with_auth(self): encoded_message = url_encode(message) pub.channel("ch1").message(message) - self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -156,8 +156,8 @@ def test_pub_encrypted_list_message(self): pub.channel("ch1").message(message) - self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + self.assertEqual(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(pub.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_remove_cg.py b/tests/functional/test_remove_cg.py index 3d9ecc7a..0fa0a758 100644 --- a/tests/functional/test_remove_cg.py +++ b/tests/functional/test_remove_cg.py @@ -27,9 +27,9 @@ def setUp(self): def test_list_channel_group(self): self.list.channel_group('gr') - self.assertEquals(self.list.build_path(), - RemoveChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.list.build_path(), + RemoveChannelGroup.REMOVE_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.list.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_remove_channel_from_cg.py b/tests/functional/test_remove_channel_from_cg.py index 9fb93b13..58940456 100644 --- a/tests/functional/test_remove_channel_from_cg.py +++ b/tests/functional/test_remove_channel_from_cg.py @@ -27,9 +27,9 @@ def setUp(self): def test_remove_single_channel(self): self.remove.channels('ch').channel_group('gr') - self.assertEquals(self.remove.build_path(), - RemoveChannelFromChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.remove.build_path(), + RemoveChannelFromChannelGroup.REMOVE_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.remove.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -42,9 +42,9 @@ def test_remove_single_channel(self): def test_remove_multiple_channels(self): self.remove.channels(['ch1', 'ch2']).channel_group('gr') - self.assertEquals(self.remove.build_path(), - RemoveChannelFromChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + self.assertEqual(self.remove.build_path(), + RemoveChannelFromChannelGroup.REMOVE_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.remove.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_revoke.py b/tests/functional/test_revoke.py index 017c1c68..718a2880 100644 --- a/tests/functional/test_revoke.py +++ b/tests/functional/test_revoke.py @@ -2,6 +2,7 @@ from pubnub import utils from pubnub.endpoints.access.revoke import Revoke +from pubnub.enums import HttpMethod try: from mock import MagicMock @@ -33,7 +34,7 @@ def setUp(self): def test_revoke_to_channel(self): self.revoke.channels('ch') - self.assertEquals(self.revoke.build_path(), Revoke.GRANT_PATH % pnconf.subscribe_key) + self.assertEqual(self.revoke.build_path(), Revoke.GRANT_PATH % pnconf.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'timestamp': 123, @@ -44,7 +45,10 @@ def test_revoke_to_channel(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf.subscribe_key + "\n" + pnconf.publish_key + "\n" + "grant\n" + pam_args + sign_input = HttpMethod.string(self.revoke.http_method()).upper() + "\n" + \ + pnconf.publish_key + "\n" + \ + self.revoke.build_path() + "\n" + \ + pam_args + "\n" self.assertEqual(self.revoke.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, @@ -53,7 +57,7 @@ def test_revoke_to_channel(self): 'r': '0', 'w': '0', 'm': '0', - 'signature': utils.sign_sha256(pnconf.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf.secret_key, sign_input).rstrip("=") }) def test_revoke_read_to_channel(self): @@ -65,7 +69,7 @@ def revoke(): def test_grant_read_and_write_to_channel_group(self): self.revoke.channel_groups(['gr1', 'gr2']) - self.assertEquals(self.revoke.build_path(), Revoke.GRANT_PATH % pnconf.subscribe_key) + self.assertEqual(self.revoke.build_path(), Revoke.GRANT_PATH % pnconf.subscribe_key) pam_args = utils.prepare_pam_arguments({ 'r': '0', @@ -76,7 +80,10 @@ def test_grant_read_and_write_to_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = pnconf.subscribe_key + "\n" + pnconf.publish_key + "\n" + "grant\n" + pam_args + sign_input = HttpMethod.string(self.revoke.http_method()).upper() + "\n" + \ + pnconf.publish_key + "\n" + \ + self.revoke.build_path() + "\n" + \ + pam_args + "\n" self.assertEqual(self.revoke.build_params_callback()({}), { 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid, @@ -85,5 +92,5 @@ def test_grant_read_and_write_to_channel_group(self): 'm': '0', 'timestamp': '123', 'channel-group': 'gr1,gr2', - 'signature': utils.sign_sha256(pnconf.secret_key, sign_input) + 'signature': "v2." + utils.sign_sha256(pnconf.secret_key, sign_input).rstrip("=") }) diff --git a/tests/functional/test_set_state.py b/tests/functional/test_set_state.py index bda6bb10..4f0b6d10 100644 --- a/tests/functional/test_set_state.py +++ b/tests/functional/test_set_state.py @@ -30,9 +30,9 @@ def setUp(self): def test_set_state_single_channel(self): self.set_state.channels('ch').state(self.state) - self.assertEquals(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, - "ch", - self.pubnub.uuid)) + self.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, + "ch", + self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) @@ -45,9 +45,9 @@ def test_set_state_single_channel(self): def test_set_state_single_group(self): self.set_state.channel_groups('gr').state(self.state) - self.assertEquals(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, - ",", - self.pubnub.uuid)) + self.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, + ",", + self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) diff --git a/tests/functional/test_stringify.py b/tests/functional/test_stringify.py index 2a72d325..212e216f 100644 --- a/tests/functional/test_stringify.py +++ b/tests/functional/test_stringify.py @@ -36,14 +36,16 @@ def test_list_channel_group(self): assert str(result) == "Group contains following channels: qwer, asdf, zxcv" def test_audit(self): - result = PNAccessManagerAuditResult(None, None, None, None, 3600, True, False, True) + result = PNAccessManagerAuditResult(None, None, None, None, 3600, True, False, True, False) - assert str(result) == "Current permissions are valid for 3600 minutes: read True, write False, manage: True" + assert str(result) == \ + "Current permissions are valid for 3600 minutes: read True, write False, manage: True, delete: False" def test_grant(self): - result = PNAccessManagerGrantResult(None, None, None, None, 3600, True, False, True) + result = PNAccessManagerGrantResult(None, None, None, None, 3600, True, False, True, False) - assert str(result) == "New permissions are set for 3600 minutes: read True, write False, manage: True" + assert str(result) == \ + "New permissions are set for 3600 minutes: read True, write False, manage: True, delete: False" def test_history(self): assert str(PNHistoryResult(None, 123, 789)) == "History result for range 123..789" diff --git a/tests/functional/test_subscribe.py b/tests/functional/test_subscribe.py index 3dc81372..38f35c7d 100644 --- a/tests/functional/test_subscribe.py +++ b/tests/functional/test_subscribe.py @@ -25,8 +25,8 @@ def setUp(self): def test_pub_single_channel(self): self.sub.channels('ch') - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, 'ch')) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -38,8 +38,8 @@ def test_pub_single_channel(self): def test_sub_multiple_channels_using_string(self): self.sub.channels("ch1,ch2,ch3") - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -51,8 +51,8 @@ def test_sub_multiple_channels_using_string(self): def test_sub_multiple_channels_using_list(self): self.sub.channels(['ch1', 'ch2', 'ch3']) - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -64,8 +64,8 @@ def test_sub_multiple_channels_using_list(self): def test_sub_multiple_channels_using_tuple(self): self.sub.channels(('ch1', 'ch2', 'ch3')) - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -77,8 +77,8 @@ def test_sub_multiple_channels_using_tuple(self): def test_sub_single_group(self): self.sub.channel_groups("gr") - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr', @@ -91,8 +91,8 @@ def test_sub_single_group(self): def test_sub_multiple_groups_using_string(self): self.sub.channel_groups("gr1,gr2,gr3") - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -105,8 +105,8 @@ def test_sub_multiple_groups_using_string(self): def test_sub_multiple_groups_using_list(self): self.sub.channel_groups(['gr1', 'gr2', 'gr3']) - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -119,8 +119,8 @@ def test_sub_multiple_groups_using_list(self): def test_sub_multiple(self): self.sub.channels('ch1,ch2').filter_expression('blah').region('us-east-1').timetoken('123') - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + % (pnconf.subscribe_key, "ch1,ch2")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/functional/test_where_now.py b/tests/functional/test_where_now.py index c2df0c65..9d3229ff 100644 --- a/tests/functional/test_where_now.py +++ b/tests/functional/test_where_now.py @@ -25,8 +25,8 @@ def setUp(self): def test_where_now(self): self.where_now.uuid("person_uuid") - self.assertEquals(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH - % (pnconf.subscribe_key, "person_uuid")) + self.assertEqual(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH + % (pnconf.subscribe_key, "person_uuid")) self.assertEqual(self.where_now.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -34,8 +34,8 @@ def test_where_now(self): }) def test_where_now_no_uuid(self): - self.assertEquals(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH - % (pnconf.subscribe_key, self.pubnub.config.uuid)) + self.assertEqual(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH + % (pnconf.subscribe_key, self.pubnub.config.uuid)) self.assertEqual(self.where_now.build_params_callback()({}), { 'pnsdk': sdk_name, diff --git a/tests/integrational/asyncio/test_pam.py b/tests/integrational/asyncio/test_pam.py index 50f9ac2b..89bf84b4 100644 --- a/tests/integrational/asyncio/test_pam.py +++ b/tests/integrational/asyncio/test_pam.py @@ -1,6 +1,6 @@ import pytest -from pubnub.models.consumer.access_manager import PNAccessManagerGrantResult, PNAccessManagerAuditResult +from pubnub.models.consumer.access_manager import PNAccessManagerGrantResult from pubnub.pubnub_asyncio import PubNubAsyncio from tests.helper import pnconf_pam_copy from tests.integrational.vcr_helper import pn_vcr @@ -24,16 +24,7 @@ def test_global_level(event_loop): assert env.result.read_enabled is True assert env.result.write_enabled is True assert env.result.manage_enabled is False - - env = (yield from pubnub.audit() - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert len(env.result.channels) >= 0 - assert len(env.result.groups) >= 0 - assert env.result.read_enabled is True - assert env.result.write_enabled is True - assert env.result.manage_enabled is False + assert env.result.delete_enabled is False env = yield from pubnub.revoke().future() @@ -43,6 +34,7 @@ def test_global_level(event_loop): assert env.result.read_enabled is False assert env.result.write_enabled is False assert env.result.manage_enabled is False + assert env.result.delete_enabled is False pubnub.stop() @@ -65,15 +57,7 @@ def test_single_channel(event_loop): assert env.result.channels[ch].read_enabled == 1 assert env.result.channels[ch].write_enabled == 1 assert env.result.channels[ch].manage_enabled == 0 - - env = (yield from pubnub.audit() - .channels(ch) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.channels[ch].read_enabled == 1 - assert env.result.channels[ch].write_enabled == 1 - assert env.result.channels[ch].manage_enabled == 0 + assert env.result.channels[ch].delete_enabled == 0 pubnub.stop() @@ -98,16 +82,7 @@ def test_single_channel_with_auth(event_loop): assert env.result.channels[ch].auth_keys[auth].read_enabled == 1 assert env.result.channels[ch].auth_keys[auth].write_enabled == 1 assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0 - - env = (yield from pubnub.audit() - .channels(ch) - .auth_keys(auth) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.channels[ch].auth_keys[auth].read_enabled == 1 - assert env.result.channels[ch].auth_keys[auth].write_enabled == 1 - assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0 + assert env.result.channels[ch].auth_keys[auth].delete_enabled == 0 pubnub.stop() @@ -139,18 +114,8 @@ def test_multiple_channels(event_loop): assert env.result.channels[ch2].write_enabled is True assert env.result.channels[ch1].manage_enabled is False assert env.result.channels[ch2].manage_enabled is False - - env = (yield from pubnub.audit() - .channels([ch1, ch2]) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.channels[ch1].read_enabled is True - assert env.result.channels[ch2].read_enabled is True - assert env.result.channels[ch1].write_enabled is True - assert env.result.channels[ch2].write_enabled is True - assert env.result.channels[ch1].manage_enabled is False - assert env.result.channels[ch2].manage_enabled is False + assert env.result.channels[ch1].delete_enabled is False + assert env.result.channels[ch2].delete_enabled is False pubnub.stop() @@ -184,18 +149,8 @@ def test_multiple_channels_with_auth(event_loop): assert env.result.channels[ch2].auth_keys[auth].write_enabled is True assert env.result.channels[ch1].auth_keys[auth].manage_enabled is False assert env.result.channels[ch2].auth_keys[auth].manage_enabled is False - - env = (yield from pubnub.audit() - .channels([ch1, ch2]) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.channels[ch1].auth_keys[auth].read_enabled is True - assert env.result.channels[ch2].auth_keys[auth].read_enabled is True - assert env.result.channels[ch1].auth_keys[auth].write_enabled is True - assert env.result.channels[ch2].auth_keys[auth].write_enabled is True - assert env.result.channels[ch1].auth_keys[auth].manage_enabled is False - assert env.result.channels[ch2].auth_keys[auth].manage_enabled is False + assert env.result.channels[ch1].auth_keys[auth].delete_enabled is False + assert env.result.channels[ch2].auth_keys[auth].delete_enabled is False pubnub.stop() @@ -219,16 +174,7 @@ def test_single_channel_group(event_loop): assert env.result.groups[cg].read_enabled == 1 assert env.result.groups[cg].write_enabled == 1 assert env.result.groups[cg].manage_enabled == 0 - - env = (yield from pubnub.audit() - .channel_groups(cg) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.level == 'channel-group' - assert env.result.groups[cg].read_enabled == 1 - assert env.result.groups[cg].write_enabled == 1 - assert env.result.groups[cg].manage_enabled == 0 + assert env.result.groups[cg].delete_enabled == 0 pubnub.stop() @@ -254,16 +200,7 @@ def test_single_channel_group_with_auth(event_loop): assert env.result.groups[gr].auth_keys[auth].read_enabled == 1 assert env.result.groups[gr].auth_keys[auth].write_enabled == 1 assert env.result.groups[gr].auth_keys[auth].manage_enabled == 0 - - env = (yield from pubnub.audit() - .channel_groups(gr) - .auth_keys(auth) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.groups[gr].auth_keys[auth].read_enabled == 1 - assert env.result.groups[gr].auth_keys[auth].write_enabled == 1 - assert env.result.groups[gr].auth_keys[auth].manage_enabled == 0 + assert env.result.groups[gr].auth_keys[auth].delete_enabled == 0 pubnub.stop() @@ -295,18 +232,8 @@ def test_multiple_channel_groups(event_loop): assert env.result.groups[gr2].write_enabled is True assert env.result.groups[gr1].manage_enabled is False assert env.result.groups[gr2].manage_enabled is False - - env = (yield from pubnub.audit() - .channel_groups([gr1, gr2]) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.groups[gr1].read_enabled is True - assert env.result.groups[gr2].read_enabled is True - assert env.result.groups[gr1].write_enabled is True - assert env.result.groups[gr2].write_enabled is True - assert env.result.groups[gr1].manage_enabled is False - assert env.result.groups[gr2].manage_enabled is False + assert env.result.groups[gr1].delete_enabled is False + assert env.result.groups[gr2].delete_enabled is False pubnub.stop() @@ -340,17 +267,7 @@ def test_multiple_channel_groups_with_auth(event_loop): assert env.result.groups[gr2].auth_keys[auth].write_enabled is True assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False - - env = (yield from pubnub.audit() - .channel_groups([gr1, gr2]) - .future()) - - assert isinstance(env.result, PNAccessManagerAuditResult) - assert env.result.groups[gr1].auth_keys[auth].read_enabled is True - assert env.result.groups[gr2].auth_keys[auth].read_enabled is True - assert env.result.groups[gr1].auth_keys[auth].write_enabled is True - assert env.result.groups[gr2].auth_keys[auth].write_enabled is True - assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False - assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False + assert env.result.groups[gr1].auth_keys[auth].delete_enabled is False + assert env.result.groups[gr2].auth_keys[auth].delete_enabled is False pubnub.stop() diff --git a/tests/integrational/fixtures/asyncio/pam/global_level.yaml b/tests/integrational/fixtures/asyncio/pam/global_level.yaml index 4b45e6e1..85104f3a 100644 --- a/tests/integrational/fixtures/asyncio/pam/global_level.yaml +++ b/tests/integrational/fixtures/asyncio/pam/global_level.yaml @@ -2,49 +2,63 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?r=1&uuid=my_uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?r=1&uuid=my_uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"subkey","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"r":1,"w":1,"m":0},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '180', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:10 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=HoR4kd5kOwKqZ3RHzjVP5HdgmoWAP-L0OzGlf3pLlXA=×tamp=1481896330&uuid=my_uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"subkey","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"r":1,"w":1,"m":0,"d":0},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?uuid=my_uuid - response: - body: {string: '{"message":"Success","payload":{"level":"subkey","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","r":1,"m":0,"w":1,"ttl":1440,"channels":{"test-pam-asyncio-ch2":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-ch":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-ch1":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"history_channel":{"auths":{"blah":{"r":1,"m":0,"w":1}}}},"objects":{},"channel-groups":{"test-pam-asyncio-cg1":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-cg2":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-cg":{"r":1,"m":0,"w":1,"ttl":166,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '982', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=3DcPzxyRzAGRUteyDwv7b7ro_GHlabAUzPtSkTtfUSU=×tamp=1481896330&uuid=my_uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '186' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:39 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.M8jqdYI2ejBcOZgPxzjie18ZaCB1wZ9WysQZK7HVw6Y×tamp=1577189138&uuid=my_uuid&w=1 + - '' - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?m=0&r=0&uuid=my_uuid&w=0 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?m=0&r=0&uuid=my_uuid&w=0 response: - body: {string: '{"message":"Success","payload":{"level":"subkey","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1,"r":0,"w":0,"m":0},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '177', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?m=0&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=0&signature=0sKgzEts2pTJr7twR9Bh9wrfV46VON0yxg9E7tpgRjU=×tamp=1481896331&uuid=my_uuid&w=0 + body: + string: '{"message":"Success","payload":{"level":"subkey","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1,"r":0,"w":0,"m":0,"d":0},"service":"Access + Manager","status":200}' + headers: + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '183' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:39 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - l_pam=0.07717299461364746&m=0&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=0&signature=v2.HCUzgODNtMLvsSiK-f0lD0GOVEfzilmWABRKpYDG6cQ×tamp=1577189138&uuid=my_uuid&w=0 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml b/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml index 1062d7d1..4bc56fc5 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&r=1&uuid=my_uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&r=1&uuid=my_uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg1":{"r":1,"w":1,"m":0},"test-pam-asyncio-cg2":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '274', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:13 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=VtYBdq4jE9aGehb765EPddcQhQbPxZ0Aqp6YjeMtJpY=×tamp=1481896333&uuid=my_uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg1":{"r":1,"w":1,"m":0,"d":0},"test-pam-asyncio-cg2":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&uuid=my_uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channel-groups":{"test-pam-asyncio-cg1":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-cg2":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '413', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:13 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=fXT2f9pwZhWWbG-Gaaa0f3l21p5yee4QO-JqrCjBkSU=×tamp=1481896333&uuid=my_uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '286' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.0eTFy_Kgi-Qiz6nD3NmfZlu4Z4ndtUT5pYHl57imcZI×tamp=1577189139&uuid=my_uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups_with_auth.yaml b/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups_with_auth.yaml index 98622ee6..f66ac792 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups_with_auth.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&r=1&uuid=my_uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&r=1&uuid=my_uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg1":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}},"test-pam-asyncio-cg2":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '351', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:14 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=Lokw1jIF_zlAlk8VKfDZGechmTe9u6HaeSnvtaaQtXM=×tamp=1481896333&uuid=my_uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg1":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}},"test-pam-asyncio-cg2":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1%2Ctest-pam-asyncio-cg2&uuid=my_uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channel-groups":{"test-pam-asyncio-cg1":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":1440}}},"test-pam-asyncio-cg2":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":1440}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '415', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:14 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=ZgUT1TBwYYEChvdtr2xQS3Ln7YZD2b6R8ktUW44zbkY=×tamp=1481896334&uuid=my_uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '363' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg1,test-pam-asyncio-cg2&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.pjnKPVphocAsl8BsxLeirCZMbNVzNOQV3CS6mfm1Bbc×tamp=1577189139&uuid=my_uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml b/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml index da025c12..55f52ee7 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&r=1&uuid=test-pam-asyncio-uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&r=1&uuid=test-pam-asyncio-uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch1":{"r":1,"w":1,"m":0},"test-pam-asyncio-ch2":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '262', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:12 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=fBB-FwdPoO45PXR9NvaTIhGagcvDHpNsMFLDwI16k0U=×tamp=1481896331&uuid=test-pam-asyncio-uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch1":{"r":1,"w":1,"m":0,"d":0},"test-pam-asyncio-ch2":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&uuid=test-pam-asyncio-uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channels":{"test-pam-asyncio-ch2":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-ch1":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '401', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:12 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=eu_KBB6V9wcllZrZ__wfKB5r8MDD6bk2PJFuHu6rYFo=×tamp=1481896332&uuid=test-pam-asyncio-uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '274' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.z01_vYcxRHcQlLohU41PTYPzZOfaU8xWK4qXRF4bjK8×tamp=1577189138&uuid=test-pam-asyncio-uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml b/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml index 9dddc328..8bbcea83 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&r=1&uuid=my_uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&r=1&uuid=my_uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"user","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch1":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}},"test-pam-asyncio-ch2":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '331', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:12 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=8liy0K_7A7VC6EcZ_lZk7pdQRlQaracysvEprI2OwnY=×tamp=1481896332&uuid=my_uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"user","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch1":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}},"test-pam-asyncio-ch2":{"auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1%2Ctest-pam-asyncio-ch2&uuid=my_uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channels":{"test-pam-asyncio-ch2":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}},"test-pam-asyncio-ch1":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '401', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:12 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=dbZkXTLoS2rBDyxhUnYv-kCbuYxyxmRzpq_Brl3xKK4=×tamp=1481896332&uuid=my_uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '343' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch1,test-pam-asyncio-ch2&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.YX_q8cliqGK-cMPUevjVQ1rRnEFAkKLLkutGJt9X1OY×tamp=1577189138&uuid=my_uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/single_channel.yaml b/tests/integrational/fixtures/asyncio/pam/single_channel.yaml index 57a87e08..7aca577a 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch&r=1&uuid=my_uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch&r=1&uuid=my_uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '218', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=VbXpLZNb0qIVR7W5vNsq9xzO8Pbl-TVq2emBPu6TkVg=×tamp=1481896331&uuid=my_uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channels":{"test-pam-asyncio-ch":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch&uuid=my_uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channels":{"test-pam-asyncio-ch":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '282', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=D_DmhzxnuCBeA15JtmXgjTTMvbXg_5ZZ-azpArQSAQc=×tamp=1481896331&uuid=my_uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '224' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:39 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.fNqcroTl6ykcSUYDgrOmpGVe2b_11FKkOjU8_LMt7E8×tamp=1577189138&uuid=my_uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml b/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml index cd556cda..345994f9 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg&r=1&uuid=test-pam-asyncio-uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg&r=1&uuid=test-pam-asyncio-uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '230', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:12 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=BmTSr5gdDP3UkBWaSLt4mBEC9rFFZjNJRR9g_tCxLEQ=×tamp=1481896332&uuid=test-pam-asyncio-uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":{"test-pam-asyncio-cg":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg&uuid=test-pam-asyncio-uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel-group","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channel-groups":{"test-pam-asyncio-cg":{"r":1,"m":0,"w":1,"ttl":1440,"auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":166}}}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '294', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:13 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=S5p2eOGJ6fXtWge3VGpdwzti7pVNAbUZ05Wb3famUig=×tamp=1481896332&uuid=test-pam-asyncio-uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '236' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.BihlEpGJOoGHtVcTzIw1h0Jp7vqKoIdpkxaIYrvV1FU×tamp=1577189138&uuid=test-pam-asyncio-uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/single_channel_group_with_auth.yaml b/tests/integrational/fixtures/asyncio/pam/single_channel_group_with_auth.yaml index 8817487b..858e58b7 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel_group_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel_group_with_auth.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&r=1&uuid=test-pam-asyncio-uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&r=1&uuid=test-pam-asyncio-uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":"test-pam-asyncio-cg","auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '267', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:13 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=5TUABkdYUy7WHzCCKrU9H3vPuPZ2gHZAeaDcl7eMA54=×tamp=1481896333&uuid=test-pam-asyncio-uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel-groups":"test-pam-asyncio-cg","auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&uuid=test-pam-asyncio-uuid - response: - body: {string: '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channel-group":"test-pam-asyncio-cg","auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":1440}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '266', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:13 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=PlsjUwIg9fE8aGoFJ8exIdRAdX9w58jiU5LiEchEV4U=×tamp=1481896333&uuid=test-pam-asyncio-uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '273' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - auth=test-pam-asyncio-auth&channel-group=test-pam-asyncio-cg&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.Sjk_iz1y4xns4Mt3xuch3EWqgAJogNU6RJ6TCce-_3w×tamp=1577189139&uuid=test-pam-asyncio-uuid&w=1 + - '' version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml b/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml index 1d0766a9..bf0546e2 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml @@ -2,33 +2,32 @@ interactions: - request: body: null headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] + User-Agent: + - PubNub-Python-Asyncio/4.1.0 method: GET - uri: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&r=1&uuid=test-pam-asyncio-uuid&w=1 + uri: http://ps.pndsn.com/v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&r=1&uuid=test-pam-asyncio-uuid&w=1 response: - body: {string: '{"message":"Success","payload":{"level":"user","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel":"test-pam-asyncio-ch","auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '246', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.0.4&r=1&signature=F4zNd7p_UsQrl_v2vzhJz-ONitOhGhNENOkpddiaxPw=×tamp=1481896331&uuid=test-pam-asyncio-uuid&w=1 -- request: - body: null + body: + string: '{"message":"Success","payload":{"level":"user","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","ttl":1440,"channel":"test-pam-asyncio-ch","auths":{"test-pam-asyncio-auth":{"r":1,"w":1,"m":0,"d":0}}},"service":"Access + Manager","status":200}' headers: - USER-AGENT: [PubNub-Python-Asyncio/4.0.4] - method: GET - uri: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&uuid=test-pam-asyncio-uuid - response: - body: {string: '{"message":"Success","payload":{"level":"user","subscribe_key":"sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f","channel":"test-pam-asyncio-ch","auths":{"test-pam-asyncio-auth":{"r":1,"m":0,"w":1,"ttl":1440}}},"service":"Access - Manager","status":200}'} - headers: {ACCESS-CONTROL-ALLOW-HEADERS: 'Origin, X-Requested-With, Content-Type, - Accept', ACCESS-CONTROL-ALLOW-METHODS: GET, ACCESS-CONTROL-ALLOW-ORIGIN: '*', - CACHE-CONTROL: 'no-cache, no-store, must-revalidate', CONNECTION: keep-alive, - CONTENT-LENGTH: '246', CONTENT-TYPE: text/javascript; charset=UTF-8, DATE: 'Fri, - 16 Dec 2016 13:52:11 GMT'} - status: {code: 200, message: OK} - url: http://ps.pndsn.com/v1/auth/audit/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f?auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.0.4&signature=zuuexSpQPVHApIDglAa2RRJFUycU2nvya_GshRBd8V0=×tamp=1481896331&uuid=test-pam-asyncio-uuid + Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept + Access-Control-Allow-Methods: GET + Access-Control-Allow-Origin: '*' + Cache-Control: no-cache, no-store, must-revalidate + Connection: keep-alive + Content-Length: '252' + Content-Type: text/javascript; charset=UTF-8 + Date: Tue, 24 Dec 2019 12:05:40 GMT + status: + code: 200 + message: OK + url: !!python/object/new:yarl.URL + state: !!python/tuple + - !!python/object/new:urllib.parse.SplitResult + - http + - ps.pndsn.com + - /v2/auth/grant/sub-key/sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f + - auth=test-pam-asyncio-auth&channel=test-pam-asyncio-ch&pnsdk=PubNub-Python-Asyncio%2F4.1.0&r=1&signature=v2.P1WnlQZkBoiO8ah1YE9CS_Cgq4Iyi34TmjCB9Hj0qUA×tamp=1577189138&uuid=test-pam-asyncio-uuid&w=1 + - '' version: 1