From 77eaa86225dda32e4e4d8fa12ddc0a8e507d1e19 Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 5 Aug 2022 14:41:00 +0200 Subject: [PATCH 1/4] fix: [speculative fix] for event publishing timing issues --- app/Model/Event.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Model/Event.php b/app/Model/Event.php index 96016801f..8c92c6247 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -4279,7 +4279,6 @@ class Event extends AppModel $jobId ); } - return $this->publish($id, $passAlong); } @@ -4324,6 +4323,7 @@ class Event extends AppModel 'recursive' => -1, 'conditions' => array('Event.id' => $id) )); + if (empty($event)) { return false; } @@ -4339,6 +4339,10 @@ class Event extends AppModel 'order' => ['id ASC'] ]); } + $fieldList = array('published', 'id', 'info', 'publish_timestamp'); + $event['Event']['skip_zmq'] = 1; + $event['Event']['skip_kafka'] = 1; + $this->save($event, array('fieldList' => $fieldList)); $userForPubSub = [ 'id' => 0, 'org_id' => $hostOrg['Org']['id'], @@ -4372,6 +4376,7 @@ class Event extends AppModel $success = $this->executeTrigger('event-publish', $fullEvent[0], $workflowErrors, $logging); if (empty($success)) { $errorMessage = implode(', ', $workflowErrors); + return $errorMessage; } } From a3f0347a45466ef193d9689206b40bcc2f6b8f5a Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 5 Aug 2022 14:44:37 +0200 Subject: [PATCH 2/4] fix: [speculative] fix for the event publishing timing issues --- app/Model/Event.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Model/Event.php b/app/Model/Event.php index 3656d3ff8..e96729a67 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -4300,6 +4300,19 @@ class Event extends AppModel public function publishRouter($id, $passAlong = null, $user) { + $event = $this->find('first', array( + 'recursive' => -1, + 'conditions' => array('Event.id' => $id) + )); + + if (empty($event)) { + return false; + } + $fieldList = array('published', 'id', 'info', 'publish_timestamp'); + $event['Event']['published'] = 1; + $event['Event']['publish_timestamp'] = time(); + $this->save($event, array('fieldList' => $fieldList)); + if (Configure::read('MISP.background_jobs')) { /** @var Job $job */ @@ -4380,10 +4393,6 @@ class Event extends AppModel 'order' => ['id ASC'] ]); } - $fieldList = array('published', 'id', 'info', 'publish_timestamp'); - $event['Event']['skip_zmq'] = 1; - $event['Event']['skip_kafka'] = 1; - $this->save($event, array('fieldList' => $fieldList)); $userForPubSub = [ 'id' => 0, 'org_id' => $hostOrg['Org']['id'], From b5596f687fe07e8f4b40a53cf82dda3f046c15b1 Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 5 Aug 2022 14:47:03 +0200 Subject: [PATCH 3/4] chg: [publishing] reverted the speculative fix --- app/Model/Event.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/Model/Event.php b/app/Model/Event.php index e96729a67..f2c5f7eda 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -4300,19 +4300,6 @@ class Event extends AppModel public function publishRouter($id, $passAlong = null, $user) { - $event = $this->find('first', array( - 'recursive' => -1, - 'conditions' => array('Event.id' => $id) - )); - - if (empty($event)) { - return false; - } - $fieldList = array('published', 'id', 'info', 'publish_timestamp'); - $event['Event']['published'] = 1; - $event['Event']['publish_timestamp'] = time(); - $this->save($event, array('fieldList' => $fieldList)); - if (Configure::read('MISP.background_jobs')) { /** @var Job $job */ From b5ababdc15612f096f8dae7707244bfb53951f1e Mon Sep 17 00:00:00 2001 From: iglocska Date: Fri, 5 Aug 2022 14:48:28 +0200 Subject: [PATCH 4/4] chg: [tests] added sleep to publishing --- tests/testlive_security.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testlive_security.py b/tests/testlive_security.py index d51b2828e..638c636b3 100644 --- a/tests/testlive_security.py +++ b/tests/testlive_security.py @@ -1253,6 +1253,7 @@ class TestSecurity(unittest.TestCase): # Publish self.assertSuccessfulResponse(self.admin_misp_connector.publish(created_event)) + sleep(6); # Event is published, so normal user should see that event self.assertTrue(logged_in.event_exists(created_event.uuid))