fix: [internal] Attaching tags to attachment attribute

pull/7915/head
Jakub Onderka 2021-10-31 15:18:59 +01:00
parent dd856827c0
commit 82dc65df50
2 changed files with 17 additions and 2 deletions

View File

@ -469,15 +469,16 @@ class Attribute extends AppModel
}
}
$result = true;
// if the 'data' field is set on the $this->data then save the data to the correct file
// if the 'data' field is set on the $attribute then save the data to the correct file
if (isset($attribute['type']) && $this->typeIsAttachment($attribute['type'])) {
if (isset($attribute['data_raw'])) {
$attribute['data'] = $attribute['data_raw'];
unset($attribute['data_raw']);
$result = $this->saveAttachment($attribute);
} elseif (isset($attribute['data'])) {
$attribute['data'] = base64_decode($attribute['data']);
$result = $this->saveAttachment($attribute);
}
$result = $this->saveAttachment($attribute);
}
$pubToZmq = Configure::read('Plugin.ZeroMQ_enable') && Configure::read('Plugin.ZeroMQ_attribute_notifications_enable');
$kafkaTopic = $this->kafkaTopic('attribute');

View File

@ -2,6 +2,7 @@
import os
import unittest
import uuid
from io import BytesIO
import urllib3 # type: ignore
import logging
@ -539,6 +540,19 @@ class TestComprehensive(unittest.TestCase):
check_response(audit_logs)
self.assertGreater(len(audit_logs), 0)
def test_add_tag_to_attachment(self):
event = create_simple_event()
with open(__file__, 'rb') as f:
event.add_attribute('attachment', value='testfile.py', data=BytesIO(f.read()))
event = check_response(self.admin_misp_connector.add_event(event))
attribute_uuids = [attribute.uuid for attribute in event.attributes if attribute.type == 'attachment']
self.assertEqual(1, len(attribute_uuids))
check_response(self.admin_misp_connector.tag(attribute_uuids[0], 'generic_tag_test'))
check_response(self.admin_misp_connector.delete_event(event))
if __name__ == '__main__':
unittest.main()