Skip to content

Commit

Permalink
Added authNoPriv test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Feb 4, 2024
1 parent bd4070c commit 63b395c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 24 additions & 0 deletions tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 63b395c

Please sign in to comment.