async def test_bad_credentials(amqp_connection, event_loop): connection = aiormq.Connection(amqp_connection.url.with_password( uuid.uuid4().hex), loop=event_loop) with pytest.raises(aiormq.exceptions.ProbableAuthenticationError): await connection.connect()
async def test_ssl_context(): url = AMQP_URL.with_scheme("amqps") context = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=cert_path("ca.pem")) context.load_cert_chain(cert_path("client.pem"), cert_path("client.key")) context.check_hostname = False connection = aiormq.Connection(url, context=context) await connection.connect() await connection.close()
async def test_conncetion_reject(event_loop): with pytest.raises(ConnectionError): await aiormq.connect("amqp://*****:*****@127.0.0.1:59999/", loop=event_loop) connection = aiormq.Connection("amqp://*****:*****@127.0.0.1:59999/", loop=event_loop) with pytest.raises(ConnectionError): await event_loop.create_task(connection.connect())
async def test_auth_plain(amqp_connection, event_loop): auth = PlainAuth(amqp_connection).marshal() assert auth == PlainAuth(amqp_connection).marshal() auth_parts = auth.split(b"\x00") assert auth_parts == [b'', b'guest', b'guest'] connection = aiormq.Connection( amqp_connection.url.with_user('foo').with_password('bar'), loop=event_loop) auth = PlainAuth(connection).marshal() auth_parts = auth.split(b"\x00") assert auth_parts == [b'', b'foo', b'bar'] auth = PlainAuth(connection) auth.value = b'boo' assert auth.marshal() == b'boo'
async def test_auth_plain(amqp_connection, loop): auth = PlainAuth(amqp_connection).marshal() assert auth == PlainAuth(amqp_connection).marshal() auth_parts = auth.split("\x00") assert auth_parts == ["", "guest", "guest"] connection = aiormq.Connection( amqp_connection.url.with_user("foo").with_password("bar"), loop=loop, ) auth = PlainAuth(connection).marshal() auth_parts = auth.split("\x00") assert auth_parts == ["", "foo", "bar"] auth = PlainAuth(connection) auth.value = "boo" assert auth.marshal() == "boo"
async def test_connection_urls_vhosts(url, vhost, event_loop): assert aiormq.Connection(url, loop=event_loop).vhost == vhost
async def test_ssl_verification_fails_without_trusted_ca(): url = AMQP_URL.with_scheme("amqps") with pytest.raises(ConnectionError, match=".*CERTIFICATE_VERIFY_FAILED.*"): connection = aiormq.Connection(url) await connection.connect()
async def test_heartbeat_not_int(loop): url = AMQP_URL.update_query(heartbeat="None") connection = aiormq.Connection(url, loop=loop) await connection.connect() assert connection.connection_tune.heartbeat == 0 await connection.close()
async def test_heartbeat_under_range(loop): url = AMQP_URL.update_query(heartbeat=-1) connection = aiormq.Connection(url, loop=loop) await connection.connect() assert connection.connection_tune.heartbeat == 0 await connection.close()
async def test_heartbeat_default(loop): connection = aiormq.Connection(AMQP_URL, loop=loop) await connection.connect() assert connection.connection_tune.heartbeat == 60 await connection.close()
async def test_timeout_1000(loop): url = AMQP_URL.update_query(timeout=1000) connection = aiormq.Connection(url, loop=loop) await connection.connect() assert connection.timeout await connection.close()
async def test_timeout_default(loop): connection = aiormq.Connection(AMQP_URL, loop=loop) await connection.connect() assert connection.timeout == 60 await connection.close()