|  | 
| 24 | 24 | import neo4j | 
| 25 | 25 | from neo4j._async.io._bolt4 import AsyncBolt4x0 | 
| 26 | 26 | from neo4j._conf import PoolConfig | 
|  | 27 | +from neo4j._meta import USER_AGENT | 
| 27 | 28 | from neo4j.exceptions import ConfigurationError | 
| 28 | 29 | 
 | 
| 29 | 30 | from ...._async_compat import mark_async_test | 
| @@ -345,3 +346,50 @@ async def test_hello_does_not_support_notification_filters( | 
| 345 | 346 |     ) | 
| 346 | 347 |     with pytest.raises(ConfigurationError, match="Notification filtering"): | 
| 347 | 348 |         await connection.hello() | 
|  | 349 | + | 
|  | 350 | + | 
|  | 351 | +@mark_async_test | 
|  | 352 | +@pytest.mark.parametrize( | 
|  | 353 | +    "user_agent", (None, "test user agent", "", USER_AGENT) | 
|  | 354 | +) | 
|  | 355 | +async def test_user_agent(fake_socket_pair, user_agent): | 
|  | 356 | +    address = neo4j.Address(("127.0.0.1", 7687)) | 
|  | 357 | +    sockets = fake_socket_pair(address, | 
|  | 358 | +                               packer_cls=AsyncBolt4x0.PACKER_CLS, | 
|  | 359 | +                               unpacker_cls=AsyncBolt4x0.UNPACKER_CLS) | 
|  | 360 | +    await sockets.server.send_message(b"\x70", {"server": "Neo4j/1.2.3"}) | 
|  | 361 | +    await sockets.server.send_message(b"\x70", {}) | 
|  | 362 | +    max_connection_lifetime = 0 | 
|  | 363 | +    connection = AsyncBolt4x0( | 
|  | 364 | +        address, sockets.client, max_connection_lifetime, user_agent=user_agent | 
|  | 365 | +    ) | 
|  | 366 | +    await connection.hello() | 
|  | 367 | + | 
|  | 368 | +    tag, fields = await sockets.server.pop_message() | 
|  | 369 | +    extra = fields[0] | 
|  | 370 | +    if not user_agent: | 
|  | 371 | +        assert extra["user_agent"] == USER_AGENT | 
|  | 372 | +    else: | 
|  | 373 | +        assert extra["user_agent"] == user_agent | 
|  | 374 | + | 
|  | 375 | + | 
|  | 376 | +@mark_async_test | 
|  | 377 | +@pytest.mark.parametrize( | 
|  | 378 | +    "user_agent", (None, "test user agent", "", USER_AGENT) | 
|  | 379 | +) | 
|  | 380 | +async def test_does_not_send_bolt_agent(fake_socket_pair, user_agent): | 
|  | 381 | +    address = neo4j.Address(("127.0.0.1", 7687)) | 
|  | 382 | +    sockets = fake_socket_pair(address, | 
|  | 383 | +                               packer_cls=AsyncBolt4x0.PACKER_CLS, | 
|  | 384 | +                               unpacker_cls=AsyncBolt4x0.UNPACKER_CLS) | 
|  | 385 | +    await sockets.server.send_message(b"\x70", {"server": "Neo4j/1.2.3"}) | 
|  | 386 | +    await sockets.server.send_message(b"\x70", {}) | 
|  | 387 | +    max_connection_lifetime = 0 | 
|  | 388 | +    connection = AsyncBolt4x0( | 
|  | 389 | +        address, sockets.client, max_connection_lifetime, user_agent=user_agent | 
|  | 390 | +    ) | 
|  | 391 | +    await connection.hello() | 
|  | 392 | + | 
|  | 393 | +    tag, fields = await sockets.server.pop_message() | 
|  | 394 | +    extra = fields[0] | 
|  | 395 | +    assert "bolt_agent" not in extra | 
0 commit comments