Skip to content

Commit

Permalink
Added more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Feb 4, 2024
1 parent ccfd8c5 commit 806132b
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 72 deletions.
21 changes: 20 additions & 1 deletion tests/hlapi/asyncio/manager/cmdgen/test_usm_none_none.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pysnmp.hlapi.asyncio import *
from pysnmp.proto.errind import UnknownUserName

@pytest.mark.asyncio
async def test_usm_no_auth_no_priv():
Expand All @@ -19,4 +20,22 @@ async def test_usm_no_auth_no_priv():
assert errorStatus == 0
assert len(varBinds) == 1
assert varBinds[0][0].prettyPrint() == "SNMPv2-MIB::sysDescr.0"
isinstance(varBinds[0][1], OctetString)
isinstance(varBinds[0][1], OctetString)

@pytest.mark.asyncio
async def test_usm_no_auth_no_priv_wrong_user():
snmpEngine = SnmpEngine()
authData = UsmUserData(
"usr-none-none-not-exist"
)
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()

This file was deleted.

70 changes: 70 additions & 0 deletions tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_aes128.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pysnmp.hlapi.asyncio import *
from pysnmp.proto.errind import RequestTimedOut, UnknownUserName

@pytest.mark.asyncio
async def test_usm_sha_aes128():
Expand All @@ -26,3 +27,72 @@ async def test_usm_sha_aes128():
isinstance(varBinds[0][1], OctetString)

snmpEngine.transportDispatcher.closeDispatcher()

@pytest.mark.asyncio
async def test_usm_sha_aes128_wrong_auth():
snmpEngine = SnmpEngine()
authData = UsmUserData(
"usr-sha-aes",
"authkey1",
"privkey1",
authProtocol=usmHMACMD5AuthProtocol, # wrongly use usmHMACMD5AuthProtocol
privProtocol=usmAesCfb128Protocol
)
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, RequestTimedOut)
assert str(errorIndication) == 'No SNMP response received before timeout'

snmpEngine.transportDispatcher.closeDispatcher()

@pytest.mark.asyncio
async def test_usm_sha_aes128_wrong_priv():
snmpEngine = SnmpEngine()
authData = UsmUserData(
"usr-sha-aes",
"authkey1",
"privkey1",
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmDESPrivProtocol, # wrongly use usmDESPrivProtocol
)
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, RequestTimedOut)
assert str(errorIndication) == 'No SNMP response received before timeout'

snmpEngine.transportDispatcher.closeDispatcher()

@pytest.mark.asyncio
async def test_usm_sha_aes128_wrong_user():
snmpEngine = SnmpEngine()
authData = UsmUserData(
"usr-sha-aes-not-exist",
"authkey1",
"privkey1",
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmAesCfb128Protocol,
)
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()

This file was deleted.

22 changes: 22 additions & 0 deletions tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from pysnmp.hlapi.asyncio import *
from pysnmp.proto.errind import UnknownUserName

@pytest.mark.asyncio
async def test_usm_sha_none():
Expand All @@ -24,3 +25,24 @@ async def test_usm_sha_none():
isinstance(varBinds[0][1], OctetString)

snmpEngine.transportDispatcher.closeDispatcher()

@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()
24 changes: 0 additions & 24 deletions tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none_wrong_user.py

This file was deleted.

0 comments on commit 806132b

Please sign in to comment.