forked from etingof/pysnmp
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make LCD reconfigure V3 users when auth data changes.
`CommandGeneratorLcdConfigurator` configures auth data and caches based on `(username, security engine id)`. If the authentication data is changed, such as via `usmUserAuthKeyChange`, the cache is not updated because neither the username nor engine ID changed. Despite new data being passed in, this results in the old data being used and a "Wrong SNMP PDU digest" error indication being returned. Change the LCD to detect a changed authKey, authProtocol, privKey, or privProtocol and reconfigure the V3 user as appropriate.
- Loading branch information
1 parent
71b7439
commit 8df333e
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
tests/hlapi/asyncio/manager/cmdgen/test_lcd_configurator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from unittest import mock | ||
|
||
from pysnmp import hlapi | ||
from pysnmp.hlapi.asyncio.cmdgen import CommandGeneratorLcdConfigurator | ||
|
||
|
||
@mock.patch('pysnmp.entity.config.addV3User') | ||
@mock.patch('pysnmp.entity.config.delV3User') | ||
def test_usm_auth_cache_cleared(delV3User, addV3User): | ||
""" | ||
Ensure auth cache is cleared when auth data is changed. | ||
""" | ||
snmpEngine = hlapi.SnmpEngine() | ||
transportTarget = hlapi.UdpTransportTarget('198.51.100.1') | ||
|
||
authDataValues = { | ||
'userName': 'username', | ||
'authKey': 'authkey1', | ||
'authProtocol': hlapi.usmHMACMD5AuthProtocol, | ||
'privKey': 'privkey1', | ||
'privProtocol': hlapi.usmAesCfb128Protocol, | ||
} | ||
|
||
lcd = CommandGeneratorLcdConfigurator() | ||
initialAuthData = hlapi.UsmUserData(**authDataValues) | ||
lcd.configure(snmpEngine, initialAuthData, transportTarget) | ||
addV3User.assert_called_with( | ||
snmpEngine, | ||
initialAuthData.userName, | ||
initialAuthData.authProtocol, | ||
initialAuthData.authKey, | ||
initialAuthData.privProtocol, | ||
initialAuthData.privKey, | ||
securityEngineId=initialAuthData.securityEngineId, | ||
securityName=initialAuthData.securityName, | ||
authKeyType=initialAuthData.authKeyType, | ||
privKeyType=initialAuthData.privKeyType, | ||
) | ||
|
||
# Ensure we do not add/delete if nothing changes | ||
addV3User.reset_mock() | ||
lcd.configure(snmpEngine, initialAuthData, transportTarget) | ||
addV3User.assert_not_called() | ||
delV3User.assert_not_called() | ||
|
||
changeAuthValues = { | ||
'authKey': 'authKey2', | ||
'privProtocol': hlapi.usmDESPrivProtocol, | ||
'authProtocol': hlapi.usmHMACSHAAuthProtocol, | ||
'privKey': 'privKey2', | ||
} | ||
|
||
for field, value in changeAuthValues.items(): | ||
addV3User.reset_mock() | ||
delV3User.reset_mock() | ||
|
||
authDataValues[field] = value | ||
authData = hlapi.UsmUserData(**authDataValues) | ||
lcd.configure(snmpEngine, authData, transportTarget) | ||
|
||
delV3User.assert_called_with( | ||
snmpEngine, | ||
authData.userName, | ||
authData.securityEngineId, | ||
) | ||
|
||
addV3User.assert_called_with( | ||
snmpEngine, | ||
authData.userName, | ||
authData.authProtocol, | ||
authData.authKey, | ||
authData.privProtocol, | ||
authData.privKey, | ||
securityEngineId=authData.securityEngineId, | ||
securityName=authData.securityName, | ||
authKeyType=authData.authKeyType, | ||
privKeyType=authData.privKeyType, | ||
) |