Пример #1
0
    def test_check_channel_sign(self):
        res = check_channel_sign('w', self.secret, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)

        res = check_channel_sign('w'*32, self.secret, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)

        res = check_channel_sign('w'*64, self.secret, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)
Пример #2
0
    def test_check_channel_sign(self):
        res = check_channel_sign('w', self.secret_key, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)

        res = check_channel_sign('w'*32, self.secret_key, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)

        res = check_channel_sign('w'*64, self.secret_key, 'test', 'channel', 'channel data')
        self.assertEqual(res, False)
Пример #3
0
    def handle_subscribe(self, params):
        """
        Subscribe client on channel.
        """
        project = self.application.get_project(self.project_name)
        if not project:
            raise Return((None, self.application.PROJECT_NOT_FOUND))

        channel = params.get('channel')
        if not channel:
            raise Return((None, 'channel required'))

        if len(channel) > self.application.MAX_CHANNEL_LENGTH:
            raise Return((None, 'maximum channel length exceeded'))

        body = {
            "channel": channel,
        }

        if self.application.USER_CHANNEL_BOUNDARY in channel:
            users_allowed = self.application.get_allowed_users(channel)
            if self.user not in users_allowed:
                raise Return((body, self.application.PERMISSION_DENIED))

        namespace = self.application.get_namespace(project, channel)
        if not namespace:
            raise Return((body, self.application.NAMESPACE_NOT_FOUND))

        project_name = self.project_name

        anonymous = namespace['anonymous']
        if not anonymous and not self.user and not self.application.INSECURE:
            raise Return((body, self.application.PERMISSION_DENIED))

        is_private = self.application.is_channel_private(channel)

        if is_private:
            client = params.get("client", "")
            if client != self.uid:
                raise Return((body, self.application.UNAUTHORIZED))
            sign = params.get("sign", "")
            info = params.get("info", "")
            is_authorized = auth.check_channel_sign(
                sign, project["secret"], client, channel, info
            )
            if not is_authorized:
                raise Return((body, self.application.UNAUTHORIZED))

            self.update_channel_info(info, channel)

        yield self.application.engine.add_subscription(
            project_name, channel, self
        )

        self.channels[channel] = True

        info = self.get_info(channel)

        yield self.application.engine.add_presence(
            project_name, channel, self.uid, info
        )

        if namespace['join_leave']:
            self.send_join_message(channel)

        raise Return((body, None))
Пример #4
0
    def handle_subscribe(self, params):
        """
        Subscribe client on channel.
        """
        project, error = yield self.application.get_project(self.project_id)
        if error:
            raise Return((None, error))

        channel = params.get('channel')
        if not channel:
            raise Return((None, 'channel required'))

        if len(channel) > self.application.MAX_CHANNEL_LENGTH:
            raise Return((None, 'maximum channel length exceeded'))

        body = {
            "channel": channel,
        }

        if self.application.USER_SEPARATOR in channel:
            users_allowed = self.application.get_allowed_users(channel)
            if self.user not in users_allowed:
                raise Return((body, self.application.PERMISSION_DENIED))

        namespace, error = yield self.application.get_namespace(project, channel)
        if error:
            raise Return((body, error))

        project_id = self.project_id

        anonymous = namespace.get('anonymous', False)
        if not anonymous and not self.user and not self.application.INSECURE:
            raise Return((body, self.application.PERMISSION_DENIED))

        is_private = self.application.is_channel_private(channel)

        if is_private:
            client = params.get("client", "")
            if client != self.uid:
                raise Return((body, self.application.UNAUTHORIZED))
            sign = params.get("sign", "")
            info = params.get("info", "{}")
            is_authorized = auth.check_channel_sign(
                sign, project.get("secret_key"), client, channel, info
            )
            if not is_authorized:
                raise Return((body, self.application.UNAUTHORIZED))

            self.update_channel_info(info, channel)

        yield self.application.engine.add_subscription(
            project_id, channel, self
        )

        self.channels[channel] = True

        info = self.get_info(channel)

        yield self.application.engine.add_presence(
            project_id, channel, self.uid, info
        )

        if namespace.get('join_leave', False):
            self.send_join_message(channel)

        raise Return((body, None))