-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial unit tests for the new XS SNMP config filters (#53)
* CP-44440: '/etc/snmp/snmp.xs.conf' format changed (changed from key-value 'x = aaa' to JSON '"x": "aaa",') * CP-46759: Add a Test case to collect SNMP files in Server Status Report * CP-46759: Fixup Test case on testing the SNMP functions in bugtool. TODO: The actual collection and filtering of files is not tested yet! The unit test checks filtering the inputs using the individual funcs. From an actual bugtool run, with this commit, we only test the non-existing files case. Co-authored-by: Bengang Yuan <[email protected]> Signed-off-by: Bernhard Kaindl <[email protected]>
- Loading branch information
Showing
7 changed files
with
113 additions
and
14 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
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
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
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
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
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,50 @@ | ||
"""Unit tests for the bugtool SNMP filter functions: filter_snmp.*_conf()""" | ||
|
||
|
||
def test_filter_snmp_xs_conf(bugtool, builtins, mocker): | ||
"""Assert that filter_snmp_xs_conf() replaces sensitive strings""" | ||
|
||
snmp_xs_conf_input = """ | ||
"community": "SECRET", | ||
"authentication_key": "SECRET", | ||
"privacy_key": "SECRET", | ||
""" | ||
snmp_xs_conf_output = """ | ||
"community": "REMOVED", | ||
"authentication_key": "REMOVED", | ||
"privacy_key": "REMOVED", | ||
""" | ||
mocker.patch(builtins + ".open", mocker.mock_open(read_data=snmp_xs_conf_input)) | ||
assert bugtool.filter_snmp_xs_conf("_") == snmp_xs_conf_output | ||
|
||
|
||
def test_filter_snmpd_xs_conf(bugtool, builtins, mocker): | ||
"""Assert that filter_snmpd_xs_conf() replaces sensitive strings""" | ||
|
||
snmpd_xs_conf_input = "com2sec notConfigUser default SECRET" | ||
snmpd_xs_conf_output = "com2sec notConfigUser default REMOVED" | ||
mocker.patch(builtins + ".open", mocker.mock_open(read_data=snmpd_xs_conf_input)) | ||
assert bugtool.filter_snmpd_xs_conf("_") == snmpd_xs_conf_output | ||
|
||
|
||
def test_filter_snmpd_conf(bugtool, builtins, mocker): | ||
"""Assert that filter_snmpd_conf() replaces sensitive strings""" | ||
|
||
snmpd_conf_input = ( | ||
"usmUser 1 3 0x80001f8880f369b576d8b2a46500000000 0x7872746d69612d30372d3035 " | ||
+ "0x7872746d69612d30372d3035 NULL .1.3.6.1.6.3.10.1.1.3 " | ||
+ "SECRET " | ||
+ ".1.3.6.1.6.3.10.1.2.2 " | ||
+ "SECRET " | ||
+ "0x" | ||
) | ||
snmpd_conf_output = ( | ||
"usmUser 1 3 0x80001f8880f369b576d8b2a46500000000 0x7872746d69612d30372d3035 " | ||
+ "0x7872746d69612d30372d3035 NULL .1.3.6.1.6.3.10.1.1.3 " | ||
+ "REMOVED " | ||
+ ".1.3.6.1.6.3.10.1.2.2 " | ||
+ "REMOVED " | ||
+ "0x" | ||
) | ||
mocker.patch(builtins + ".open", mocker.mock_open(read_data=snmpd_conf_input)) | ||
assert bugtool.filter_snmpd_conf("_") == snmpd_conf_output |
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