From 63b395ca4b39519ae35f6e3ece7bb361634cbb52 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Sun, 4 Feb 2024 02:45:23 -0500 Subject: [PATCH] Added authNoPriv test cases. --- .../manager/cmdgen/test_usm_sha_none.py | 26 +++++++++++++++++++ .../cmdgen/test_usm_sha_none_wrong_user.py | 24 +++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py create mode 100644 tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py new file mode 100644 index 000000000..d9adfb013 --- /dev/null +++ b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py @@ -0,0 +1,26 @@ +import pytest +from pysnmp.hlapi.asyncio import * + +@pytest.mark.asyncio +async def test_usm_sha_none(): + snmpEngine = SnmpEngine() + authData = UsmUserData( + "usr-sha-none", + "authkey1", + authProtocol=usmHMACSHAAuthProtocol, + ) + errorIndication, errorStatus, errorIndex, varBinds = await getCmd( + snmpEngine, + authData, + UdpTransportTarget(("demo.pysnmp.com", 161), retries=0), + ContextData(), + ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), + ) + + assert errorIndication is None + assert errorStatus == 0 + assert len(varBinds) == 1 + assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysDescr.0" + isinstance(varBinds[0][1], OctetString) + + snmpEngine.transportDispatcher.closeDispatcher() diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py new file mode 100644 index 000000000..4eaf84e4d --- /dev/null +++ b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py @@ -0,0 +1,24 @@ +import pytest +from pysnmp.hlapi.asyncio import * +from pysnmp.proto.errind import UnknownUserName + +@pytest.mark.asyncio +async def test_usm_sha_none_wrong_user(): + snmpEngine = SnmpEngine() + authData = UsmUserData( + "usr-sha-none-not-exist", + "authkey1", + authProtocol=usmHMACSHAAuthProtocol, + ) + errorIndication, errorStatus, errorIndex, varBinds = await getCmd( + snmpEngine, + authData, + UdpTransportTarget(("demo.pysnmp.com", 161), retries=0), + ContextData(), + ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), + ) + + assert isinstance(errorIndication, UnknownUserName) + assert str(errorIndication) == 'Unknown USM user' + + snmpEngine.transportDispatcher.closeDispatcher()