-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_snmp.py
50 lines (41 loc) · 1.85 KB
/
test_snmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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