ame"> link-rel-dns-prefetch.js d8e79ace03 index commit лет назад: 2 link-rel-modulepreload.js d8e79ace03 index commit лет назад: 2 link-rel-preconnect.js d8e79ace03 index commit лет назад: 2 link-rel-prefetch.js d8e79ace03 index commit лет назад: 2 link-rel-preload.js d8e79ace03 index commit лет назад: 2 link-rel-prerender.js d8e79ace03 index commit лет назад: 2 loading-lazy-attr.js d8e79ace03 index commit лет назад: 2 localecompare.js d8e79ace03 index commit лет назад: 2 magnetometer.js d8e79ace03 index commit лет назад: 2 matchesselector.js d8e79ace03 index commit лет назад: 2 matchmedia.js d8e79ace03 index commit лет назад: 2 mathml.js d8e79ace03 index commit лет назад: 2 maxlength.js d8e79ace03 index commit лет назад: 2 mdn-css-unicode-bidi-isolate-override.js d8e79ace03 index commit лет назад: 2 mdn-css-unicode-bidi-isolate.js d8e79ace03 index commit лет назад: 2 mdn-css-unicode-bidi-plaintext.js d8e79ace03 index commit лет назад: 2 mdn-text-decoration-color.js d8e79ace03 index commit лет назад: 2 mdn-text-decoration-line.js d8e79ace03 index commit лет назад: 2 mdn-text-decoration-shorthand.js d8e79ace03 index commit лет назад: 2 mdn-text-decoration-style.js d8e79ace03 index commit лет назад: 2 media-fragments.js d8e79ace03 index commit лет назад: 2 mediacapture-fromelement.js d8e79ace03 index commit лет назад: 2 mediarecorder.js d8e79ace03 index commit лет назад: 2 mediasource.js d8e79ace03 index commit лет назад: 2 menu.js d8e79ace03 index commit лет назад: 2 meta-theme-color.js d8e79ace03 index commit лет назад: 2 meter.js d8e79ace03 index commit лет назад: 2 midi.js d8e79ace03 index commit лет назад: 2 minmaxwh.js d8e79ace03 index commit лет назад: 2 mp3.js d8e79ace03 index commit лет назад: 2 mpeg-dash.js d8e79ace03 index commit лет назад: 2 mpeg4.js d8e79ace03 index commit лет назад: 2 multibackgrounds.js d8e79ace03 index commit лет назад: 2 multicolumn.js d8e79ace03 index commit лет назад: 2 mutation-events.js d8e79ace03 index commit лет назад: 2 mutationobserver.js d8e79ace03 index commit лет назад: 2 namevalue-storage.js d8e79ace03 index commit лет назад: 2 native-filesystem-api.js d8e79ace03 index commit лет назад: 2 nav-timing.js d8e79ace03 index commit лет назад: 2 netinfo.js d8e79ace03 index commit лет назад: 2 notifications.js d8e79ace03 index commit лет назад: 2 object-entries.js d8e79ace03 index commit лет назад: 2 object-fit.js d8e79ace03 index commit лет назад: 2 object-observe.js d8e79ace03 index commit лет назад: 2 object-values.js d8e79ace03 index commit лет назад: 2 objectrtc.js d8e79ace03 index commit лет назад: 2 offline-apps.js d8e79ace03 index commit лет назад: 2 offscreencanvas.js d8e79ace03 index commit лет назад: 2 ogg-vorbis.js d8e79ace03 index commit лет назад: 2 ogv.js d8e79ace03 index commit лет назад: 2 ol-reversed.js d8e79ace03 index commit лет назад: 2 once-event-listener.js d8e79ace03 index commit лет назад: 2 online-status.js d8e79ace03 index commit лет назад: 2 opus.js d8e79ace03 index commit лет назад: 2 orientation-sensor.js d8e79ace03 index commit лет назад: 2 outline.js d8e79ace03 index commit лет назад: 2 pad-start-end.js d8e79ace03 index commit лет назад: 2 page-transition-events.js d8e79ace03 index commit лет назад: 2 pagevisibility.js d8e79ace03 index commit лет назад: 2 passive-event-listener.js d8e79ace03 index commit лет назад: 2 passwordrules.js d8e79ace03 index commit лет назад: 2 path2d.js d8e79ace03 index commit лет назад: 2 payment-request.js d8e79ace03 index commit лет назад: 2 pdf-viewer.js d8e79ace03 index commit лет назад: 2 permissions-api.js d8e79ace03 index commit лет назад: 2 permissions-policy.js d8e79ace03 index commit лет назад: 2 picture-in-picture.js d8e79ace03 index commit лет назад: 2 picture.js d8e79ace03 index commit лет назад: 2 ping.js d8e79ace03 index commit лет назад: 2 png-alpha.js d8e79ace03 index commit лет назад: 2 pointer-events.js d8e79ace03 index commit лет назад: 2 pointer.js d8e79ace03 index commit лет назад: 2 pointerlock.js d8e79ace03 index commit лет назад: 2 portals.js d8e79ace03 index commit лет назад: 2 prefers-color-scheme.js d8e79ace03 index commit лет назад: 2 prefers-reduced-motion.js d8e79ace03 index commit лет назад: 2 progress.js d8e79ace03 index commit лет назад: 2 promise-finally.js d8e79ace03 index commit лет назад: 2 promises.js d8e79ace03 index commit лет назад: 2 proximity.js d8e79ace03 index commit лет назад: 2 proxy.js d8e79ace03 index commit лет назад: 2 publickeypinning.js d8e79ace03 index commit лет назад: 2 push-api.js d8e79ace03 index commit лет назад: 2 queryselector.js d8e79ace03 index commit лет назад: 2 readonly-attr.js d8e79ace03 index commit лет назад: 2 referrer-policy.js d8e79ace03 index commit лет назад: 2 registerprotocolhandler.js d8e79ace03 index commit лет назад: 2 rel-noopener.js d8e79ace03 index commit лет назад: 2 rel-noreferrer.js d8e79ace03 index commit лет назад: 2 rellist.js d8e79ace03 index commit лет назад: 2 rem.js d8e79ace03 index commit лет назад: 2 requestanimationframe.js d8e79ace03 index commit лет назад: 2 requestidlecallback.js d8e79ace03 index commit лет назад: 2 resizeobserver.js d8e79ace03 index commit лет назад: 2 resource-timing.js d8e79ace03 index commit лет назад: 2 rest-parameters.js d8e79ace03 index commit лет назад: 2 rtcpeerconnection.js d8e79ace03 index commit лет назад: 2 ruby.js d8e79ace03 index commit лет назад: 2 run-in.js d8e79ace03 index commit лет назад: 2 same-site-cookie-attribute.js d8e79ace03 index commit лет назад: 2 screen-orientation.js d8e79ace03 index commit лет назад: 2 script-async.js d8e79ace03 index commit лет назад: 2 script-defer.js d8e79ace03 index commit лет назад: 2 scrollintoview.js d8e79ace03 index commit лет назад: 2 scrollintoviewifneeded.js d8e79ace03 index commit лет назад: 2 sdch.js d8e79ace03 index commit лет назад: 2 selection-api.js d8e79ace03 index commit лет назад: 2 server-timing.js d8e79ace03 index commit лет назад: 2 serviceworkers.js d8e79ace03 index commit лет назад: 2 setimmediate.js d8e79ace03 index commit лет назад: 2 shadowdom.js d8e79ace03 index commit лет назад: 2 shadowdomv1.js d8e79ace03 index commit лет назад: 2 sharedarraybuffer.js d8e79ace03 index commit лет назад: 2 sharedworkers.js d8e79ace03 index commit лет назад: 2 sni.js d8e79ace03 index commit лет назад: 2 spdy.js d8e79ace03 index commit лет назад: 2 speech-recognition.js d8e79ace03 index commit лет назад: 2 speech-synthesis.js d8e79ace03 index commit лет назад: 2 spellcheck-attribute.js d8e79ace03 index commit лет назад: 2 sql-storage.js d8e79ace03 index commit лет назад: 2 srcset.js d8e79ace03 index commit лет назад: 2 stream.js d8e79ace03 index commit лет назад: 2 streams.js d8e79ace03 index commit лет назад: 2 stricttransportsecurity.js d8e79ace03 index commit лет назад: 2 style-scoped.js d8e79ace03 index commit лет назад: 2 subresource-bundling.js d8e79ace03 index commit лет назад: 2 subresource-integrity.js d8e79ace03 index commit лет назад: 2 svg-css.js d8e79ace03 index commit лет назад: 2 svg-filters.js d8e79ace03 index commit лет назад: 2 svg-fonts.js d8e79ace03 index commit лет назад: 2 svg-fragment.js d8e79ace03 index commit лет назад: 2 svg-html.js d8e79ace03 index commit лет назад: 2 svg-html5.js d8e79ace03 index commit лет назад: 2 svg-img.js d8e79ace03 index commit лет назад: 2 svg-smil.js d8e79ace03 index commit лет назад: 2 svg.js d8e79ace03 index commit лет назад: 2 sxg.js d8e79ace03 index commit лет назад: 2 tabindex-attr.js d8e79ace03 index commit лет назад: 2 template-literals.js d8e79ace03 index commit лет назад: 2 template.js d8e79ace03 index commit лет назад: 2 temporal.js d8e79ace03 index commit лет назад: 2 testfeat.js d8e79ace03 index commit лет назад: 2 text-decoration.js d8e79ace03 index commit лет назад: 2 text-emphasis.js d8e79ace03 index commit лет назад: 2 text-overflow.js d8e79ace03 index commit лет назад: 2 text-size-adjust.js d8e79ace03 index commit лет назад: 2 text-stroke.js d8e79ace03 index commit лет назад: 2 textcontent.js d8e79ace03 index commit лет назад: 2 textencoder.js d8e79ace03 index commit лет назад: 2 tls1-1.js d8e79ace03 index commit лет назад: 2 tls1-2.js d8e79ace03 index commit лет назад: 2 tls1-3.js d8e79ace03 index commit лет назад: 2 touch.js d8e79ace03 index commit лет назад: 2 transforms2d.js d8e79ace03 index commit лет назад: 2 transforms3d.js d8e79ace03 index commit лет назад: 2 trusted-types.js d8e79ace03 index commit лет назад: 2 ttf.js d8e79ace03 index commit лет назад: 2 typedarrays.js d8e79ace03 index commit лет назад: 2 u2f.js d8e79ace03 index commit лет назад: 2 unhandledrejection.js d8e79ace03 index commit лет назад: 2 upgradeinsecurerequests.js d8e79ace03 index commit лет назад: 2 url-scroll-to-text-fragment.js d8e79ace03 index commit лет назад: 2 url.js d8e79ace03 index commit лет назад: 2 urlsearchparams.js d8e79ace03 index commit лет назад: 2 use-strict.js d8e79ace03 index commit лет назад: 2 user-select-none.js d8e79ace03 index commit лет назад: 2 user-timing.js d8e79ace03 index commit лет назад: 2 variable-fonts.js d8e79ace03 index commit лет назад: 2 vector-effect.js d8e79ace03 index commit лет назад: 2 vibration.js d8e79ace03 index commit лет назад: 2 video.js d8e79ace03 index commit лет назад: 2 videotracks.js d8e79ace03 index commit лет назад: 2 viewport-unit-variants.js d8e79ace03 index commit лет назад: 2 viewport-units.js d8e79ace03 index commit лет назад: 2 wai-aria.js d8e79ace03 index commit лет назад: 2 wake-lock.js d8e79ace03 index commit лет назад: 2 wasm.js d8e79ace03 index commit лет назад: 2 wav.js d8e79ace03 index commit лет назад: 2 wbr-element.js d8e79ace03 index commit лет назад: 2 web-animation.js d8e79ace03 index commit лет назад: 2 web-app-manifest.js d8e79ace03 index commit лет назад: 2 web-bluetooth.js d8e79ace03 index commit лет назад: 2 web-serial.js d8e79ace03 index commit лет назад: 2 web-share.js d8e79ace03 index commit лет назад: 2 webauthn.js d8e79ace03 index commit лет назад: 2 webcodecs.js d8e79ace03 index commit лет назад: 2 webgl.js d8e79ace03 index commit лет назад: 2 webgl2.js d8e79ace03 index commit лет назад: 2 webgpu.js d8e79ace03 index commit лет назад: 2 webhid.js d8e79ace03 index commit лет назад: 2 webkit-user-drag.js d8e79ace03 index commit лет назад: 2 webm.js d8e79ace03 index commit лет назад: 2 webnfc.js d8e79ace03 index commit лет назад: 2 webp.js d8e79ace03 index commit лет назад: 2 websockets.js d8e79ace03 index commit лет назад: 2 webtransport.js d8e79ace03 index commit лет назад: 2 webusb.js d8e79ace03 index commit лет назад: 2 webvr.js d8e79ace03 index commit лет назад: 2 webvtt.js d8e79ace03 index commit лет назад: 2 webworkers.js d8e79ace03 index commit лет назад: 2 webxr.js d8e79ace03 index commit лет назад: 2 will-change.js d8e79ace03 index commit лет назад: 2 woff.js d8e79ace03 index commit лет назад: 2 woff2.js d8e79ace03 index commit лет назад: 2 word-break.js d8e79ace03 index commit лет назад: 2 wordwrap.js d8e79ace03 index commit лет назад: 2 x-doc-messaging.js d8e79ace03 index commit лет назад: 2 x-frame-options.js d8e79ace03 index commit лет назад: 2 xhr2.js d8e79ace03 index commit лет назад: 2 xhtml.js d8e79ace03 index commit лет назад: 2 xhtmlsmil.js d8e79ace03 index commit лет назад: 2 xml-serializer.js d8e79ace03 index commit лет назад: 2 tum/soc - Gogs: Simplico Git Service

