Esempio n. 1
0
    async def test_message(self):
        conn = await create_connection(host=self.host, port=self.port,
                                       loop=self.loop)

        resp = await conn.identify(feature_negotiation=True)
        resp = json.loads(_convert_to_str(resp))
        if resp.get('auth_required') is True:
            await conn.auth(self.auth_secret)

        ok = await conn.execute(b'PUB', self.topic, data=b'boom')
        self.assertEqual(ok, b'OK')
        res = await conn.execute(b'SUB', self.topic,  'boom')
        self.assertEqual(res, b"OK")
        await conn.execute(b'RDY', 1)

        msg = await conn._queue.get()
        self.assertEqual(msg.processed, False)

        await msg.touch()
        self.assertEqual(msg.processed, False)
        await msg.req(1)
        self.assertEqual(msg.processed, True)
        await conn.execute(b'RDY', 1)
        new_msg = await conn._queue.get()
        res = await new_msg.fin()
        self.assertEqual(res, b"OK")
        self.assertEqual(msg.processed, True)

        await conn.execute(b'CLS')
        conn.close()
 async def _is_auth_required(self):
     conn = await create_connection(host=self.host,
                                    port=self.port,
                                    loop=self.loop)
     res = await conn.identify(feature_negotiation=True)
     res = json.loads(_convert_to_str(res))
     auth_required = res.get('auth_required') or False
     conn.close()
     return auth_required
Esempio n. 3
0
 async def test_auth_fail_needs_tls(self):
     host, port = '127.0.0.1', 4150
     conn = await create_connection(host=host, port=port, loop=self.loop)
     res = await conn.identify(feature_negotiation=True)
     res = json.loads(_convert_to_str(res))
     if res.get('auth_required') is True:
         with self.assertRaises(NSQAuthFailed):
             await conn.auth('test_tls')
         conn.close()
     else:
         conn.close()
         self.skipTest("no auth enabled")
Esempio n. 4
0
 async def test_auth_fail_no_sub(self):
     host, port = '127.0.0.1', 4150
     conn = await create_connection(host=host, port=port, loop=self.loop)
     res = await conn.identify(feature_negotiation=True)
     res = json.loads(_convert_to_str(res))
     if res.get('auth_required') is True:
         await conn.auth('test_no_sub')
         with self.assertRaises(NSQUnauthorized) as cm:
             await self._pub_sub_rdy_fin(conn)
         self.assertIn('AUTH failed for SUB', repr(cm.exception))
         conn.close()
     else:
         conn.close()
         self.skipTest("no auth enabled")
Esempio n. 5
0
    async def test_deflate(self):
        conn = await create_connection(host=self.host, port=self.port,
                                       loop=self.loop)

        config = {'feature_negotiation': True, 'tls_v1': False,
                  'snappy': False, 'deflate': True
                  }
        self.assertIsInstance(conn._parser, Reader)

        nego_res = await conn.identify(**config)
        print(nego_res)
        self.assertIsInstance(conn._parser, DeflateReader)

        nego_res = json.loads(_convert_to_str(nego_res))
        if nego_res.get('auth_required') is True:
            await conn.auth(self.auth_secret)

        await self._pub_sub_rdy_fin(conn)
        conn.close()