def __init__(self, pubnub):
        Grant.__init__(self, pubnub)
        self._read = False
        self._write = False
        self._manage = False

        self._sort_params = True
Beispiel #2
0
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf_pam,
                             sdk_name=sdk_name,
                             timestamp=MagicMock(return_value=123),
                             uuid=None)
     self.pubnub.uuid = "UUID_GrantUnitTest"
     self.grant = Grant(self.pubnub)
Beispiel #3
0
 def setUp(self):
     self.pubnub = MagicMock(
         spec=PubNub,
         config=pnconf_pam,
         sdk_name=sdk_name,
         timestamp=MagicMock(return_value=123),
         uuid=None
     )
     self.pubnub.uuid = "UUID_GrantUnitTest"
     self.grant = Grant(self.pubnub)
Beispiel #4
0
class TestGrant(unittest.TestCase):
    def setUp(self):
        self.pubnub = MagicMock(
            spec=PubNub,
            config=pnconf_pam,
            sdk_name=sdk_name,
            timestamp=MagicMock(return_value=123),
            uuid=None
        )
        self.pubnub.uuid = "UUID_GrantUnitTest"
        self.pubnub._telemetry_manager = TelemetryManager()
        self.grant = Grant(self.pubnub)

    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)

        pam_args = utils.prepare_pam_arguments({
            'r': '1',
            'w': '1',
            'ttl': '7',
            'timestamp': 123,
            'channel': 'ch',
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid
        })
        sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "grant\n" + pam_args
        self.assertEqual(self.grant.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'r': '1',
            'w': '1',
            'ttl': '7',
            'timestamp': '123',
            'channel': 'ch',
            'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input)
        })

    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)

        pam_args = utils.prepare_pam_arguments({
            'r': '1',
            'w': '1',
            'timestamp': 123,
            'channel-group': 'gr1,gr2',
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid
        })
        sign_input = pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" + "grant\n" + pam_args
        self.assertEqual(self.grant.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'r': '1',
            'w': '1',
            'timestamp': '123',
            'channel-group': 'gr1,gr2',
            'signature': utils.sign_sha256(pnconf_pam.secret_key, sign_input)
        })
Beispiel #5
0
class TestGrant(unittest.TestCase):
    def setUp(self):
        self.pubnub = MagicMock(
            spec=PubNub,
            config=pnconf_pam,
            sdk_name=sdk_name,
            timestamp=MagicMock(return_value=123),
            uuid=None
        )
        self.pubnub.uuid = "UUID_GrantUnitTest"
        self.grant = Grant(self.pubnub)

    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_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'r': '1',
            'w': '1',
            'ttl': '7',
            'timestamp': '123',
            'channel': 'ch',
            'signature': utils.sign_sha256(pnconf_pam.secret_key,
                                           pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" +
                                           "grant\n" + utils.prepare_pam_arguments({
                                               'r': '1',
                                               'w': '1',
                                               'ttl': '7',
                                               'timestamp': 123,
                                               'channel': 'ch',
                                               'pnsdk': sdk_name,
                                               'uuid': self.pubnub.uuid
                                           }))
        })

    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_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'r': '1',
            'w': '1',
            'timestamp': '123',
            'channel-group': 'gr1,gr2',
            'signature': utils.sign_sha256(pnconf_pam.secret_key,
                                           pnconf_pam.subscribe_key + "\n" + pnconf_pam.publish_key + "\n" +
                                           "grant\n" + utils.prepare_pam_arguments({
                                               'r': '1',
                                               'w': '1',
                                               'timestamp': 123,
                                               'channel-group': 'gr1,gr2',
                                               'pnsdk': sdk_name,
                                               'uuid': self.pubnub.uuid
                                           }))
        })