Bez popisu

tests_rest_iocs.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. _IDENTIFIER_FOR_NONEXISTENT_OBJECT = 123456789
  21. class TestsRestIocs(TestCase):
  22. def setUp(self) -> None:
  23. self._subject = Iris()
  24. def tearDown(self):
  25. self._subject.clear_database()
  26. def test_get_ioc_should_not_fail(self):
  27. response = self._subject.get('/case/ioc/list').json()
  28. self.assertEqual('success', response['status'])
  29. def test_create_ioc_should_return_correct_ioc_type_id(self):
  30. case_identifier = self._subject.create_dummy_case()
  31. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  32. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  33. self.assertEqual(1, response['ioc_type_id'])
  34. def test_get_ioc_should_return_ioc_type_id(self):
  35. ioc_type_id = 1
  36. case_identifier = self._subject.create_dummy_case()
  37. body = {'ioc_type_id': ioc_type_id, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  38. test = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  39. current_id = test['ioc_id']
  40. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs/{current_id}').json()
  41. self.assertEqual(ioc_type_id, response['ioc_type_id'])
  42. def test_get_ioc_with_missing_ioc_identifier_should_return_error(self):
  43. case_identifier = self._subject.create_dummy_case()
  44. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  45. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  46. test = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs/None').json()
  47. self.assertEqual('error', test['status'])
  48. def test_delete_ioc_should_return_204(self):
  49. case_identifier = self._subject.create_dummy_case()
  50. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  51. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  52. ioc_identifier = response['ioc_id']
  53. response = self._subject.delete(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}')
  54. self.assertEqual(204, response.status_code)
  55. def test_delete_ioc_with_missing_ioc_identifier_should_return_404(self):
  56. case_identifier = self._subject.create_dummy_case()
  57. response = self._subject.delete(f'/api/v2/cases/{case_identifier}/iocs/{_IDENTIFIER_FOR_NONEXISTENT_OBJECT}')
  58. self.assertEqual(404, response.status_code)
  59. def test_get_iocs_should_not_fail(self):
  60. case_identifier = self._subject.create_dummy_case()
  61. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs')
  62. self.assertEqual(200, response.status_code)
  63. def test_create_ioc_should_add_the_ioc_in_the_correct_case(self):
  64. case_identifier = self._subject.create_dummy_case()
  65. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  66. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  67. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs').json()
  68. self.assertEqual(1, response['total'])
  69. def test_get_iocs_should_filter_and_return_ioc_type_identifier(self):
  70. case_identifier = self._subject.create_dummy_case()
  71. ioc_type_identifier = 2
  72. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', {
  73. 'ioc_type_id': ioc_type_identifier,
  74. 'ioc_tlp_id': 2,
  75. 'ioc_value': 'test_get_iocs_should_filter_on_ioc_value',
  76. 'ioc_description': 'rewrw',
  77. 'ioc_tags': '',
  78. 'custom_attributes': {}
  79. }).json()
  80. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', {
  81. 'ioc_type_id': 1,
  82. 'ioc_tlp_id': 2,
  83. 'ioc_value': 'wrong_test',
  84. 'ioc_description': 'rewrw',
  85. 'ioc_tags': '',
  86. 'custom_attributes': {}
  87. }).json()
  88. filters = {'ioc_value': 'test_get_iocs_should_filter_on_ioc_value'}
  89. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs', query_parameters=filters).json()
  90. identifiers = []
  91. for ioc in response['data']:
  92. identifiers.append(ioc['ioc_type_id'])
  93. self.assertIn(ioc_type_identifier, identifiers)
  94. def test_get_ioc_should_return_404_when_not_present(self):
  95. case_identifier = self._subject.create_dummy_case()
  96. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs/{_IDENTIFIER_FOR_NONEXISTENT_OBJECT}')
  97. self.assertEqual(404, response.status_code)
  98. def test_get_ioc_should_return_200_on_success(self):
  99. case_identifier = self._subject.create_dummy_case()
  100. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  101. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  102. ioc_identifier = response['ioc_id']
  103. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}')
  104. self.assertEqual(200, response.status_code)
  105. def test_get_iocs_should_include_tlp_information(self):
  106. case_identifier = self._subject.create_dummy_case()
  107. tlp_identifier = 2
  108. body = {'ioc_type_id': 1, 'ioc_tlp_id': tlp_identifier, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  109. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  110. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs').json()
  111. self.assertEqual(tlp_identifier, response['data'][0]['tlp']['tlp_id'])
  112. def test_get_iocs_should_include_link_to_other_cases_with_same_value_type_ioc(self):
  113. case_identifier1 = self._subject.create_dummy_case()
  114. case_identifier2 = self._subject.create_dummy_case()
  115. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  116. self._subject.create(f'/api/v2/cases/{case_identifier1}/iocs', body).json()
  117. body = {'ioc_type_id': 1, 'ioc_tlp_id': 1, 'ioc_value': '8.8.8.8', 'ioc_description': 'another', 'ioc_tags': ''}
  118. self._subject.create(f'/api/v2/cases/{case_identifier2}/iocs', body).json()
  119. response = self._subject.get(f'/api/v2/cases/{case_identifier2}/iocs').json()
  120. self.assertEqual(case_identifier1, response['data'][0]['link'][0]['case_id'])
  121. def test_create_ioc_should_include_field_link(self):
  122. case_identifier = self._subject.create_dummy_case()
  123. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  124. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  125. self.assertEqual([], response['link'])
  126. def test_get_ioc_should_include_field_link(self):
  127. case_identifier = self._subject.create_dummy_case()
  128. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  129. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  130. ioc_identifier = response['ioc_id']
  131. response = self._subject.get(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}').json()
  132. self.assertEqual([], response['link'])
  133. def test_create_ioc_should_not_create_two_iocs_with_identical_type_and_value(self):
  134. case_identifier = self._subject.create_dummy_case()
  135. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  136. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body)
  137. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body)
  138. self.assertEqual(400, response.status_code)
  139. def test_delete_ioc_should_not_prevent_case_deletion(self):
  140. case_identifier = self._subject.create_dummy_case()
  141. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  142. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  143. ioc_identifier = response['ioc_id']
  144. self._subject.create(f'/case/ioc/{ioc_identifier}/comments/add', {'comment_text': 'comment text'})
  145. self._subject.delete(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}')
  146. response = self._subject.delete(f'/api/v2/cases/{case_identifier}')
  147. self.assertEqual(204, response.status_code)
  148. def test_update_ioc_should_not_fail(self):
  149. case_identifier = self._subject.create_dummy_case()
  150. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  151. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  152. ioc_identifier = response['ioc_id']
  153. response = self._subject.update(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}', {'ioc_value': '9.9.9.9'})
  154. self.assertEqual(200, response.status_code)
  155. def test_update_ioc_should_return_updated_value(self):
  156. case_identifier = self._subject.create_dummy_case()
  157. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  158. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  159. ioc_identifier = response['ioc_id']
  160. new_value = '9.9.9.9'
  161. response = self._subject.update(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}', {'ioc_value': new_value}).json()
  162. self.assertEqual(new_value, response['ioc_value'])
  163. def test_update_ioc_should_return_an_error_when_ioc_type_identifier_is_out_of_range(self):
  164. case_identifier = self._subject.create_dummy_case()
  165. body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''}
  166. response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json()
  167. ioc_identifier = response['ioc_id']
  168. response = self._subject.update(f'/api/v2/cases/{case_identifier}/iocs/{ioc_identifier}', {'ioc_type_id': '123456789'})
  169. self.assertEqual(400, response.status_code)
  170. def test_rest_case_should_return_error_ioc_when_permission_denied(self):
  171. user = self._subject.create_dummy_user()
  172. case_identifier = self._subject.create_dummy_case()
  173. body = {'ioc_type_id': 1, 'ioc_tlp_id': 1, 'ioc_value': 'IOC value'}
  174. self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body)
  175. response = user.get(f'/api/v2/cases/{case_identifier}/iocs')
  176. self.assertEqual(403, response.status_code)