暫無描述

tests_rest_alerts.py 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # IRIS Source Code
  2. # Copyright (C) 2023 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from unittest import TestCase
  19. from iris import Iris
  20. from uuid import uuid4
  21. class TestsRestAlerts(TestCase):
  22. def setUp(self) -> None:
  23. self._subject = Iris()
  24. def tearDown(self):
  25. self._subject.clear_database()
  26. response = self._subject.get('api/v2/alerts').json()
  27. for alert in response['data']:
  28. identifier = alert['alert_id']
  29. self._subject.create(f'/alerts/delete/{identifier}', {})
  30. def test_create_alert_should_not_fail(self):
  31. body = {
  32. 'alert_title': 'title',
  33. 'alert_severity_id': 4,
  34. 'alert_status_id': 3,
  35. 'alert_customer_id': 1
  36. }
  37. response = self._subject.create('/alerts/add', body)
  38. self.assertEqual(200, response.status_code)
  39. def test_alerts_with_filter_alerts_assets_should_not_fail(self):
  40. response = self._subject.get('/api/v2/alerts', query_parameters={'alert_assets': 'some assert name'})
  41. self.assertEqual(200, response.status_code)
  42. def test_alerts_filter_with_filter_alert_iocs_should_not_fail(self):
  43. response = self._subject.get('api/v2/alerts', query_parameters={'alert_iocs': 'some ioc value'})
  44. self.assertEqual(200, response.status_code)
  45. def test_get_alerts_filter_should_show_newly_created_alert_for_administrator(self):
  46. alert_title = f'title{uuid4()}'
  47. body = {
  48. 'alert_title': alert_title,
  49. 'alert_severity_id': 4,
  50. 'alert_status_id': 3,
  51. 'alert_customer_id': 1
  52. }
  53. self._subject.create('/alerts/add', body)
  54. response = self._subject.get('/api/v2/alerts', query_parameters={'alert_title': alert_title}).json()
  55. self.assertEqual(1, response['total'])
  56. def test_get_alerts_should_return_field_data(self):
  57. response = self._subject.get('/api/v2/alerts').json()
  58. self.assertEqual([], response['data'])
  59. def test_merge_alert_into_a_case_should_not_fail(self):
  60. case_identifier = self._subject.create_dummy_case()
  61. body = {
  62. 'alert_title': 'title',
  63. 'alert_severity_id': 4,
  64. 'alert_status_id': 3,
  65. 'alert_customer_id': 1
  66. }
  67. response = self._subject.create('/alerts/add', body).json()
  68. alert_identifier = response['data']['alert_id']
  69. body = {
  70. 'target_case_id': case_identifier,
  71. 'iocs_import_list': [],
  72. 'assets_import_list': []
  73. }
  74. response = self._subject.create(f'/alerts/merge/{alert_identifier}', body)
  75. # TODO should be 201
  76. self.assertEqual(200, response.status_code)