示例#1
0
    async def test_wrong_secret(self):
        secret = 'wrong.secret'

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id='777', secret=secret).SerializeToString())
        await self.check_error(
            request, 'discord.data_protection_collect_data.wrong_secret')
示例#2
0
    async def test_has_data(self):
        # prepair data
        await operations.set_properties([
            helpers.property(object_id=100,
                             type=200,
                             value='x.1',
                             mode=relations.MODE.APPEND),
            helpers.property(object_id=200,
                             type=200,
                             value='x.2',
                             mode=relations.MODE.APPEND),
            helpers.property(object_id=100,
                             type=200,
                             value='y.1',
                             mode=relations.MODE.APPEND),
            helpers.property(object_id=300,
                             type=200,
                             value='y.2',
                             mode=relations.MODE.APPEND),
            helpers.property(object_id=100,
                             type=400,
                             value='x.4',
                             mode=relations.MODE.APPEND)
        ])

        # request data

        secret = helpers.get_config()['custom']['data_protector']['secret']

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id=str('100'), secret=secret).SerializeToString())
        response = await self.check_success(
            request, data_protector_pb2.PluginReportResponse, raw=True)

        self.assertEqual(
            response.result,
            data_protector_pb2.PluginReportResponse.ResultType.Value(
                'SUCCESS'))

        report = s11n.from_json(response.data)

        self.assertCountEqual(report,
                              [['property', {
                                  'type': 200,
                                  'value': 'x.1'
                              }], ['property', {
                                  'type': 200,
                                  'value': 'y.1'
                              }], ['property', {
                                  'type': 400,
                                  'value': 'x.4'
                              }]])
示例#3
0
    async def test_no_data(self):
        secret = helpers.get_config()['custom']['data_protector']['secret']

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id='777', secret=secret).SerializeToString())
        response = await self.check_success(
            request, data_protector_pb2.PluginReportResponse, raw=True)

        self.assertEqual(
            response.result,
            data_protector_pb2.PluginReportResponse.ResultType.Value(
                'SUCCESS'))

        report = s11n.from_json(response.data)

        self.assertEqual(report, [])
示例#4
0
    async def test_has_data(self):

        # prepair data
        accounts_infos = await helpers.create_accounts(game_ids=(666, 777, 888)
                                                       )

        await helpers.force_bind(accounts_infos[1].id, discord_id=100500)
        await helpers.force_bind(accounts_infos[2].id, discord_id=100501)

        code_1_1 = await operations.get_bind_code(accounts_infos[0].id,
                                                  expire_timeout=60)
        code_2 = await operations.get_bind_code(accounts_infos[2].id,
                                                expire_timeout=60)
        code_1_2 = await operations.get_bind_code(accounts_infos[0].id,
                                                  expire_timeout=60)

        new_info = await operations.get_account_info_by_id(accounts_infos[2].id
                                                           )

        # request data

        secret = helpers.get_config()['custom']['data_protector']['secret']

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id='888', secret=secret).SerializeToString())
        response = await self.check_success(
            request, data_protector_pb2.PluginReportResponse, raw=True)

        self.assertEqual(
            response.result,
            data_protector_pb2.PluginReportResponse.ResultType.Value(
                'SUCCESS'))

        report = s11n.from_json(response.data)

        self.assertEqual(
            report,
            [['discord_id', 100501], ['bind_code', code_2.data()]])
示例#5
0
    async def test_has_data(self):
        infos, invoices = await self.prepair_complex_data()

        secret = helpers.get_config()['custom']['data_protector']['secret']

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id=str(infos[0].id),
                secret=secret).SerializeToString())
        response = await self.check_success(
            request, data_protector_pb2.PluginReportResponse, raw=True)

        self.assertEqual(
            response.result,
            data_protector_pb2.PluginReportResponse.ResultType.Value(
                'SUCCESS'))

        report = s11n.from_json(response.data)

        self.assertCountEqual(report, [
            ['account_info', {
                'email': infos[0].email,
                'name': infos[0].name
            }],
            [
                'invoice', {
                    'purchased_amount': invoices[0].purchased_amount,
                    'xsolla_id': invoices[0].xsolla_id
                }
            ],
            [
                'invoice', {
                    'purchased_amount': invoices[2].purchased_amount,
                    'xsolla_id': invoices[2].xsolla_id
                }
            ]
        ])
示例#6
0
    async def request_report(self, account_id, logger):
        try:
            async with aiohttp.ClientSession() as session:
                data = data_protector_pb2.PluginReportRequest(
                    account_id=account_id, secret=self.secret)

                logger.info('request %s', self.report_url)

                async with session.post(
                        self.report_url,
                        data=data.SerializeToString()) as response:
                    logger.info('answer status: %s', response.status)

                    if response.status != 200:
                        return None

                    content = await response.read()
        except Exception:
            logger.exception('error while doing request')
            return None

        logger.info('answer received')

        return data_protector_pb2.PluginReportResponse.FromString(content)
示例#7
0
    async def test_has_data(self):
        # prepair data
        message_1_id = await operations.send_message(sender_id=1,
                                                     recipients_ids=[2, 3, 4],
                                                     body='1')
        message_2_id = await operations.send_message(sender_id=2,
                                                     recipients_ids=[3, 4, 5],
                                                     body='2')
        message_3_id = await operations.send_message(sender_id=3,
                                                     recipients_ids=[4, 5, 6],
                                                     body='3')
        message_4_id = await operations.send_message(sender_id=4,
                                                     recipients_ids=[2],
                                                     body='4')

        messages_ids = [message_1_id, message_2_id, message_3_id, message_4_id]

        for message_id, account_id in [(messages_ids[0], 1),
                                       (messages_ids[0], 2),
                                       (messages_ids[0], 3),
                                       (messages_ids[0], 4),
                                       (messages_ids[1], 2),
                                       (messages_ids[2], 4),
                                       (messages_ids[2], 5),
                                       (messages_ids[2], 6),
                                       (messages_ids[3], 4),
                                       (messages_ids[3], 2)]:
            await operations.hide_message(account_id, message_id)

        removed_messages_ids = await operations.candidates_to_remove_ids()
        self.assertNotEqual(removed_messages_ids, [])
        await operations.remove_messages(removed_messages_ids)

        messages = []

        test_account_id = 3

        for message_id in messages_ids:
            message = await operations.load_message(test_account_id,
                                                    message_id,
                                                    visibility=None)
            messages.append(message)

        # request data

        secret = helpers.get_config()['custom']['data_protector']['secret']

        request = await self.client.post(
            '/data-protection-collect-data',
            data=data_protector_pb2.PluginReportRequest(
                account_id=str(test_account_id),
                secret=secret).SerializeToString())
        response = await self.check_success(
            request, data_protector_pb2.PluginReportResponse, raw=True)

        self.assertEqual(
            response.result,
            data_protector_pb2.PluginReportResponse.ResultType.Value(
                'SUCCESS'))

        report = s11n.from_json(response.data)

        self.assertCountEqual(
            report,
            [['message', messages[message_index].data_of(test_account_id)]
             for message_index in [1, 2]])