示例#1
0
    def test_audit_channel_group(self):
        self.audit.channel_groups(['gr1', 'gr2'])

        self.assertEqual(self.audit.build_path(),
                         Audit.AUDIT_PATH % pnconf_pam.subscribe_key)

        pam_args = utils.prepare_pam_arguments({
            'timestamp': 123,
            'channel-group': 'gr1,gr2',
            '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"
        self.assertEqual(
            self.audit.build_params_callback()({}), {
                'pnsdk':
                sdk_name,
                'uuid':
                self.pubnub.uuid,
                'timestamp':
                '123',
                'channel-group':
                'gr1,gr2',
                'signature':
                "v2." + utils.sign_sha256(pnconf_pam.secret_key,
                                          sign_input).rstrip("=")
            })
示例#2
0
    def test_grant_read_and_write_to_channel_group(self):
        self.revoke.channel_groups(['gr1', 'gr2'])

        self.assertEqual(self.revoke.build_path(),
                         Revoke.GRANT_PATH % pnconf.subscribe_key)

        pam_args = utils.prepare_pam_arguments({
            'r': '0',
            'w': '0',
            'm': '0',
            'g': '0',
            'u': '0',
            'j': '0',
            'timestamp': 123,
            'channel-group': 'gr1,gr2',
            '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"
        self.assertEqual(
            self.revoke.build_params_callback()({}), {
                'pnsdk':
                sdk_name,
                'uuid':
                self.pubnub.uuid,
                'r':
                '0',
                'w':
                '0',
                'm':
                '0',
                'g':
                '0',
                'u':
                '0',
                'j':
                '0',
                'timestamp':
                '123',
                'channel-group':
                'gr1,gr2',
                'signature':
                "v2." +
                utils.sign_sha256(pnconf.secret_key, sign_input).rstrip("=")
            })
示例#3
0
    def test_grant_read_and_write_to_channel(self):
        self.grant.channels('ch').read(True).write(True).ttl(7)

        self.assertEqual(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 = 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,
                'r':
                '1',
                'w':
                '1',
                'ttl':
                '7',
                'timestamp':
                '123',
                'channel':
                'ch',
                'signature':
                "v2." + utils.sign_sha256(pnconf_pam.secret_key,
                                          sign_input).rstrip("=")
            })