зеркало из https://github.com/mozilla/MozDef.git
Eis 2329 (#1660)
* Write some new test cases that break the current implementation of the ldap_fixup email parser * Tweak tests to break as expected * Fix breaking test cases * Add example from input that caused failure * Split actor strings on spaces and on commas
This commit is contained in:
Родитель
aa602f4763
Коммит
a8a1663452
|
@ -57,10 +57,17 @@ def _parse_email_from_actor(actor_str: str) -> types.Optional[str]:
|
|||
`"mail=username@mozilla.com,o=com,dc=mozilla"`
|
||||
'''
|
||||
|
||||
mapping = dict([
|
||||
pair.split('=')
|
||||
for pair in actor_str.split(',')
|
||||
if '=' in pair
|
||||
])
|
||||
mapping = {}
|
||||
|
||||
pairs = []
|
||||
|
||||
for section in actor_str.split(' '):
|
||||
pairs.extend(section.split(','))
|
||||
|
||||
for item in pairs:
|
||||
pair = item.split('=')
|
||||
|
||||
if len(pair) == 2:
|
||||
mapping[pair[0]] = pair[1]
|
||||
|
||||
return mapping.get('mail')
|
||||
|
|
|
@ -39,6 +39,39 @@ class TestLdapFixupPlugin():
|
|||
assert retmessage == expected_message
|
||||
assert retmeta == {}
|
||||
|
||||
def test_ldap_fixup_complex_actor_format(self):
|
||||
msg = {
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
'hostname': 'random.host.com',
|
||||
'category': 'ldap',
|
||||
'details': {
|
||||
'tls': 'true',
|
||||
'authenticated': 'true',
|
||||
'actor': 'dc=mozilla mail=tester@mozilla.com,o=com,dc=mozilla '
|
||||
'IP=123.45.67.89:46740 conn=180255',
|
||||
}
|
||||
}
|
||||
|
||||
expected = {
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
'hostname': 'random.host.com',
|
||||
'category': 'ldap',
|
||||
'source': 'ldap',
|
||||
'details': {
|
||||
'tls_encrypted': 'true',
|
||||
'authenticated': 'true',
|
||||
'email': 'tester@mozilla.com',
|
||||
'username': 'tester',
|
||||
'actor': 'dc=mozilla mail=tester@mozilla.com,o=com,dc=mozilla '
|
||||
'IP=123.45.67.89:46740 conn=180255',
|
||||
}
|
||||
}
|
||||
|
||||
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
||||
|
||||
assert retmessage == expected
|
||||
assert retmeta == {}
|
||||
|
||||
def test_ldap_fixup_missing_actor(self):
|
||||
msg = {
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
|
@ -54,3 +87,43 @@ class TestLdapFixupPlugin():
|
|||
|
||||
assert retmessage['details'].get('email') is None
|
||||
assert retmessage['details'].get('username') is None
|
||||
|
||||
def test_ldap_fixup_poorly_formatted_actor(self):
|
||||
msgs = [
|
||||
{
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
'hostname': 'random.host.com',
|
||||
'category': 'ldap',
|
||||
'details': {
|
||||
'tls': 'true',
|
||||
'authenticated': 'true',
|
||||
'actor': 'o=com=extra,mail=tester@mozilla.com=extra2',
|
||||
}
|
||||
},
|
||||
{
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
'hostname': 'random.host.com',
|
||||
'category': 'ldap',
|
||||
'details': {
|
||||
'tls': 'true',
|
||||
'authenticated': 'true',
|
||||
'actor': 'o=com,',
|
||||
}
|
||||
},
|
||||
{
|
||||
'summary': 'LDAP-Humanizer:45582:1.1.1.1',
|
||||
'hostname': 'random.host.com',
|
||||
'category': 'ldap',
|
||||
'details': {
|
||||
'tls': 'true',
|
||||
'authenticated': 'true',
|
||||
'actor': 'o,mail',
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
for msg in msgs:
|
||||
(retmessage, retmeta) = self.plugin.onMessage(msg, {})
|
||||
|
||||
assert retmessage['details'].get('email') is None
|
||||
assert retmessage['details'].get('username') is None
|
||||
|
|
Загрузка…
Ссылка в новой задаче