update compliance item format to align with standard event
This commit is contained in:
Родитель
ceb3ac8496
Коммит
37de0fd0d1
|
@ -179,30 +179,6 @@ class MozDefMsg(object):
|
|||
|
||||
amsg.send()
|
||||
|
||||
class MozDefCompliance(MozDefMessage):
|
||||
def validate_log(self):
|
||||
for k in ['target', 'policy', 'check', 'compliance', 'link',
|
||||
'utctimestamp']:
|
||||
if k not in self._sendlog.keys():
|
||||
return False
|
||||
for k in ['level', 'name', 'url']:
|
||||
if k not in self._sendlog['policy'].keys():
|
||||
return False
|
||||
for k in ['description', 'location', 'name', 'test']:
|
||||
if k not in self._sendlog['check'].keys():
|
||||
return False
|
||||
for k in ['type', 'value']:
|
||||
if k not in self._sendlog['check']['test'].keys():
|
||||
return False
|
||||
return True
|
||||
|
||||
def construct(self):
|
||||
self._sendlog = self.log
|
||||
|
||||
def __init__(self, url):
|
||||
MozDefMessage.__init__(self, url)
|
||||
self._msgtype = self.MSGTYPE_COMPLIANCE
|
||||
|
||||
class MozDefVulnerability(MozDefMessage):
|
||||
def validate_log(self):
|
||||
for k in ['utctimestamp', 'description', 'vuln', 'asset',
|
||||
|
@ -318,6 +294,28 @@ class MozDefAssetHint(MozDefEvent):
|
|||
self._msgtype = self.MSGTYPE_ASSETHINT
|
||||
self._category = 'asset_hint'
|
||||
|
||||
class MozDefCompliance(MozDefEvent):
|
||||
def validate_log(self):
|
||||
for k in ['target', 'policy', 'check', 'compliance', 'link',
|
||||
'utctimestamp']:
|
||||
if k not in self.details.keys():
|
||||
return False
|
||||
for k in ['level', 'name', 'url']:
|
||||
if k not in self.details['policy'].keys():
|
||||
return False
|
||||
for k in ['description', 'location', 'name', 'test']:
|
||||
if k not in self.details['check'].keys():
|
||||
return False
|
||||
for k in ['type', 'value']:
|
||||
if k not in self.details['check']['test'].keys():
|
||||
return False
|
||||
return True
|
||||
|
||||
def __init__(self, url):
|
||||
MozDefEvent.__init__(self, url)
|
||||
self._msgtype = self.MSGTYPE_COMPLIANCE
|
||||
self._category = 'complianceitems'
|
||||
|
||||
class MozDefTests(unittest.TestCase):
|
||||
def create_valid_event(self):
|
||||
self.emsg_summary = 'a test event'
|
||||
|
@ -418,10 +416,12 @@ class MozDefTests(unittest.TestCase):
|
|||
|
||||
def testMozdefComplianceValidate(self):
|
||||
m = MozDefCompliance('http://127.0.0.1')
|
||||
self.assertFalse(m.validate())
|
||||
m.summary = 'compliance item'
|
||||
self.assertTrue(m.validate())
|
||||
m.construct()
|
||||
self.assertFalse(m.validate_log())
|
||||
m.log = self.compmsg
|
||||
m.details = self.compmsg
|
||||
m.construct()
|
||||
self.assertTrue(m.validate_log())
|
||||
|
||||
|
@ -440,8 +440,7 @@ class MozDefTests(unittest.TestCase):
|
|||
def testMozdefCompSyslog(self):
|
||||
m = MozDefCompliance('http://127.0.0.1')
|
||||
m.log = self.compmsg
|
||||
with self.assertRaises(MozDefError):
|
||||
m.syslog_convert()
|
||||
self.assertIsNotNone(m.syslog_convert())
|
||||
|
||||
def testAssetHintValidate(self):
|
||||
m = MozDefAssetHint('http://127.0.0.1')
|
||||
|
@ -478,10 +477,10 @@ class MozDefTests(unittest.TestCase):
|
|||
|
||||
def testMozdefCompSyslogSend(self):
|
||||
m = MozDefCompliance('http://127.0.0.1')
|
||||
m.log = self.compmsg
|
||||
m.summary = 'compliance item'
|
||||
m.details = self.compmsg
|
||||
m.set_send_to_syslog(True, only_syslog=True)
|
||||
with self.assertRaises(MozDefError):
|
||||
m.send()
|
||||
m.send()
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
|
Загрузка…
Ссылка в новой задаче