From 2ddeb68ea0951ff03b797d1828c70e5929f25aa0 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Thu, 19 Dec 2019 13:58:57 +0100 Subject: [PATCH 01/12] Introduce 'delete' permission to Grant --- pubnub/endpoints/access/grant.py | 7 +++++++ pubnub/models/consumer/access_manager.py | 26 ++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pubnub/endpoints/access/grant.py b/pubnub/endpoints/access/grant.py index 64dbff1a..8c7f7ba2 100644 --- a/pubnub/endpoints/access/grant.py +++ b/pubnub/endpoints/access/grant.py @@ -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/models/consumer/access_manager.py b/pubnub/models/consumer/access_manager.py index 470cfb1f..b71cd245 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,6 +75,7 @@ def from_json(cls, json_input): r=r, w=w, m=m, + d=d, ttl=ttl, ) @@ -91,24 +93,25 @@ def __str__(self): 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) 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 From 984bfd4aac9a896fdac32534869327e149bff2b4 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Fri, 20 Dec 2019 22:07:01 +0100 Subject: [PATCH 02/12] Implement v2 signatures. Update PAM endpoints to /v2. Update PAM tests to support v2 signatures and /v2 endpoints. --- pubnub/endpoints/access/audit.py | 2 +- pubnub/endpoints/access/grant.py | 2 +- pubnub/endpoints/endpoint.py | 19 ++--------- pubnub/utils.py | 33 ++++++++++++++++++- tests/functional/test_audit.py | 15 +++++---- tests/functional/test_grant.py | 13 ++++---- tests/functional/test_revoke.py | 13 ++++---- .../fixtures/asyncio/pam/global_level.yaml | 12 +++---- .../asyncio/pam/multiple_channel_groups.yaml | 8 ++--- .../multiple_channel_groups_with_auth.yaml | 8 ++--- .../asyncio/pam/multiple_channels.yaml | 8 ++--- .../pam/multiple_channels_with_auth.yaml | 8 ++--- .../fixtures/asyncio/pam/single_channel.yaml | 8 ++--- .../asyncio/pam/single_channel_group.yaml | 8 ++--- .../pam/single_channel_group_with_auth.yaml | 8 ++--- .../asyncio/pam/single_channel_with_auth.yaml | 8 ++--- 16 files changed, 97 insertions(+), 76 deletions(-) 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 8c7f7ba2..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) diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 9848d950..5106b0a5 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -1,5 +1,4 @@ from abc import ABCMeta, abstractmethod - 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, \ @@ -7,9 +6,9 @@ from pubnub.exceptions import PubNubException from pubnub.models.consumer.common import PNStatus from pubnub.models.consumer.pn_error_data import PNErrorData +from pubnub.utils import sign_request from ..structures import RequestOptions, ResponseInfo - class Endpoint(object): SERVER_RESPONSE_SUCCESS = 200 SERVER_RESPONSE_FORBIDDEN = 403 @@ -155,21 +154,7 @@ def callback(params_to_merge): 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" - - signed_input += utils.prepare_pam_arguments(custom_params) - signature = utils.sign_sha256(self.pubnub.config.secret_key, signed_input) - - custom_params['signature'] = signature + 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: diff --git a/pubnub/utils.py b/pubnub/utils.py index ba399084..ed75bf91 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -15,7 +15,7 @@ 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 .exceptions import PubNubException @@ -173,3 +173,34 @@ 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 diff --git a/tests/functional/test_audit.py b/tests/functional/test_audit.py index d7429348..694d77a7 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,21 @@ 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 +60,11 @@ 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_grant.py b/tests/functional/test_grant.py index 5a735421..b345ead8 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,7 @@ 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 +50,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 +66,7 @@ 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 +74,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_revoke.py b/tests/functional/test_revoke.py index 017c1c68..34d65902 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,7 @@ 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 +54,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 +66,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 +77,7 @@ 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 +86,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/integrational/fixtures/asyncio/pam/global_level.yaml b/tests/integrational/fixtures/asyncio/pam/global_level.yaml index 4b45e6e1..5fdebb65 100644 --- a/tests/integrational/fixtures/asyncio/pam/global_level.yaml +++ b/tests/integrational/fixtures/asyncio/pam/global_level.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,13 +30,13 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 - request: body: null headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -46,5 +46,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..52c70c70 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channel_groups.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=VtYBdq4jE9aGehb765EPddcQhQbPxZ0Aqp6YjeMtJpY=×tamp=1481896333&uuid=my_uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..06b63225 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 @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=Lokw1jIF_zlAlk8VKfDZGechmTe9u6HaeSnvtaaQtXM=×tamp=1481896333&uuid=my_uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml b/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml index da025c12..aca4580a 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channels.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=fBB-FwdPoO45PXR9NvaTIhGagcvDHpNsMFLDwI16k0U=×tamp=1481896331&uuid=test-pam-asyncio-uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..0abd3168 100644 --- a/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/multiple_channels_with_auth.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=8liy0K_7A7VC6EcZ_lZk7pdQRlQaracysvEprI2OwnY=×tamp=1481896332&uuid=my_uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 version: 1 diff --git a/tests/integrational/fixtures/asyncio/pam/single_channel.yaml b/tests/integrational/fixtures/asyncio/pam/single_channel.yaml index 57a87e08..b9d822d4 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=VbXpLZNb0qIVR7W5vNsq9xzO8Pbl-TVq2emBPu6TkVg=×tamp=1481896331&uuid=my_uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..b7fa018f 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel_group.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=BmTSr5gdDP3UkBWaSLt4mBEC9rFFZjNJRR9g_tCxLEQ=×tamp=1481896332&uuid=test-pam-asyncio-uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..d03b0c07 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 @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=5TUABkdYUy7WHzCCKrU9H3vPuPZ2gHZAeaDcl7eMA54=×tamp=1481896333&uuid=test-pam-asyncio-uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 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..7727ee46 100644 --- a/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml +++ b/tests/integrational/fixtures/asyncio/pam/single_channel_with_auth.yaml @@ -4,7 +4,7 @@ interactions: headers: USER-AGENT: [PubNub-Python-Asyncio/4.0.4] 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}'} @@ -14,13 +14,13 @@ interactions: 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 + url: 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.0.4&r=1&signature=F4zNd7p_UsQrl_v2vzhJz-ONitOhGhNENOkpddiaxPw=×tamp=1481896331&uuid=test-pam-asyncio-uuid&w=1 - request: body: null 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 + uri: http://ps.pndsn.com/v2/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}'} @@ -30,5 +30,5 @@ interactions: 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 + url: http://ps.pndsn.com/v2/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 version: 1 From dc599e2360c0b9a3c032943e4d4250b9d1b24f73 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 07:20:14 +0100 Subject: [PATCH 03/12] Add TokenManager. Implement GrantToken method. Add cbor2 library to dependencies. --- pubnub/endpoints/access/grant_token.py | 120 ++++++++++++++++ pubnub/endpoints/endpoint.py | 32 ++++- pubnub/endpoints/membership/get_members.py | 9 +- .../membership/get_space_memberships.py | 9 +- pubnub/endpoints/membership/manage_members.py | 9 +- .../membership/manage_memberships.py | 9 +- pubnub/endpoints/space/create_space.py | 9 +- pubnub/endpoints/space/delete_space.py | 9 +- pubnub/endpoints/space/get_space.py | 9 +- pubnub/endpoints/space/get_spaces.py | 9 +- pubnub/endpoints/space/update_space.py | 9 +- pubnub/endpoints/users/create_user.py | 9 +- pubnub/endpoints/users/delete_user.py | 9 +- pubnub/endpoints/users/get_user.py | 9 +- pubnub/endpoints/users/get_users.py | 9 +- pubnub/endpoints/users/update_user.py | 9 +- pubnub/enums.py | 14 ++ pubnub/errors.py | 5 + pubnub/managers.py | 130 +++++++++++++++++- pubnub/models/consumer/access_manager.py | 8 +- pubnub/models/consumer/v3/access_manager.py | 24 ++++ pubnub/models/consumer/v3/channel.py | 29 ++++ pubnub/models/consumer/v3/group.py | 25 ++++ pubnub/models/consumer/v3/pn_resource.py | 34 +++++ pubnub/models/consumer/v3/space.py | 37 +++++ pubnub/models/consumer/v3/user.py | 37 +++++ pubnub/pnconfiguration.py | 1 + pubnub/pubnub.py | 6 + pubnub/pubnub_asyncio.py | 3 + pubnub/pubnub_core.py | 25 +++- pubnub/pubnub_tornado.py | 3 + pubnub/pubnub_twisted.py | 3 + pubnub/utils.py | 83 ++++++++++- requirements27-dev.txt | 1 + requirements34-dev.txt | 1 + requirements35-dev.txt | 1 + requirements36-dev.txt | 1 + requirements37-dev.txt | 1 + setup.py | 3 +- 39 files changed, 725 insertions(+), 28 deletions(-) create mode 100644 pubnub/endpoints/access/grant_token.py create mode 100644 pubnub/models/consumer/v3/access_manager.py create mode 100644 pubnub/models/consumer/v3/channel.py create mode 100644 pubnub/models/consumer/v3/group.py create mode 100644 pubnub/models/consumer/v3/pn_resource.py create mode 100644 pubnub/models/consumer/v3/space.py create mode 100644 pubnub/models/consumer/v3/user.py 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 5106b0a5..98d944c6 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -1,4 +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, \ @@ -6,9 +9,11 @@ from pubnub.exceptions import PubNubException from pubnub.models.consumer.common import PNStatus from pubnub.models.consumer.pn_error_data import PNErrorData -from pubnub.utils import sign_request from ..structures import RequestOptions, ResponseInfo +logger = logging.getLogger("pubnub") + + class Endpoint(object): SERVER_RESPONSE_SUCCESS = 200 SERVER_RESPONSE_FORBIDDEN = 403 @@ -89,7 +94,6 @@ def options(self): def sync(self): self.validate_params() - envelope = self.pubnub.request_sync(self.options()) if envelope.status.is_error(): @@ -153,8 +157,27 @@ 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.disable_token_manager is False and self.pubnub.config.auth_key is None: + if self.operation_type() in [ + PNOperationType.PNGetUsersOperation, PNOperationType.PNCreateUserOperation, + PNOperationType.PNGetUserOperation, PNOperationType.PNUpdateUserOperation, + PNOperationType.PNDeleteUserOperation, PNOperationType.PNGetSpacesOperation, + PNOperationType.PNCreateSpaceOperation, PNOperationType.PNGetSpaceOperation, + PNOperationType.PNUpdateSpaceOperation, PNOperationType.PNDeleteSpaceOperation, + PNOperationType.PNGetMembersOperation, PNOperationType.PNGetSpaceMembershipsOperation, + PNOperationType.PNManageMembersOperation, PNOperationType.PNManageMembershipsOperation + ]: + + token_manager_properties = self.get_tms_properties() + + token = self.pubnub.get_token(token_manager_properties) + if token is not None: + custom_params['auth'] = token + else: + logger.warning("No token found for: " + str(token_manager_properties)) + if self.pubnub.config.secret_key is not None: - sign_request(self, self.pubnub, custom_params, self.http_method(), self.build_data()) + 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: @@ -233,3 +256,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..86164ec0 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 + ) diff --git a/pubnub/endpoints/membership/get_space_memberships.py b/pubnub/endpoints/membership/get_space_memberships.py index a0ffe566..8d921960 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 + ) diff --git a/pubnub/endpoints/membership/manage_members.py b/pubnub/endpoints/membership/manage_members.py index e5cad199..39b3d22a 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 + ) diff --git a/pubnub/endpoints/membership/manage_memberships.py b/pubnub/endpoints/membership/manage_memberships.py index 66a28cd1..c735d9cc 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 + ) diff --git a/pubnub/endpoints/space/create_space.py b/pubnub/endpoints/space/create_space.py index f65efc48..d1c5d710 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'] + ) diff --git a/pubnub/endpoints/space/delete_space.py b/pubnub/endpoints/space/delete_space.py index e1f04a1e..6459926c 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 + ) diff --git a/pubnub/endpoints/space/get_space.py b/pubnub/endpoints/space/get_space.py index 39c5b347..a9076de3 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 + ) 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..6d7f6fc5 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 + ) diff --git a/pubnub/endpoints/users/create_user.py b/pubnub/endpoints/users/create_user.py index c28359ce..d76e56ee 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'] + ) diff --git a/pubnub/endpoints/users/delete_user.py b/pubnub/endpoints/users/delete_user.py index 5b6bf12f..126e34b4 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 + ) diff --git a/pubnub/endpoints/users/get_user.py b/pubnub/endpoints/users/get_user.py index fbaca447..abbdc167 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 + ) 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..b0b519dc 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 + ) 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..6dbdf0e2 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -4,9 +4,13 @@ import math import time import copy +import base64 +from cbor2 import loads +from pubnub.errors import PNERR_INVALID_ACCESS_TOKEN +from pubnub.exceptions import PubNubException 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 @@ -478,6 +482,130 @@ 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, token_manager_properties): + resource_token = self.get_token_by_match(token_manager_properties, PNMatchType.RESOURCE) + + if resource_token is None: + return self.get_token_by_match(token_manager_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, token_manager_properties, match_type): + if token_manager_properties is None or token_manager_properties.resource_type is None or token_manager_properties.resource_id is None: + return None + + if match_type != PNMatchType.PATTERN: + if token_manager_properties.resource_id in self._map[token_manager_properties.resource_type][match_type]: + token = self._map[token_manager_properties.resource_type][match_type][token_manager_properties.resource_id] + if token is not None: + return token + else: + string_token_wrapper_dict = self._map[token_manager_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 \ No newline at end of file diff --git a/pubnub/models/consumer/access_manager.py b/pubnub/models/consumer/access_manager.py index b71cd245..f5dfd9f7 100644 --- a/pubnub/models/consumer/access_manager.py +++ b/pubnub/models/consumer/access_manager.py @@ -82,14 +82,14 @@ def from_json(cls, json_input): 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): diff --git a/pubnub/models/consumer/v3/access_manager.py b/pubnub/models/consumer/v3/access_manager.py new file mode 100644 index 00000000..8d0b6510 --- /dev/null +++ b/pubnub/models/consumer/v3/access_manager.py @@ -0,0 +1,24 @@ +""" +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..20078757 --- /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 \ No newline at end of file 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..e22ded30 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) diff --git a/pubnub/pubnub_asyncio.py b/pubnub/pubnub_asyncio.py index 46d4b634..9383476e 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) diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 13afdd38..0feb5f90 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -3,7 +3,8 @@ from abc import ABCMeta, abstractmethod -from .managers import BasePathManager +from pubnub.endpoints.access.grant_token import GrantToken +from .managers import BasePathManager, TokenManager, TokenManagerProperties from .builders import SubscribeBuilder from .builders import UnsubscribeBuilder from .endpoints.time import Time @@ -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, token_manager_properties): + return self._token_manager.get_token(token_manager_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..b7559297 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( 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 ed75bf91..b69d55a3 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -4,6 +4,8 @@ import uuid as u import threading +from pubnub.endpoints.access.grant_token import GrantToken + try: from hashlib import sha256 @@ -17,7 +19,7 @@ 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 @@ -107,7 +109,7 @@ def is_subscribed_event(status): def is_unsubscribed_event(status): assert isinstance(status, PNStatus) return status.category == PNStatusCategory.PNAcknowledgmentCategory \ - and status.operation == PNOperationType.PNUnsubscribeOperation + and status.operation == PNOperationType.PNUnsubscribeOperation def prepare_pam_arguments(unsorted_params): @@ -182,7 +184,7 @@ def sign_request(endpoint, pn, custom_params, method, body): encoded_query_string = prepare_pam_arguments(custom_params) - is_v2_signature = not(request_url.startswith("/publish") and method == HttpMethod.POST) + is_v2_signature = not (request_url.startswith("/publish") and method == HttpMethod.POST) signed_input = "" if not is_v2_signature: @@ -196,7 +198,7 @@ def sign_request(endpoint, pn, custom_params, method, body): signed_input += request_url + "\n" signed_input += encoded_query_string + "\n" if body is not None: - signed_input += body + signed_input += body signature = sign_sha256(pn.config.secret_key, signed_input) if is_v2_signature: @@ -204,3 +206,76 @@ def sign_request(endpoint, pn, custom_params, method, body): 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 + + 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/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..cc5ce29f 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,8 @@ install_requires=[ 'pycryptodomex>=3.3', 'requests>=2.4', - 'six>=1.10' + 'six>=1.10', + 'cbor2' ], zip_safe=False, ) From 43e15f5aad65b52f99302f56ed3b4084ef313ab3 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 07:21:08 +0100 Subject: [PATCH 04/12] Resolve test warnings due to use of deprecated method. --- .../functional/push/test_add_channels_to_push.py | 6 +++--- .../functional/push/test_list_push_provisions.py | 6 +++--- .../push/test_remove_channels_from_push.py | 6 +++--- .../push/test_remove_device_from_push.py | 6 +++--- tests/functional/test_add_channel_to_cg.py | 4 ++-- tests/functional/test_get_state.py | 4 ++-- tests/functional/test_heartbeat.py | 10 +++++----- tests/functional/test_here_now.py | 6 +++--- tests/functional/test_history.py | 4 ++-- tests/functional/test_history_delete.py | 4 ++-- tests/functional/test_leave.py | 16 ++++++++-------- tests/functional/test_list_channels_in_cg.py | 2 +- tests/functional/test_publish.py | 14 +++++++------- tests/functional/test_remove_cg.py | 2 +- tests/functional/test_remove_channel_from_cg.py | 4 ++-- tests/functional/test_set_state.py | 4 ++-- tests/functional/test_subscribe.py | 16 ++++++++-------- tests/functional/test_where_now.py | 4 ++-- 18 files changed, 59 insertions(+), 59 deletions(-) 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..8eb7b377 100644 --- a/tests/functional/push/test_list_push_provisions.py +++ b/tests/functional/push/test_list_push_provisions.py @@ -28,7 +28,7 @@ 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(), + self.assertEqual(self.list_push.build_path(), ListPushProvisions.LIST_PATH % ( pnconf.subscribe_key, "coolDevice")) @@ -41,7 +41,7 @@ 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(), + self.assertEqual(self.list_push.build_path(), ListPushProvisions.LIST_PATH % ( pnconf.subscribe_key, "coolDevice")) @@ -54,7 +54,7 @@ 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(), + self.assertEqual(self.list_push.build_path(), ListPushProvisions.LIST_PATH % ( pnconf.subscribe_key, "coolDevice")) 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..16f80495 100644 --- a/tests/functional/test_add_channel_to_cg.py +++ b/tests/functional/test_add_channel_to_cg.py @@ -27,7 +27,7 @@ def setUp(self): def test_add_single_channel(self): self.add.channels('ch').channel_group('gr') - self.assertEquals(self.add.build_path(), + self.assertEqual(self.add.build_path(), AddChannelToChannelGroup.ADD_PATH % ( pnconf.subscribe_key, "gr")) @@ -42,7 +42,7 @@ 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(), + self.assertEqual(self.add.build_path(), AddChannelToChannelGroup.ADD_PATH % ( pnconf.subscribe_key, "gr")) diff --git a/tests/functional/test_get_state.py b/tests/functional/test_get_state.py index db348fc4..fce468a2 100644 --- a/tests/functional/test_get_state.py +++ b/tests/functional/test_get_state.py @@ -28,7 +28,7 @@ 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, + self.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, "ch", self.pubnub.uuid)) @@ -42,7 +42,7 @@ 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.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, ",", self.pubnub.uuid)) diff --git a/tests/functional/test_heartbeat.py b/tests/functional/test_heartbeat.py index cc844cfc..b9c750e3 100644 --- a/tests/functional/test_heartbeat.py +++ b/tests/functional/test_heartbeat.py @@ -30,7 +30,7 @@ def setUp(self): def test_sub_single_channel(self): self.hb.channels('ch') - self.assertEquals(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.hb.build_params_callback()({}), { @@ -44,7 +44,7 @@ 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 + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.hb.build_params_callback()({}), { @@ -58,7 +58,7 @@ 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 + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { @@ -73,7 +73,7 @@ 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 + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { @@ -91,7 +91,7 @@ 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 + self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH % (pnconf.subscribe_key, "ch1,ch2")) params = self.hb.build_params_callback()({}) diff --git a/tests/functional/test_here_now.py b/tests/functional/test_here_now.py index 8c352efd..41ae6962 100644 --- a/tests/functional/test_here_now.py +++ b/tests/functional/test_here_now.py @@ -27,7 +27,7 @@ def setUp(self): def test_here_now(self): self.here_now.channels("ch1") - self.assertEquals(self.here_now.build_path(), HereNow.HERE_NOW_PATH + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { @@ -38,7 +38,7 @@ 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 + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.here_now.build_params_callback()({}), { @@ -50,7 +50,7 @@ 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 + self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { 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..ec04a1d4 100644 --- a/tests/functional/test_history_delete.py +++ b/tests/functional/test_history_delete.py @@ -30,7 +30,7 @@ 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 % + self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history_delete.build_params_callback()({}), { @@ -41,7 +41,7 @@ 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 % + self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history_delete.build_params_callback()({}), { diff --git a/tests/functional/test_leave.py b/tests/functional/test_leave.py index 7a37d5cc..1a31c9b5 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,7 +75,7 @@ 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 + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { @@ -89,7 +89,7 @@ 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 + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { @@ -103,7 +103,7 @@ 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 + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { @@ -117,7 +117,7 @@ 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 + self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH % (pnconf.subscribe_key, "ch1,ch2")) self.assertEqual(self.leave.build_params_callback()({}), { diff --git a/tests/functional/test_list_channels_in_cg.py b/tests/functional/test_list_channels_in_cg.py index da1cd3bf..296e205e 100644 --- a/tests/functional/test_list_channels_in_cg.py +++ b/tests/functional/test_list_channels_in_cg.py @@ -27,7 +27,7 @@ def setUp(self): def test_list_channel_group(self): self.list.channel_group('gr') - self.assertEquals(self.list.build_path(), + self.assertEqual(self.list.build_path(), ListChannelsInChannelGroup.LIST_PATH % ( pnconf.subscribe_key, "gr")) diff --git a/tests/functional/test_publish.py b/tests/functional/test_publish.py index 677464d0..884089be 100644 --- a/tests/functional/test_publish.py +++ b/tests/functional/test_publish.py @@ -35,7 +35,7 @@ def test_pub_message(self): self.pub.channel("ch1").message(message) - self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + 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()({}), { @@ -51,7 +51,7 @@ 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" + 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()({}), { @@ -68,7 +68,7 @@ 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" + 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()({}), { @@ -85,7 +85,7 @@ 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" + 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()({}), { @@ -102,7 +102,7 @@ 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" + 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()({}), { @@ -128,7 +128,7 @@ 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" + 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()({}), { @@ -156,7 +156,7 @@ def test_pub_encrypted_list_message(self): pub.channel("ch1").message(message) - self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" + 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()({}), { diff --git a/tests/functional/test_remove_cg.py b/tests/functional/test_remove_cg.py index 3d9ecc7a..51a8682e 100644 --- a/tests/functional/test_remove_cg.py +++ b/tests/functional/test_remove_cg.py @@ -27,7 +27,7 @@ def setUp(self): def test_list_channel_group(self): self.list.channel_group('gr') - self.assertEquals(self.list.build_path(), + self.assertEqual(self.list.build_path(), RemoveChannelGroup.REMOVE_PATH % ( pnconf.subscribe_key, "gr")) diff --git a/tests/functional/test_remove_channel_from_cg.py b/tests/functional/test_remove_channel_from_cg.py index 9fb93b13..4eef166b 100644 --- a/tests/functional/test_remove_channel_from_cg.py +++ b/tests/functional/test_remove_channel_from_cg.py @@ -27,7 +27,7 @@ def setUp(self): def test_remove_single_channel(self): self.remove.channels('ch').channel_group('gr') - self.assertEquals(self.remove.build_path(), + self.assertEqual(self.remove.build_path(), RemoveChannelFromChannelGroup.REMOVE_PATH % ( pnconf.subscribe_key, "gr")) @@ -42,7 +42,7 @@ 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(), + self.assertEqual(self.remove.build_path(), RemoveChannelFromChannelGroup.REMOVE_PATH % ( pnconf.subscribe_key, "gr")) diff --git a/tests/functional/test_set_state.py b/tests/functional/test_set_state.py index bda6bb10..978bfb30 100644 --- a/tests/functional/test_set_state.py +++ b/tests/functional/test_set_state.py @@ -30,7 +30,7 @@ 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, + self.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, "ch", self.pubnub.uuid)) @@ -45,7 +45,7 @@ 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.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, ",", self.pubnub.uuid)) diff --git a/tests/functional/test_subscribe.py b/tests/functional/test_subscribe.py index 3dc81372..c3c71c2c 100644 --- a/tests/functional/test_subscribe.py +++ b/tests/functional/test_subscribe.py @@ -25,7 +25,7 @@ def setUp(self): def test_pub_single_channel(self): self.sub.channels('ch') - self.assertEquals(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.sub.build_params_callback()({}), { @@ -38,7 +38,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -51,7 +51,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -64,7 +64,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -77,7 +77,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -91,7 +91,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -105,7 +105,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { @@ -119,7 +119,7 @@ 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 + self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH % (pnconf.subscribe_key, "ch1,ch2")) self.assertEqual(self.sub.build_params_callback()({}), { diff --git a/tests/functional/test_where_now.py b/tests/functional/test_where_now.py index c2df0c65..6f34ca9b 100644 --- a/tests/functional/test_where_now.py +++ b/tests/functional/test_where_now.py @@ -25,7 +25,7 @@ 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 + self.assertEqual(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH % (pnconf.subscribe_key, "person_uuid")) self.assertEqual(self.where_now.build_params_callback()({}), { @@ -34,7 +34,7 @@ def test_where_now(self): }) def test_where_now_no_uuid(self): - self.assertEquals(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH + 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()({}), { From 434146b660494bd20f10d7ba2e3347871e2da344 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 12:58:57 +0100 Subject: [PATCH 05/12] Remove PAM audit tests. Resolve Codacy errors. --- pubnub/endpoints/endpoint.py | 6 +- pubnub/managers.py | 23 ++--- pubnub/models/consumer/v3/access_manager.py | 1 - pubnub/models/consumer/v3/pn_resource.py | 2 +- pubnub/pubnub_core.py | 4 +- pubnub/utils.py | 2 +- .../push/test_list_push_provisions.py | 12 +-- tests/functional/test_add_channel_to_cg.py | 8 +- tests/functional/test_audit.py | 10 +- tests/functional/test_get_state.py | 9 +- tests/functional/test_grant.py | 10 +- tests/functional/test_heartbeat.py | 11 +-- tests/functional/test_here_now.py | 7 +- tests/functional/test_history_delete.py | 4 +- tests/functional/test_leave.py | 8 +- tests/functional/test_list_channels_in_cg.py | 4 +- tests/functional/test_publish.py | 14 +-- tests/functional/test_remove_cg.py | 4 +- .../functional/test_remove_channel_from_cg.py | 8 +- tests/functional/test_revoke.py | 10 +- tests/functional/test_set_state.py | 8 +- tests/functional/test_stringify.py | 10 +- tests/functional/test_subscribe.py | 16 +-- tests/functional/test_where_now.py | 4 +- tests/integrational/asyncio/test_pam.py | 99 +------------------ 25 files changed, 105 insertions(+), 189 deletions(-) diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 98d944c6..74c76417 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -168,13 +168,13 @@ def callback(params_to_merge): PNOperationType.PNManageMembersOperation, PNOperationType.PNManageMembershipsOperation ]: - token_manager_properties = self.get_tms_properties() + tms_properties = self.get_tms_properties() - token = self.pubnub.get_token(token_manager_properties) + token = self.pubnub.get_token(tms_properties) if token is not None: custom_params['auth'] = token else: - logger.warning("No token found for: " + str(token_manager_properties)) + logger.warning("No token found for: " + str(tms_properties)) if self.pubnub.config.secret_key is not None: utils.sign_request(self, self.pubnub, custom_params, self.http_method(), self.build_data()) diff --git a/pubnub/managers.py b/pubnub/managers.py index 6dbdf0e2..f71e04a7 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -496,10 +496,7 @@ def __init__(self): self.init_map() def init_map(self): - resources = [ - PNResourceType.USER, - PNResourceType.SPACE - ] + resources = [PNResourceType.USER, PNResourceType.SPACE] for resource in resources: skeleton_map = { @@ -516,11 +513,11 @@ def set_tokens(self, tokens): for token in tokens: self.set_token(token) - def get_token(self, token_manager_properties): - resource_token = self.get_token_by_match(token_manager_properties, PNMatchType.RESOURCE) + 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(token_manager_properties, PNMatchType.PATTERN) + return self.get_token_by_match(tms_properties, PNMatchType.PATTERN) return resource_token @@ -564,17 +561,17 @@ def unwrap_token(self, token): except Exception: raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN) - def get_token_by_match(self, token_manager_properties, match_type): - if token_manager_properties is None or token_manager_properties.resource_type is None or token_manager_properties.resource_id is None: + 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 token_manager_properties.resource_id in self._map[token_manager_properties.resource_type][match_type]: - token = self._map[token_manager_properties.resource_type][match_type][token_manager_properties.resource_id] + 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[token_manager_properties.resource_type][match_type] + 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] @@ -608,4 +605,4 @@ def __init__(self, resource_type, resource_id): self.resource_id = resource_id def __str__(self): - return "resource_type: " + self.resource_type + ", resource_id: " + self.resource_id \ No newline at end of file + return "resource_type: " + self.resource_type + ", resource_id: " + self.resource_id diff --git a/pubnub/models/consumer/v3/access_manager.py b/pubnub/models/consumer/v3/access_manager.py index 8d0b6510..5f49a17d 100644 --- a/pubnub/models/consumer/v3/access_manager.py +++ b/pubnub/models/consumer/v3/access_manager.py @@ -21,4 +21,3 @@ def __str__(self): def get_token(self): return self.token - diff --git a/pubnub/models/consumer/v3/pn_resource.py b/pubnub/models/consumer/v3/pn_resource.py index 20078757..3f2a3aa8 100644 --- a/pubnub/models/consumer/v3/pn_resource.py +++ b/pubnub/models/consumer/v3/pn_resource.py @@ -31,4 +31,4 @@ def is_manage(self): return self._manage def is_delete(self): - return self._delete \ No newline at end of file + return self._delete diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 0feb5f90..999dc682 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -242,8 +242,8 @@ def set_token(self, token): def set_tokens(self, tokens): self._token_manager.set_tokens(tokens) - def get_token(self, token_manager_properties): - return self._token_manager.get_token(token_manager_properties) + 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( diff --git a/pubnub/utils.py b/pubnub/utils.py index b69d55a3..3e9b77c7 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -109,7 +109,7 @@ def is_subscribed_event(status): def is_unsubscribed_event(status): assert isinstance(status, PNStatus) return status.category == PNStatusCategory.PNAcknowledgmentCategory \ - and status.operation == PNOperationType.PNUnsubscribeOperation + and status.operation == PNOperationType.PNUnsubscribeOperation def prepare_pam_arguments(unsorted_params): diff --git a/tests/functional/push/test_list_push_provisions.py b/tests/functional/push/test_list_push_provisions.py index 8eb7b377..94296dca 100644 --- a/tests/functional/push/test_list_push_provisions.py +++ b/tests/functional/push/test_list_push_provisions.py @@ -29,8 +29,8 @@ def test_list_channel_group_apns(self): self.list_push.push_type(PNPushType.APNS).device_id('coolDevice') self.assertEqual(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -42,8 +42,8 @@ def test_list_channel_group_gcm(self): self.list_push.push_type(PNPushType.GCM).device_id('coolDevice') self.assertEqual(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -55,8 +55,8 @@ def test_list_channel_group_mpns(self): self.list_push.push_type(PNPushType.MPNS).device_id('coolDevice') self.assertEqual(self.list_push.build_path(), - ListPushProvisions.LIST_PATH % ( - pnconf.subscribe_key, "coolDevice")) + ListPushProvisions.LIST_PATH % ( + pnconf.subscribe_key, "coolDevice")) self.assertEqual(self.list_push.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 16f80495..c34bda1c 100644 --- a/tests/functional/test_add_channel_to_cg.py +++ b/tests/functional/test_add_channel_to_cg.py @@ -28,8 +28,8 @@ def test_add_single_channel(self): self.add.channels('ch').channel_group('gr') self.assertEqual(self.add.build_path(), - AddChannelToChannelGroup.ADD_PATH % ( - pnconf.subscribe_key, "gr")) + AddChannelToChannelGroup.ADD_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.add.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -43,8 +43,8 @@ def test_add_multiple_channels(self): self.add.channels(['ch1', 'ch2']).channel_group('gr') self.assertEqual(self.add.build_path(), - AddChannelToChannelGroup.ADD_PATH % ( - pnconf.subscribe_key, "gr")) + 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 694d77a7..042f9ac3 100644 --- a/tests/functional/test_audit.py +++ b/tests/functional/test_audit.py @@ -39,7 +39,10 @@ def test_audit_channel(self): 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.audit.http_method()).upper() + "\n" + pnconf_pam.publish_key + "\n" + self.audit.build_path() + "\n" + pam_args + "\n" + 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, @@ -60,7 +63,10 @@ def test_audit_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.audit.http_method()).upper() + "\n" + pnconf_pam.publish_key + "\n" + self.audit.build_path() + "\n" + pam_args + "\n" + 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, diff --git a/tests/functional/test_get_state.py b/tests/functional/test_get_state.py index fce468a2..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: @@ -29,8 +28,8 @@ def test_get_state_single_channel(self): self.get_state.channels('ch') self.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, - "ch", - self.pubnub.uuid)) + "ch", + self.pubnub.uuid)) self.assertEqual(self.get_state.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -43,8 +42,8 @@ def test_get_state_single_group(self): self.get_state.channel_groups('gr') self.assertEqual(self.get_state.build_path(), GetState.GET_STATE_PATH % (pnconf.subscribe_key, - ",", - self.pubnub.uuid)) + ",", + 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 b345ead8..95a5ca3c 100644 --- a/tests/functional/test_grant.py +++ b/tests/functional/test_grant.py @@ -41,7 +41,10 @@ def test_grant_read_and_write_to_channel(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.grant.http_method()).upper() + "\n" + pnconf_pam.publish_key + "\n" + self.grant.build_path() + "\n" + pam_args + "\n" + 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, @@ -66,7 +69,10 @@ def test_grant_read_and_write_to_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.grant.http_method()).upper() + "\n" + pnconf_pam.publish_key + "\n" + self.grant.build_path() + "\n" + pam_args + "\n" + 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, diff --git a/tests/functional/test_heartbeat.py b/tests/functional/test_heartbeat.py index b9c750e3..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: @@ -31,7 +30,7 @@ def test_sub_single_channel(self): self.hb.channels('ch') self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, 'ch')) + % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.hb.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -45,7 +44,7 @@ def test_hb_multiple_channels_using_list(self): self.hb.channels(['ch1', 'ch2', 'ch3']) self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.hb.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -59,7 +58,7 @@ def test_hb_single_group(self): self.hb.channel_groups("gr") self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { 'channel-group': 'gr', @@ -74,7 +73,7 @@ def test_hb_multiple_groups_using_list(self): self.hb.channel_groups(['gr1', 'gr2', 'gr3']) self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.hb.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -92,7 +91,7 @@ def test_hb_with_state(self): self.hb.channels('ch1,ch2').state(state) self.assertEqual(self.hb.build_path(), Heartbeat.HEARTBEAT_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + % (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 41ae6962..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: @@ -28,7 +27,7 @@ def test_here_now(self): self.here_now.channels("ch1") self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, "ch1")) + % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -39,7 +38,7 @@ def test_here_now_groups(self): self.here_now.channel_groups("gr1") self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.here_now.build_params_callback()({}), { 'channel-group': 'gr1', @@ -51,7 +50,7 @@ def test_here_now_with_options(self): self.here_now.channels(["ch1"]).channel_groups("gr1").include_state(True).include_uuids(False) self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH - % (pnconf.subscribe_key, "ch1")) + % (pnconf.subscribe_key, "ch1")) self.assertEqual(self.here_now.build_params_callback()({}), { 'channel-group': 'gr1', diff --git a/tests/functional/test_history_delete.py b/tests/functional/test_history_delete.py index ec04a1d4..af32baf0 100644 --- a/tests/functional/test_history_delete.py +++ b/tests/functional/test_history_delete.py @@ -31,7 +31,7 @@ def test_history_delete_basic(self): self.history_delete.channel('ch') self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % - (pnconf.subscribe_key, 'ch')) + (pnconf.subscribe_key, 'ch')) self.assertEqual(self.history_delete.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -42,7 +42,7 @@ def test_history_delete_full(self): self.history_delete.channel('ch').start(100000).end(200000) self.assertEqual(self.history_delete.build_path(), HistoryDelete.HISTORY_DELETE_PATH % - (pnconf.subscribe_key, 'ch')) + (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 1a31c9b5..78d886e5 100644 --- a/tests/functional/test_leave.py +++ b/tests/functional/test_leave.py @@ -76,7 +76,7 @@ def test_leave_single_group(self): self.leave.channel_groups("gr") self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr', @@ -90,7 +90,7 @@ def test_leave_multiple_groups_using_string(self): self.leave.channel_groups("gr1,gr2,gr3") self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -104,7 +104,7 @@ def test_leave_multiple_groups_using_list(self): self.leave.channel_groups(['gr1', 'gr2', 'gr3']) self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.leave.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -118,7 +118,7 @@ def test_leave_channels_and_groups(self): self.leave.channels('ch1,ch2').channel_groups(["gr1", "gr2"]) self.assertEqual(self.leave.build_path(), Leave.LEAVE_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + % (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 296e205e..d06ed726 100644 --- a/tests/functional/test_list_channels_in_cg.py +++ b/tests/functional/test_list_channels_in_cg.py @@ -28,8 +28,8 @@ def test_list_channel_group(self): self.list.channel_group('gr') self.assertEqual(self.list.build_path(), - ListChannelsInChannelGroup.LIST_PATH % ( - pnconf.subscribe_key, "gr")) + 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 884089be..e26b9750 100644 --- a/tests/functional/test_publish.py +++ b/tests/functional/test_publish.py @@ -36,7 +36,7 @@ def test_pub_message(self): self.pub.channel("ch1").message(message) self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -52,7 +52,7 @@ def test_pub_list_message(self): self.pub.channel("ch1").message(message) self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -69,7 +69,7 @@ def test_pub_with_meta(self): self.pub.channel("ch1").message(message).meta(meta) self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -86,7 +86,7 @@ def test_pub_store(self): self.pub.channel("ch1").message(message).should_store(True) self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -103,7 +103,7 @@ def test_pub_do_not_store(self): self.pub.channel("ch1").message(message).should_store(False) self.assertEqual(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(self.pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -129,7 +129,7 @@ def test_pub_with_auth(self): pub.channel("ch1").message(message) self.assertEqual(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) self.assertEqual(pub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -157,7 +157,7 @@ def test_pub_encrypted_list_message(self): pub.channel("ch1").message(message) self.assertEqual(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s" - % (pnconf.publish_key, pnconf.subscribe_key, encoded_message)) + % (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 51a8682e..0fa0a758 100644 --- a/tests/functional/test_remove_cg.py +++ b/tests/functional/test_remove_cg.py @@ -28,8 +28,8 @@ def test_list_channel_group(self): self.list.channel_group('gr') self.assertEqual(self.list.build_path(), - RemoveChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + 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 4eef166b..58940456 100644 --- a/tests/functional/test_remove_channel_from_cg.py +++ b/tests/functional/test_remove_channel_from_cg.py @@ -28,8 +28,8 @@ def test_remove_single_channel(self): self.remove.channels('ch').channel_group('gr') self.assertEqual(self.remove.build_path(), - RemoveChannelFromChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + RemoveChannelFromChannelGroup.REMOVE_PATH % ( + pnconf.subscribe_key, "gr")) self.assertEqual(self.remove.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -43,8 +43,8 @@ def test_remove_multiple_channels(self): self.remove.channels(['ch1', 'ch2']).channel_group('gr') self.assertEqual(self.remove.build_path(), - RemoveChannelFromChannelGroup.REMOVE_PATH % ( - pnconf.subscribe_key, "gr")) + 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 34d65902..718a2880 100644 --- a/tests/functional/test_revoke.py +++ b/tests/functional/test_revoke.py @@ -45,7 +45,10 @@ def test_revoke_to_channel(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.revoke.http_method()).upper() + "\n" + pnconf.publish_key + "\n" + self.revoke.build_path() + "\n" + pam_args + "\n" + 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, @@ -77,7 +80,10 @@ def test_grant_read_and_write_to_channel_group(self): 'pnsdk': sdk_name, 'uuid': self.pubnub.uuid }) - sign_input = HttpMethod.string(self.revoke.http_method()).upper() + "\n" + pnconf.publish_key + "\n" + self.revoke.build_path() + "\n" + pam_args + "\n" + 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, diff --git a/tests/functional/test_set_state.py b/tests/functional/test_set_state.py index 978bfb30..4f0b6d10 100644 --- a/tests/functional/test_set_state.py +++ b/tests/functional/test_set_state.py @@ -31,8 +31,8 @@ def test_set_state_single_channel(self): self.set_state.channels('ch').state(self.state) self.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, - "ch", - self.pubnub.uuid)) + "ch", + self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) @@ -46,8 +46,8 @@ def test_set_state_single_group(self): self.set_state.channel_groups('gr').state(self.state) self.assertEqual(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, - ",", - self.pubnub.uuid)) + ",", + 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 c3c71c2c..38f35c7d 100644 --- a/tests/functional/test_subscribe.py +++ b/tests/functional/test_subscribe.py @@ -26,7 +26,7 @@ def test_pub_single_channel(self): self.sub.channels('ch') self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, 'ch')) + % (pnconf.subscribe_key, 'ch')) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -39,7 +39,7 @@ def test_sub_multiple_channels_using_string(self): self.sub.channels("ch1,ch2,ch3") self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -52,7 +52,7 @@ def test_sub_multiple_channels_using_list(self): self.sub.channels(['ch1', 'ch2', 'ch3']) self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -65,7 +65,7 @@ def test_sub_multiple_channels_using_tuple(self): self.sub.channels(('ch1', 'ch2', 'ch3')) self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2,ch3")) + % (pnconf.subscribe_key, "ch1,ch2,ch3")) self.assertEqual(self.sub.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -78,7 +78,7 @@ def test_sub_single_group(self): self.sub.channel_groups("gr") self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr', @@ -92,7 +92,7 @@ def test_sub_multiple_groups_using_string(self): self.sub.channel_groups("gr1,gr2,gr3") self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -106,7 +106,7 @@ def test_sub_multiple_groups_using_list(self): self.sub.channel_groups(['gr1', 'gr2', 'gr3']) self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, ",")) + % (pnconf.subscribe_key, ",")) self.assertEqual(self.sub.build_params_callback()({}), { 'channel-group': 'gr1,gr2,gr3', @@ -120,7 +120,7 @@ def test_sub_multiple(self): self.sub.channels('ch1,ch2').filter_expression('blah').region('us-east-1').timetoken('123') self.assertEqual(self.sub.build_path(), Subscribe.SUBSCRIBE_PATH - % (pnconf.subscribe_key, "ch1,ch2")) + % (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 6f34ca9b..9d3229ff 100644 --- a/tests/functional/test_where_now.py +++ b/tests/functional/test_where_now.py @@ -26,7 +26,7 @@ def test_where_now(self): self.where_now.uuid("person_uuid") self.assertEqual(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH - % (pnconf.subscribe_key, "person_uuid")) + % (pnconf.subscribe_key, "person_uuid")) self.assertEqual(self.where_now.build_params_callback()({}), { 'pnsdk': sdk_name, @@ -35,7 +35,7 @@ def test_where_now(self): def test_where_now_no_uuid(self): self.assertEqual(self.where_now.build_path(), WhereNow.WHERE_NOW_PATH - % (pnconf.subscribe_key, self.pubnub.config.uuid)) + % (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..cb0edc37 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 @@ -25,16 +25,6 @@ def test_global_level(event_loop): 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 - env = yield from pubnub.revoke().future() assert isinstance(env.result, PNAccessManagerGrantResult) @@ -66,15 +56,6 @@ def test_single_channel(event_loop): 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 - pubnub.stop() @@ -99,16 +80,6 @@ def test_single_channel_with_auth(event_loop): 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 - pubnub.stop() @@ -140,18 +111,6 @@ def test_multiple_channels(event_loop): 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 - pubnub.stop() @@ -185,18 +144,6 @@ def test_multiple_channels_with_auth(event_loop): 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 - pubnub.stop() @@ -220,16 +167,6 @@ def test_single_channel_group(event_loop): 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 - pubnub.stop() @@ -255,16 +192,6 @@ def test_single_channel_group_with_auth(event_loop): 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 - pubnub.stop() @@ -296,18 +223,6 @@ def test_multiple_channel_groups(event_loop): 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 - pubnub.stop() @@ -341,16 +256,4 @@ def test_multiple_channel_groups_with_auth(event_loop): 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 - pubnub.stop() From c05e312435df4cf7fca971b300522cd99197e00e Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 13:24:16 +0100 Subject: [PATCH 06/12] Resolve logger deprecation warnings. Add delete_enabled field to PAMv2 Grant tests. --- pubnub/pubnub.py | 2 +- pubnub/pubnub_asyncio.py | 2 +- pubnub/pubnub_tornado.py | 2 +- tests/integrational/asyncio/test_pam.py | 14 ++++ .../fixtures/asyncio/pam/global_level.yaml | 84 +++++++++++-------- .../asyncio/pam/multiple_channel_groups.yaml | 49 ++++++----- .../multiple_channel_groups_with_auth.yaml | 49 ++++++----- .../asyncio/pam/multiple_channels.yaml | 49 ++++++----- .../pam/multiple_channels_with_auth.yaml | 49 ++++++----- .../fixtures/asyncio/pam/single_channel.yaml | 49 ++++++----- .../asyncio/pam/single_channel_group.yaml | 49 ++++++----- .../pam/single_channel_group_with_auth.yaml | 49 ++++++----- .../asyncio/pam/single_channel_with_auth.yaml | 49 ++++++----- 13 files changed, 258 insertions(+), 238 deletions(-) diff --git a/pubnub/pubnub.py b/pubnub/pubnub.py index e22ded30..ade34118 100644 --- a/pubnub/pubnub.py +++ b/pubnub/pubnub.py @@ -129,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 9383476e..01461b11 100644 --- a/pubnub/pubnub_asyncio.py +++ b/pubnub/pubnub_asyncio.py @@ -290,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_tornado.py b/pubnub/pubnub_tornado.py index b7559297..d2499ab7 100644 --- a/pubnub/pubnub_tornado.py +++ b/pubnub/pubnub_tornado.py @@ -323,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/tests/integrational/asyncio/test_pam.py b/tests/integrational/asyncio/test_pam.py index cb0edc37..89bf84b4 100644 --- a/tests/integrational/asyncio/test_pam.py +++ b/tests/integrational/asyncio/test_pam.py @@ -24,6 +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 + assert env.result.delete_enabled is False env = yield from pubnub.revoke().future() @@ -33,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() @@ -55,6 +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 + assert env.result.channels[ch].delete_enabled == 0 pubnub.stop() @@ -79,6 +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 + assert env.result.channels[ch].auth_keys[auth].delete_enabled == 0 pubnub.stop() @@ -110,6 +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 + assert env.result.channels[ch1].delete_enabled is False + assert env.result.channels[ch2].delete_enabled is False pubnub.stop() @@ -143,6 +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 + 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() @@ -166,6 +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 + assert env.result.groups[cg].delete_enabled == 0 pubnub.stop() @@ -191,6 +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 + assert env.result.groups[gr].auth_keys[auth].delete_enabled == 0 pubnub.stop() @@ -222,6 +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 + assert env.result.groups[gr1].delete_enabled is False + assert env.result.groups[gr2].delete_enabled is False pubnub.stop() @@ -255,5 +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 + 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 5fdebb65..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/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/v2/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/v2/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/v2/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/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/v2/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 52c70c70..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/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/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.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/v2/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/v2/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 06b63225..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/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/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.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/v2/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/v2/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 aca4580a..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/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/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.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/v2/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/v2/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 0abd3168..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/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/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.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/v2/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/v2/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 b9d822d4..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/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/v2/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/v2/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/v2/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 b7fa018f..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/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/v2/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/v2/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/v2/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 d03b0c07..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/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/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.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/v2/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/v2/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 7727ee46..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/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/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.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/v2/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/v2/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 From ff496b22518f9f95df07eaae576529945447c184 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 15:25:18 +0100 Subject: [PATCH 07/12] Resolved import errors in older Python versions. --- pubnub/managers.py | 4 ++-- pubnub/models/consumer/v3/__init__.py | 0 pubnub/pubnub_core.py | 2 +- pubnub/utils.py | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 pubnub/models/consumer/v3/__init__.py diff --git a/pubnub/managers.py b/pubnub/managers.py index f71e04a7..1c51cc26 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -7,8 +7,6 @@ import base64 from cbor2 import loads -from pubnub.errors import PNERR_INVALID_ACCESS_TOKEN -from pubnub.exceptions import PubNubException from . import utils from .enums import PNStatusCategory, PNReconnectionPolicy, PNOperationType, PNResourceType, PNMatchType from .models.consumer.common import PNStatus @@ -16,6 +14,8 @@ 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") 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/pubnub_core.py b/pubnub/pubnub_core.py index 999dc682..93102f95 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -3,7 +3,6 @@ from abc import ABCMeta, abstractmethod -from pubnub.endpoints.access.grant_token import GrantToken from .managers import BasePathManager, TokenManager, TokenManagerProperties from .builders import SubscribeBuilder from .builders import UnsubscribeBuilder @@ -11,6 +10,7 @@ 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 diff --git a/pubnub/utils.py b/pubnub/utils.py index 3e9b77c7..e2737e18 100644 --- a/pubnub/utils.py +++ b/pubnub/utils.py @@ -4,8 +4,6 @@ import uuid as u import threading -from pubnub.endpoints.access.grant_token import GrantToken - try: from hashlib import sha256 @@ -233,6 +231,7 @@ def parse_resources(resource_list, resource_set_name, resources, patterns): 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 From d4f34040f403538e9496cdbb6ba74e6a86d646cc Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 15:37:43 +0100 Subject: [PATCH 08/12] Resolve unused variable warning. --- pubnub/models/consumer/access_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubnub/models/consumer/access_manager.py b/pubnub/models/consumer/access_manager.py index f5dfd9f7..800c68c5 100644 --- a/pubnub/models/consumer/access_manager.py +++ b/pubnub/models/consumer/access_manager.py @@ -111,7 +111,7 @@ def from_json(cls, name, 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, d) + return cls(name, constructed_auth_keys, r, w, m, d, ttl) class PNAccessManagerChannelData(_PAMEntityData): From af10c5b2ac154693e81551f4fc2a0adcac92fcc1 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 15:38:14 +0100 Subject: [PATCH 09/12] Add cbor2 dependency to PyPy. --- requirements-pypy-dev.txt | 1 + 1 file changed, 1 insertion(+) 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 From 2d10d558ff33626187851d25eeb4c389e6ac6535 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Tue, 24 Dec 2019 16:02:29 +0100 Subject: [PATCH 10/12] Prepare for release 4.1.8. --- .pubnub.yml | 15 ++++++++++++++- CHANGELOG.md | 10 ++++++++++ pubnub/pubnub_core.py | 2 +- setup.py | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index c9815bbd..d7a02765 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: 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/pubnub_core.py b/pubnub/pubnub_core.py index 93102f95..81b231a2 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -52,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 diff --git a/setup.py b/setup.py index cc5ce29f..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', From d48835b65bb7c53958a7677f26e36a69176b73c7 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Thu, 26 Dec 2019 15:17:42 +0100 Subject: [PATCH 11/12] Refactor token manager properties code. --- pubnub/endpoints/endpoint.py | 14 ++------------ pubnub/endpoints/membership/get_members.py | 2 +- .../endpoints/membership/get_space_memberships.py | 2 +- pubnub/endpoints/membership/manage_members.py | 2 +- pubnub/endpoints/membership/manage_memberships.py | 2 +- pubnub/endpoints/space/create_space.py | 2 +- pubnub/endpoints/space/delete_space.py | 2 +- pubnub/endpoints/space/get_space.py | 2 +- pubnub/endpoints/space/update_space.py | 2 +- pubnub/endpoints/users/create_user.py | 2 +- pubnub/endpoints/users/delete_user.py | 2 +- pubnub/endpoints/users/get_user.py | 2 +- pubnub/endpoints/users/update_user.py | 2 +- 13 files changed, 14 insertions(+), 24 deletions(-) diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 74c76417..92d870e7 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -158,18 +158,8 @@ def callback(params_to_merge): custom_params['auth'] = self.pubnub.config.auth_key if self.pubnub.config.disable_token_manager is False and self.pubnub.config.auth_key is None: - if self.operation_type() in [ - PNOperationType.PNGetUsersOperation, PNOperationType.PNCreateUserOperation, - PNOperationType.PNGetUserOperation, PNOperationType.PNUpdateUserOperation, - PNOperationType.PNDeleteUserOperation, PNOperationType.PNGetSpacesOperation, - PNOperationType.PNCreateSpaceOperation, PNOperationType.PNGetSpaceOperation, - PNOperationType.PNUpdateSpaceOperation, PNOperationType.PNDeleteSpaceOperation, - PNOperationType.PNGetMembersOperation, PNOperationType.PNGetSpaceMembershipsOperation, - PNOperationType.PNManageMembersOperation, PNOperationType.PNManageMembershipsOperation - ]: - - tms_properties = self.get_tms_properties() - + 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 diff --git a/pubnub/endpoints/membership/get_members.py b/pubnub/endpoints/membership/get_members.py index 86164ec0..a5af63e8 100644 --- a/pubnub/endpoints/membership/get_members.py +++ b/pubnub/endpoints/membership/get_members.py @@ -103,5 +103,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._space_id + 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 8d921960..eff67584 100644 --- a/pubnub/endpoints/membership/get_space_memberships.py +++ b/pubnub/endpoints/membership/get_space_memberships.py @@ -103,5 +103,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._user_id + 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 39b3d22a..57a0b898 100644 --- a/pubnub/endpoints/membership/manage_members.py +++ b/pubnub/endpoints/membership/manage_members.py @@ -113,5 +113,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._space_id + 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 c735d9cc..d2cc82f4 100644 --- a/pubnub/endpoints/membership/manage_memberships.py +++ b/pubnub/endpoints/membership/manage_memberships.py @@ -113,5 +113,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._user_id + 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 d1c5d710..6459183d 100644 --- a/pubnub/endpoints/space/create_space.py +++ b/pubnub/endpoints/space/create_space.py @@ -66,5 +66,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._data['id'] + 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 6459926c..a2d4eae6 100644 --- a/pubnub/endpoints/space/delete_space.py +++ b/pubnub/endpoints/space/delete_space.py @@ -57,5 +57,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._space_id + 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 a9076de3..2b8c286f 100644 --- a/pubnub/endpoints/space/get_space.py +++ b/pubnub/endpoints/space/get_space.py @@ -62,5 +62,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._space_id + resource_id=self._space_id if self._space_id is not None else "" ) diff --git a/pubnub/endpoints/space/update_space.py b/pubnub/endpoints/space/update_space.py index 6d7f6fc5..bc03eeab 100644 --- a/pubnub/endpoints/space/update_space.py +++ b/pubnub/endpoints/space/update_space.py @@ -74,5 +74,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.SPACE, - resource_id=self._space_id + 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 d76e56ee..6c7579c5 100644 --- a/pubnub/endpoints/users/create_user.py +++ b/pubnub/endpoints/users/create_user.py @@ -66,5 +66,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._data['id'] + 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 126e34b4..5bebc46f 100644 --- a/pubnub/endpoints/users/delete_user.py +++ b/pubnub/endpoints/users/delete_user.py @@ -57,5 +57,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._user_id + 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 abbdc167..cfb95545 100644 --- a/pubnub/endpoints/users/get_user.py +++ b/pubnub/endpoints/users/get_user.py @@ -62,5 +62,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._user_id + resource_id=self._user_id if self._user_id is not None else "" ) diff --git a/pubnub/endpoints/users/update_user.py b/pubnub/endpoints/users/update_user.py index b0b519dc..93d9a10c 100644 --- a/pubnub/endpoints/users/update_user.py +++ b/pubnub/endpoints/users/update_user.py @@ -74,5 +74,5 @@ def name(self): def get_tms_properties(self): return TokenManagerProperties( resource_type=PNResourceType.USER, - resource_id=self._user_id + resource_id=self._user_id if self._user_id is not None else "" ) From 2e84c9dcfa6c2ed948ba8995bdc098bb697e3973 Mon Sep 17 00:00:00 2001 From: QSD_s Date: Thu, 26 Dec 2019 16:04:14 +0100 Subject: [PATCH 12/12] Update .pubnub.yml. --- .pubnub.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pubnub.yml b/.pubnub.yml index d7a02765..5a43ae14 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -150,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 @@ -172,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 @@ -208,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