Beispiel #1
0
 def test_auth_with_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     with self.assertRaises(VkTwoFactorCodeNeeded):
         yield from s.authorize()
     s.close()
Beispiel #2
0
 def test_auth_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     yield from s.authorize()
     s.close()
     self.assertIsNotNone(s.access_token)
Beispiel #3
0
    async def test_auth_process_captcha_without(self):
        s = ImplicitSession(login='******', password='******', app_id='123')
        s.REQUEST_URL = 'https://{}/method/'.format(self.base_url)
        s.AUTH_URL = 'https://{}/authorize'.format(self.base_url)

        await s.authorize()
        await s.close()
Beispiel #4
0
 def test_auth_with_invalid_password(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password='******',
                         app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Beispiel #5
0
 def test_auth_process_captcha_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     for i in range(10):
         with self.assertRaises(VkCaptchaNeeded):
             yield from s.authorize()
     s.close()
Beispiel #6
0
    async def test_auth_with_empty_data(self):
        s = ImplicitSession(login='', password='', app_id='')
        s.REQUEST_URL = 'https://{}/method/'.format(self.base_url)
        s.AUTH_URL = 'https://{}/authorize'.format(self.base_url)

        with self.assertRaises(VkAuthError):
            await s.authorize()
        await s.close()
Beispiel #7
0
async def test_implicit_session_auth_process_captcha_without(vk_server):
    url = f'http://{vk_server.host}:{vk_server.port}'
    s = ImplicitSession(login='******', password='******', app_id='123')
    s.REQUEST_URL = f'{url}/method/'
    s.AUTH_URL = f'{url}/authorize'

    await s.authorize()
    await s.close()
Beispiel #8
0
    async def init_vk(self):
        vk_session = None
        if self.config['IMPLICIT']:
            vk_session = ImplicitSession(self.config['USER_LOGIN'], self.config['USER_PASSWORD'],
                                         self.config['APP_ID'], ['messages', 'wall'])
        else:
            # TODO(spark): implement TokenSession
            pass

        self.logger.info('Auth in VK...')
        await vk_session.authorize()

        self.vk_api = vk_api = API(vk_session)
        vk_lp = LongPoll(vk_api, mode=2)

        while self.running:
            # Main working loop
            response = await vk_lp.wait()

            for action in response['updates']:
                if action[0] is 4:
                    message_id = action[1]
                    sender = action[3]
                    sender_id = sender
                    message = str(action[6])
                    attachment = action[7]
                    self.logger.debug('Got message: {}'.format(message))

                    if sender > 2000000000:
                        # Groupchat
                        sender_id = int(attachment['from'])

                    f_flag = False
                    for f in self.filters:
                        f_res = await f(sender, sender_id, message, attachment)
                        if f_res is False:
                            f_flag = True
                            continue

                    if f_flag:
                        continue

                    if message.startswith(self.config['COMMAND_SYMBOL']) and message[1] is not ' ':
                        message = message[1:]
                        flag = False
                        for c in self.commands:
                            if message.startswith(c) and not flag:
                                flag = True
                                command = message.split(' ')[0]
                                if command in self.admin_commands and sender_id not in self.config['ADMINS']:
                                    await self.send_message(sender, 'Access denied')
                                else:
                                    await self.commands[command](sender, sender_id, message, attachment)
                        if flag is False:
                            await self.send_message(sender, 'Command not found')

        vk_session.close()
Beispiel #9
0
async def test_implicit_session_auth_with_empty_data(vk_server):
    url = f'http://{vk_server.host}:{vk_server.port}'
    s = ImplicitSession(login='', password='', app_id='')
    s.REQUEST_URL = f'{url}/method/'
    s.AUTH_URL = f'{url}/authorize'

    with pytest.raises(VkAuthError):
        await s.authorize()
    await s.close()
Beispiel #10
0
 def test_auth_with_app_id(self):
     s = ImplicitSession(login='', password='', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Beispiel #11
0
 def test_auth_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     yield from s.authorize()
     s.close()
     self.assertIsNotNone(s.access_token)
Beispiel #12
0
 def test_auth_with_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     with self.assertRaises(VkTwoFactorCodeNeeded):
         yield from s.authorize()
     s.close()
Beispiel #13
0
 def test_auth_with_invalid_password(self):
     s = ImplicitSession(login=USER_LOGIN, password='******', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Beispiel #14
0
 def test_auth_with_app_id(self):
     s = ImplicitSession(login='', password='', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Beispiel #15
0
 def test_auth_process_captcha_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     for i in range(10):
         with self.assertRaises(VkCaptchaNeeded):
             yield from s.authorize()
     s.close()