Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
remove empty start time keys, or assume value (#1605)
Browse files Browse the repository at this point in the history
* remove empty start time keys, or assume value

* adding new test case for multiple empty start fields

* updating summary of test

* updating zoom_fixup.py to correct parsing errors.
  • Loading branch information
Phrozyn committed Apr 23, 2020
1 parent 3b5b6a2 commit 04bd718
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 12 deletions.
22 changes: 17 additions & 5 deletions mq/plugins/zoom_fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,23 @@ def onMessage(self, message, metadata):
# JMESPath likes to silently return a None object
if mappedvalue is not None:
newmessage['details'][key] = mappedvalue
# Some zoom messages don't contain details.start_time
# so we set it to original start time
if key_exists('details.start_time', newmessage) and key_exists('details.original_sched_start_time', newmessage):
if newmessage['details']['start_time'] == '':
newmessage['details']['start_time'] = newmessage['details']['original_sched_start_time']
# Some zoom messages don't contain values within details.payload.object.start_time or details.payload.old_object.start_time.
# so we set it to original start time, if there is no time data, we remove the key from the message.
if key_exists('details.payload.object.start_time', message):
if message['details']['payload']['object']['start_time'] != '':
newmessage['details']['start_time'] = message['details']['payload']['object']['start_time']
else:
del newmessage['details']['start_time']
if key_exists('details.payload.old_object.start_time', message):
if message['details']['payload']['old_object']['start_time'] != '':
newmessage['details']['original_sched_start_time'] = message['details']['payload']['old_object']['start_time']
else:
del newmessage['details']['original_sched_start_time']
# Duration can exist in details.payload.object and details.payload.old_object, let's ensure we are capturing these correctly for updated meetings.
if key_exists('details.payload.object.duration', message):
newmessage['details']['duration'] = message['details']['payload']['object']['duration']
if key_exists('details.payload.old_object.duration', message):
newmessage['details']['original_sched_duration'] = message['details']['payload']['old_object']['duration']

else:
newmessage = None
Expand Down
67 changes: 60 additions & 7 deletions tests/mq/plugins/test_zoom_fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_summary_user_name(self):
'uuid': 'aodij/OWIE9241048=',
"participant": {
'user_id': '12039103',
'user_name': 'Random User',
'user_name': 'Random User'
}
}
}
Expand All @@ -98,7 +98,7 @@ def test_summary_user_name(self):
'type': '4',
'uuid': 'aodij/OWIE9241048=',
'participant_username': 'Random User',
'participant_user_id': '12039103',
'participant_user_id': '12039103'
}
}
assert retmessage == expected_message
Expand All @@ -122,7 +122,7 @@ def test_summary_operator(self):
'object': {
'id': '123456789',
'type': '2',
'uuid': 'aodij/OWIE9241048=',
'uuid': 'aodij/OWIE9241048='
}
}
}
Expand All @@ -145,7 +145,7 @@ def test_summary_operator(self):
'type': '2',
'user_id': '12o3i-294jo24jad',
'username': 'randomuser@randomco.com',
'uuid': 'aodij/OWIE9241048=',
'uuid': 'aodij/OWIE9241048='
}
}
assert retmessage == expected_message
Expand Down Expand Up @@ -299,14 +299,15 @@ def test_start_time_empty_string(self):
'payload': {
'account_id': 'ABCDEFG123456',
'object': {
'account_id': 'HIJKLMN123456',
'account_id': 'ABCDEFG123456',
'id': '123456789',
'type': '2',
'uuid': 'aodij/OWIE9241048=',
'start_time': ''
},
'old_object': {
'start_time': '2020-02-11T20:25:30Z'
'start_time': '2020-02-11T20:25:30Z',
'duration': '60'
}
}
}
Expand All @@ -329,7 +330,59 @@ def test_start_time_empty_string(self):
'type': '2',
'uuid': 'aodij/OWIE9241048=',
'original_sched_start_time': '2020-02-11T20:25:30Z',
'start_time': '2020-02-11T20:25:30Z',
'original_sched_duration': '60'
}
}
assert retmessage == expected_message
assert retmeta == {}

def test_empty_original_sched_start_time_strings(self):
msg = {
'summary': 'zoom_event',
'source': 'api_aws_lambda',
'hostname': 'zoom_host',
'severity': 'info',
'eventsource': 'MozDef-EF-zoom',
'tags': ['zoom', 'MozDef-EF-zoom-dev'],
'category': 'zoom',
'details': {
'event': 'meeting.updated',
'payload': {
'account_id': 'ABCDEFG123456',
'object': {
'account_id': 'ABCDEFG123456',
'id': '123456789',
'type': '2',
'uuid': 'aodij/OWIE9241048=',
'start_time': ''
},
'old_object': {
'id': '123456789',
'type': '2',
'start_time': '',
'duration': '60'
}
}
}
}
(retmessage, retmeta) = self.plugin.onMessage(msg, {})

expected_message = {
'summary': 'zoom: meeting.updated',
'category': 'zoom',
'source': 'api_aws_lambda',
'hostname': 'zoom_host',
'severity': 'info',
'eventsource': 'MozDef-EF-zoom',
'tags': ['zoom', 'MozDef-EF-zoom-dev'],
'processname': 'zoom_webhook_api',
'details': {
'account_id': 'ABCDEFG123456',
'event': 'meeting.updated',
'id': '123456789',
'type': '2',
'uuid': 'aodij/OWIE9241048=',
'original_sched_duration': '60'
}
}
assert retmessage == expected_message
Expand Down

0 comments on commit 04bd718

Please sign in to comment.