From 39441de2829acda774fa7f562ebfa78805683742 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Fri, 4 Oct 2024 20:18:28 -0400 Subject: [PATCH] Added a new test case. --- .../asyncio/agent/ntforg/test_v3-trap.py | 19 +++++++++++++++++++ tests/manager_context.py | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/hlapi/v3arch/asyncio/agent/ntforg/test_v3-trap.py b/tests/hlapi/v3arch/asyncio/agent/ntforg/test_v3-trap.py index e5caa93f..6e84d452 100644 --- a/tests/hlapi/v3arch/asyncio/agent/ntforg/test_v3-trap.py +++ b/tests/hlapi/v3arch/asyncio/agent/ntforg/test_v3-trap.py @@ -25,6 +25,25 @@ async def test_send_v3_trap_notification(): assert message_count == [1] +@pytest.mark.asyncio +async def test_send_v3_trap_notification_none(): + async with ManagerContextManager() as (_, message_count): + # snmptrap -v3 -l noAuthNoPriv -u usr-none-none -e 8000000001020305 localhost:MANAGER_PORT 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s "my system" + snmpEngine = SnmpEngine(OctetString(hexValue="8000000001020305")) + errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( + snmpEngine, + UsmUserData("usr-none-none", None, None), + await UdpTransportTarget.create(("localhost", MANAGER_PORT)), + ContextData(), + "trap", + NotificationType(ObjectIdentity("IF-MIB", "linkDown")), + ) + + snmpEngine.closeDispatcher() + await asyncio.sleep(1) + assert message_count == [1] + + @pytest.mark.asyncio async def test_send_v3_trap_notification_invalid_user(): async with ManagerContextManager() as (_, message_count): diff --git a/tests/manager_context.py b/tests/manager_context.py index 3b34b8b2..67432d82 100644 --- a/tests/manager_context.py +++ b/tests/manager_context.py @@ -58,6 +58,16 @@ async def start_manager( securityEngineId=v2c.OctetString(hexValue="8000000001020304"), ) + # user: usr-none-none, auth: NONE, priv: NONE + # this USM entry is used for TRAP receiving purposes + config.addV3User( + snmpEngine, + "usr-none-none", + config.USM_AUTH_NONE, + config.USM_PRIV_NONE, + securityEngineId=v2c.OctetString(hexValue="8000000001020305"), + ) + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(