Sin descripción

tests_graphql.py 53KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  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 iris import API_URL
  21. from graphql_api import GraphQLApi
  22. from base64 import b64encode
  23. class TestsGraphQL(TestCase):
  24. def setUp(self) -> None:
  25. self._subject = Iris()
  26. def tearDown(self):
  27. self._subject.clear_database()
  28. @staticmethod
  29. def _get_first_case(body):
  30. for case in body['data']['cases']['edges']:
  31. if case['node']['name'] == '#1 - Initial Demo':
  32. return case
  33. def _create_case(self):
  34. payload = {
  35. 'query': 'mutation { caseCreate(name: "case name", description: "Some description", clientId: 1) {case { caseId } } }'
  36. }
  37. body = self._subject.execute_graphql_query(payload)
  38. return int(body['data']['caseCreate']['case']['caseId'])
  39. def test_graphql_endpoint_should_reject_requests_with_wrong_authentication_token(self):
  40. graphql_api = GraphQLApi(API_URL + '/graphql', 64 * '0')
  41. payload = {
  42. 'query': 'query { cases { edges { node { name } } } }'
  43. }
  44. response = graphql_api.execute(payload)
  45. self.assertEqual(401, response.status_code)
  46. def test_graphql_cases_should_contain_the_initial_case(self):
  47. payload = {
  48. 'query': 'query { cases { edges { node { name } } } }'
  49. }
  50. body = self._subject.execute_graphql_query(payload)
  51. case_names = []
  52. for case in body['data']['cases']['edges']:
  53. case_names.append(case['node']['name'])
  54. self.assertIn('#1 - Initial Demo', case_names)
  55. def test_graphql_cases_should_have_a_global_identifier(self):
  56. payload = {
  57. 'query': 'query { cases { edges { node { id name } } } }'
  58. }
  59. body = self._subject.execute_graphql_query(payload)
  60. first_case = self._get_first_case(body)
  61. self.assertEqual(b64encode(b'CaseObject:1').decode(), first_case['node']['id'])
  62. def test_graphql_create_ioc_should_not_fail(self):
  63. case_identifier = self._create_case()
  64. ioc_value = 'IOC value'
  65. payload = {
  66. 'query': f'''mutation {{
  67. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  68. ioc {{ iocValue }}
  69. }}
  70. }}'''
  71. }
  72. response = self._subject.execute_graphql_query(payload)
  73. test_ioc_value = response['data']['iocCreate']['ioc']['iocValue']
  74. self.assertEqual(test_ioc_value, ioc_value)
  75. def test_graphql_delete_ioc_should_not_fail(self):
  76. case_identifier = self._create_case()
  77. payload = {
  78. 'query': f'''mutation {{
  79. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
  80. ioc {{ iocId }}
  81. }}
  82. }}'''
  83. }
  84. response = self._subject.execute_graphql_query(payload)
  85. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  86. payload = {
  87. 'query': f'''mutation {{
  88. iocDelete(iocId: {ioc_identifier}) {{
  89. message
  90. }}
  91. }}'''
  92. }
  93. response = self._subject.execute_graphql_query(payload)
  94. self.assertEqual(f'IOC {int(ioc_identifier)} deleted', response['data']['iocDelete']['message'])
  95. def test_graphql_create_ioc_should_allow_optional_description_to_be_set(self):
  96. case_identifier = self._create_case()
  97. description = 'Some description'
  98. payload = {
  99. 'query': f'''mutation {{
  100. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
  101. description: "{description}") {{
  102. ioc {{ iocDescription }}
  103. }}
  104. }}'''
  105. }
  106. response = self._subject.execute_graphql_query(payload)
  107. self.assertEqual(description, response['data']['iocCreate']['ioc']['iocDescription'])
  108. def test_graphql_create_ioc_should_allow_optional_tags_to_be_set(self):
  109. case_identifier = self._create_case()
  110. tags = 'tag1,tag2'
  111. payload = {
  112. 'query': f'''mutation {{
  113. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
  114. tags: "{tags}") {{
  115. ioc {{ iocTags }}
  116. }}
  117. }}'''
  118. }
  119. response = self._subject.execute_graphql_query(payload)
  120. self.assertEqual(tags, response['data']['iocCreate']['ioc']['iocTags'])
  121. def test_graphql_update_ioc_should_update_tlp(self):
  122. case_identifier = self._create_case()
  123. ioc_value = 'IOC value'
  124. payload = {
  125. 'query': f'''mutation {{
  126. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  127. ioc {{ iocId }}
  128. }}
  129. }}'''
  130. }
  131. response = self._subject.execute_graphql_query(payload)
  132. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  133. payload = {
  134. 'query': f'''mutation {{
  135. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}") {{
  136. ioc {{ iocTlpId }}
  137. }}
  138. }}'''
  139. }
  140. response = self._subject.execute_graphql_query(payload)
  141. self.assertEqual(2, response['data']['iocUpdate']['ioc']['iocTlpId'])
  142. def test_graphql_update_ioc_should_not_update_typeId(self):
  143. case_identifier = self._create_case()
  144. ioc_value = 'IOC value'
  145. payload = {
  146. 'query': f'''mutation {{
  147. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  148. ioc {{ iocId iocTypeId }}
  149. }}
  150. }}'''
  151. }
  152. response = self._subject.execute_graphql_query(payload)
  153. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  154. ioc_type = response['data']['iocCreate']['ioc']['iocTypeId']
  155. payload = {
  156. 'query': f'''mutation {{
  157. iocUpdate(iocId: {ioc_identifier}, tlpId:1, value: "{ioc_value}") {{
  158. ioc {{ iocTypeId }}
  159. }}
  160. }}'''
  161. }
  162. response = self._subject.execute_graphql_query(payload)
  163. self.assertEqual(ioc_type, response['data']['iocUpdate']['ioc']['iocTypeId'])
  164. def test_graphql_update_ioc_should_fail_when_missing_iocId(self):
  165. case_identifier = self._create_case()
  166. ioc_value = 'IOC value'
  167. payload = {
  168. 'query': f'''mutation {{
  169. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  170. ioc {{ iocId }}
  171. }}
  172. }}'''
  173. }
  174. self._subject.execute_graphql_query(payload)
  175. payload = {
  176. 'query': f'''mutation {{
  177. iocUpdate(typeId:1, tlpId:1, value: "{ioc_value}") {{
  178. ioc {{ iocTlpId }}
  179. }}
  180. }}'''
  181. }
  182. response = self._subject.execute_graphql_query(payload)
  183. self.assertIn('errors', response)
  184. def test_graphql_update_ioc_should_not_update_tlpId(self):
  185. case_identifier = self._create_case()
  186. ioc_value = 'IOC value'
  187. payload = {
  188. 'query': f'''mutation {{
  189. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  190. ioc {{ iocId iocTlpId }}
  191. }}
  192. }}'''
  193. }
  194. response = self._subject.execute_graphql_query(payload)
  195. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  196. ioc_tlp = response['data']['iocCreate']['ioc']['iocTlpId']
  197. payload = {
  198. 'query': f'''mutation {{
  199. iocUpdate(iocId: {ioc_identifier}, typeId:1, value: "{ioc_value}") {{
  200. ioc {{ iocId iocTlpId }}
  201. }}
  202. }}'''
  203. }
  204. response = self._subject.execute_graphql_query(payload)
  205. self.assertEqual(ioc_tlp, response['data']['iocUpdate']['ioc']['iocTlpId'])
  206. def test_graphql_update_ioc_should_not_update_value(self):
  207. case_identifier = self._create_case()
  208. payload = {
  209. 'query': f'''mutation {{
  210. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
  211. ioc {{ iocId iocValue }}
  212. }}
  213. }}'''
  214. }
  215. response = self._subject.execute_graphql_query(payload)
  216. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  217. ioc_value = response['data']['iocCreate']['ioc']['iocValue']
  218. payload = {
  219. 'query': f'''mutation {{
  220. iocUpdate(iocId: {ioc_identifier}, typeId:1, tlpId:1) {{
  221. ioc {{ iocValue }}
  222. }}
  223. }}'''
  224. }
  225. response = self._subject.execute_graphql_query(payload)
  226. self.assertEqual(ioc_value, response['data']['iocUpdate']['ioc']['iocValue'])
  227. def test_graphql_update_ioc_should_update_optional_parameter_description(self):
  228. case_identifier = self._create_case()
  229. ioc_value = 'IOC value'
  230. payload = {
  231. 'query': f'''mutation {{
  232. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  233. ioc {{ iocId }}
  234. }}
  235. }}'''
  236. }
  237. response = self._subject.execute_graphql_query(payload)
  238. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  239. description = 'Some description'
  240. payload = {
  241. 'query': f'''mutation {{
  242. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}",
  243. description: "{description}") {{
  244. ioc {{ iocDescription }}
  245. }}
  246. }}'''
  247. }
  248. response = self._subject.execute_graphql_query(payload)
  249. self.assertEqual(description, response['data']['iocUpdate']['ioc']['iocDescription'])
  250. def test_graphql_update_ioc_should_update_optional_parameter_tags(self):
  251. case_identifier = self._create_case()
  252. ioc_value = 'IOC value'
  253. payload = {
  254. 'query': f'''mutation {{
  255. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  256. ioc {{ iocId }}
  257. }}
  258. }}'''
  259. }
  260. response = self._subject.execute_graphql_query(payload)
  261. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  262. tags = 'tag1,tag2'
  263. payload = {
  264. 'query': f'''mutation {{
  265. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}",
  266. tags: "{tags}") {{
  267. ioc {{ iocTags }}
  268. }}
  269. }}'''
  270. }
  271. response = self._subject.execute_graphql_query(payload)
  272. self.assertEqual(tags, response['data']['iocUpdate']['ioc']['iocTags'])
  273. def test_graphql_case_should_return_a_case_by_its_identifier(self):
  274. case_identifier = self._create_case()
  275. payload = {
  276. 'query': f'''{{
  277. case(caseId: {case_identifier}) {{
  278. caseId
  279. }}
  280. }}'''
  281. }
  282. response = self._subject.execute_graphql_query(payload)
  283. self.assertEqual(case_identifier, response['data']['case']['caseId'])
  284. def test_graphql_iocs_should_return_all_iocs_of_a_case(self):
  285. case_identifier = self._create_case()
  286. payload = {
  287. 'query': f'''mutation {{
  288. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
  289. ioc {{ iocId }}
  290. }}
  291. }}'''
  292. }
  293. self._subject.execute_graphql_query(payload)
  294. payload = {
  295. 'query': f'''{{
  296. case(caseId: {case_identifier}) {{
  297. iocs {{ edges {{ node {{ iocId }} }} }}
  298. }}
  299. }}'''
  300. }
  301. response = self._subject.execute_graphql_query(payload)
  302. self.assertNotIn('errors', response)
  303. def test_graphql_case_should_return_error_log_uuid_when_permission_denied(self):
  304. user = self._subject.create_dummy_user()
  305. case_identifier = self._create_case()
  306. payload = {
  307. 'query': f'''{{
  308. case(caseId: {case_identifier}) {{
  309. caseId
  310. }}
  311. }}'''
  312. }
  313. response = user.execute_graphql_query(payload)
  314. self.assertRegex(response['errors'][0]['message'], r'Permission denied \(EID [0-9a-f-]{36}\)')
  315. def test_graphql_case_should_return_error_ioc_when_permission_denied(self):
  316. user = self._subject.create_dummy_user()
  317. case_identifier = self._create_case()
  318. payload = {
  319. 'query': f'''mutation {{
  320. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
  321. ioc {{ iocId iocValue }}
  322. }}
  323. }}'''
  324. }
  325. self._subject.execute_graphql_query(payload)
  326. payload = {
  327. 'query': f'''{{
  328. case(caseId: {case_identifier}) {{
  329. iocs {{ totalCount edges {{ node {{ iocId }} }} }}
  330. }}
  331. }}'''
  332. }
  333. response = user.execute_graphql_query(payload)
  334. self.assertIn('errors', response)
  335. def test_graphql_create_case_should_not_fail(self):
  336. test_description = 'Some description'
  337. payload = {'query': f''' mutation {{ caseCreate(name: "case2", description: "{test_description}", clientId: 1) {{ case {{ description }} }} }} '''}
  338. body = self._subject.execute_graphql_query(payload)
  339. description = body['data']['caseCreate']['case']['description']
  340. self.assertEqual(description, test_description)
  341. def test_graphql_update_case_fail_due_to_delete_case(self):
  342. payload = {
  343. 'query': '''mutation {
  344. caseCreate(name: "case2", description: "Some description", clientId: 1) {
  345. case { caseId }
  346. }
  347. }'''
  348. }
  349. response = self._subject.execute_graphql_query(payload)
  350. case_identifier = response['data']['caseCreate']['case']['caseId']
  351. payload2 = {
  352. 'query': f'''mutation {{
  353. caseDelete(caseId: {case_identifier}) {{
  354. case {{ caseId }}
  355. }}
  356. }}'''
  357. }
  358. self._subject.execute_graphql_query(payload2)
  359. payload = {
  360. 'query': f'''mutation {{
  361. caseUpdate(caseId: {case_identifier}, name: "test_delete_case") {{
  362. case {{ name }}
  363. }}
  364. }}'''
  365. }
  366. body = self._subject.execute_graphql_query(payload)
  367. self.assertIn('errors', body)
  368. def test_graphql_delete_case_should_fail(self):
  369. payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1) { case { caseId } } }'}
  370. response = self._subject.execute_graphql_query(payload)
  371. case_identifier = response['data']['caseCreate']['case']['caseId']
  372. payload2 = {
  373. 'query': f'''mutation {{
  374. caseDelete(caseId: {case_identifier}, cur_id: 1) {{
  375. case {{ caseId }}
  376. }}
  377. }}'''
  378. }
  379. body = self._subject.execute_graphql_query(payload2)
  380. self.assertIn('errors', body)
  381. def test_graphql_update_case_should_not_fail(self):
  382. case_identifier = self._create_case()
  383. test_name = 'new name'
  384. expected_name = f'#{case_identifier} - new name'
  385. payload = {
  386. 'query': f'''mutation {{
  387. caseUpdate(caseId: {case_identifier}, name: "{test_name}") {{
  388. case {{ name }}
  389. }}
  390. }}'''
  391. }
  392. body = self._subject.execute_graphql_query(payload)
  393. name = body['data']['caseUpdate']['case']['name']
  394. self.assertEqual(name, expected_name)
  395. def test_graphql_create_case_should_use_optionals_parameters(self):
  396. id_client = 1
  397. payload = {
  398. 'query': f''' mutation {{
  399. caseCreate(name: "case2", description: "Some description", clientId: {id_client},
  400. socId: "1", classificationId : 1) {{
  401. case {{ clientId }}
  402. }}
  403. }}'''
  404. }
  405. body = self._subject.execute_graphql_query(payload)
  406. client_id = body['data']['caseCreate']['case']['clientId']
  407. self.assertEqual(client_id, id_client)
  408. def test_graphql_update_case_should_use_optionals_parameters(self):
  409. id_case = 1
  410. payload = {
  411. 'query': f'''mutation {{
  412. caseUpdate(caseId: {id_case}, description: "Some description", clientId: 1, socId: "1",
  413. classificationId : 1) {{
  414. case {{ caseId }}
  415. }}
  416. }}'''
  417. }
  418. body = self._subject.execute_graphql_query(payload)
  419. case_id = body['data']['caseUpdate']['case']['caseId']
  420. self.assertEqual(case_id, id_case)
  421. def test_graphql_cases_should_return_newly_created_case(self):
  422. payload = {
  423. 'query': ''' mutation { caseCreate(name: "case2", description: "Some description", clientId: 1) {
  424. case { caseId }
  425. }
  426. }'''
  427. }
  428. response = self._subject.execute_graphql_query(payload)
  429. case_identifier = response['data']['caseCreate']['case']['caseId']
  430. payload = {
  431. 'query': 'query { cases { edges { node { caseId } } } }'
  432. }
  433. response = self._subject.execute_graphql_query(payload)
  434. case_identifiers = []
  435. for case in response['data']['cases']['edges']:
  436. case_identifiers.append(case['node']['caseId'])
  437. self.assertIn(case_identifier, case_identifiers)
  438. def test_graphql_update_case_should_update_optional_parameter_description(self):
  439. payload = {
  440. 'query': ''' mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
  441. classificationId : 1) {
  442. case { caseId }
  443. }
  444. }'''
  445. }
  446. body = self._subject.execute_graphql_query(payload)
  447. case_identifier = body['data']['caseCreate']['case']['caseId']
  448. description = 'Some description'
  449. payload = {
  450. 'query': f'''mutation {{
  451. caseUpdate(caseId: {case_identifier}, description: "{description}") {{
  452. case {{ description }}
  453. }}
  454. }}'''
  455. }
  456. response = self._subject.execute_graphql_query(payload)
  457. self.assertEqual(description, response['data']['caseUpdate']['case']['description'])
  458. def test_graphql_update_case_should_update_optional_parameter_socId(self):
  459. payload = {
  460. 'query': ''' mutation {
  461. caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
  462. classificationId : 1) {
  463. case { caseId }
  464. }
  465. }'''
  466. }
  467. body = self._subject.execute_graphql_query(payload)
  468. case_identifier = body['data']['caseCreate']['case']['caseId']
  469. soc_id = '17'
  470. payload = {
  471. 'query': f'''mutation {{
  472. caseUpdate(caseId: {case_identifier}, socId: "{soc_id}") {{
  473. case {{ socId }}
  474. }}
  475. }}'''
  476. }
  477. response = self._subject.execute_graphql_query(payload)
  478. self.assertEqual(soc_id, response['data']['caseUpdate']['case']['socId'])
  479. def test_graphql_update_case_should_update_optional_parameter_classificationId(self):
  480. payload = {
  481. 'query': ''' mutation {
  482. caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
  483. classificationId : 1) {
  484. case { caseId }
  485. }
  486. }'''
  487. }
  488. body = self._subject.execute_graphql_query(payload)
  489. case_identifier = body['data']['caseCreate']['case']['caseId']
  490. classification_id = 2
  491. payload = {
  492. 'query': f'''mutation {{
  493. caseUpdate(caseId: {case_identifier}, classificationId: {classification_id}) {{
  494. case {{ classificationId }}
  495. }}
  496. }}'''
  497. }
  498. response = self._subject.execute_graphql_query(payload)
  499. self.assertEqual(2, response['data']['caseUpdate']['case']['classificationId'])
  500. def test_graphql_update_case_with_optional_parameter_severityId(self):
  501. case_identifier = self._create_case()
  502. payload = {'query': f'mutation {{ caseUpdate(caseId: {case_identifier}, severityId: 1) {{ case {{ severityId }} }} }}'}
  503. body = self._subject.execute_graphql_query(payload)
  504. self.assertEqual(1, body['data']['caseUpdate']['case']['severityId'])
  505. def test_graphql_update_case_with_optional_parameter_ownerId(self):
  506. case_identifier = self._create_case()
  507. payload = {
  508. 'query': f'''mutation {{
  509. caseUpdate(caseId: {case_identifier}, ownerId: 1) {{
  510. case {{ ownerId }}
  511. }}
  512. }}'''
  513. }
  514. body = self._subject.execute_graphql_query(payload)
  515. self.assertEqual(1, body['data']['caseUpdate']['case']['ownerId'])
  516. def test_graphql_update_case_with_optional_parameter_stateId_reviewerId(self):
  517. case_identifier = self._create_case()
  518. payload = {
  519. 'query': f'''mutation {{
  520. caseUpdate(caseId: {case_identifier}, reviewerId: 1) {{
  521. case {{ reviewerId }}
  522. }}
  523. }}'''
  524. }
  525. body = self._subject.execute_graphql_query(payload)
  526. self.assertEqual(1, body['data']['caseUpdate']['case']['reviewerId'])
  527. def test_graphql_update_case_with_optional_parameter_stateId(self):
  528. case_identifier = self._create_case()
  529. payload = {
  530. 'query': f'''mutation {{
  531. caseUpdate(caseId: {case_identifier}, stateId: 1) {{
  532. case {{ stateId }}
  533. }}
  534. }}'''
  535. }
  536. body = self._subject.execute_graphql_query(payload)
  537. self.assertEqual(1, body['data']['caseUpdate']['case']['stateId'])
  538. def test_graphql_update_case_with_optional_parameter_reviewStatusId(self):
  539. case_identifier = self._create_case()
  540. payload = {
  541. 'query': f'''mutation {{
  542. caseUpdate(caseId: {case_identifier}, reviewStatusId: 1) {{
  543. case {{ reviewStatusId }}
  544. }}
  545. }}'''
  546. }
  547. body = self._subject.execute_graphql_query(payload)
  548. self.assertEqual(1, body['data']['caseUpdate']['case']['reviewStatusId'])
  549. def test_graphql_query_ioc_should_not_fail(self):
  550. case_identifier = self._create_case()
  551. ioc_value = 'IOC value'
  552. payload = {
  553. 'query': f'''mutation {{
  554. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  555. ioc {{ iocId }}
  556. }}
  557. }}'''
  558. }
  559. response = self._subject.execute_graphql_query(payload)
  560. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  561. payload = {
  562. 'query': f'''query {{
  563. ioc(iocId: {ioc_identifier}) {{ iocValue }}
  564. }}'''
  565. }
  566. body = self._subject.execute_graphql_query(payload)
  567. self.assertEqual(ioc_value, body['data']['ioc']['iocValue'])
  568. def test_graphql_cases_should_not_fail(self):
  569. test_name = '#1 - Initial Demo'
  570. payload = {
  571. 'query': '{ cases(first: 1) { edges { node { id name } } } }'
  572. }
  573. body = self._subject.execute_graphql_query(payload)
  574. for case in body['data']['cases']['edges']:
  575. name = case['node']['name']
  576. self.assertEqual(test_name, name)
  577. def test_graphql_update_ioc_should_update_misp(self):
  578. case_identifier = self._create_case()
  579. ioc_value = 'IOC value'
  580. payload = {
  581. 'query': f'''mutation {{
  582. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  583. ioc {{ iocId }}
  584. }}
  585. }}'''
  586. }
  587. response = self._subject.execute_graphql_query(payload)
  588. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  589. payload = {
  590. 'query': f'''mutation {{
  591. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, iocMisp: "test",
  592. value: "{ioc_value}") {{
  593. ioc {{ iocMisp }}
  594. }}
  595. }}'''
  596. }
  597. response = self._subject.execute_graphql_query(payload)
  598. self.assertEqual("test", response['data']['iocUpdate']['ioc']['iocMisp'])
  599. def test_graphql_update_ioc_should_update_userId(self):
  600. case_identifier = self._create_case()
  601. ioc_value = 'IOC value'
  602. payload = {
  603. 'query': f'''mutation {{
  604. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  605. ioc {{ iocId }}
  606. }}
  607. }}'''
  608. }
  609. response = self._subject.execute_graphql_query(payload)
  610. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  611. payload = {
  612. 'query': f'''mutation {{
  613. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, userId: 1, value: "{ioc_value}") {{
  614. ioc {{ userId }}
  615. }}
  616. }}'''
  617. }
  618. response = self._subject.execute_graphql_query(payload)
  619. self.assertEqual(1, response['data']['iocUpdate']['ioc']['userId'])
  620. def test_graphql_update_ioc_should_update_iocEnrichment(self):
  621. case_identifier = self._create_case()
  622. ioc_value = 'IOC value'
  623. payload = {
  624. 'query': f'''mutation {{
  625. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  626. ioc {{ iocId }}
  627. }}
  628. }}'''
  629. }
  630. response = self._subject.execute_graphql_query(payload)
  631. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  632. payload = {
  633. 'query': f'''mutation {{
  634. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, iocEnrichment: "test",
  635. value: "{ioc_value}") {{
  636. ioc {{ iocEnrichment }}
  637. }}
  638. }}'''
  639. }
  640. response = self._subject.execute_graphql_query(payload)
  641. self.assertEqual('"test"', response['data']['iocUpdate']['ioc']['iocEnrichment'])
  642. def test_graphql_update_ioc_should_update_modificationHistory(self):
  643. case_identifier = self._create_case()
  644. ioc_value = 'IOC value'
  645. payload = {
  646. 'query': f'''mutation {{
  647. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  648. ioc {{ iocId }}
  649. }}
  650. }}'''
  651. }
  652. response = self._subject.execute_graphql_query(payload)
  653. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  654. payload = {
  655. 'query': f'''mutation {{
  656. iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, modificationHistory: "test",
  657. value: "{ioc_value}") {{
  658. ioc {{ modificationHistory }}
  659. }}
  660. }}'''
  661. }
  662. response = self._subject.execute_graphql_query(payload)
  663. self.assertEqual('"test"', response['data']['iocUpdate']['ioc']['modificationHistory'])
  664. def test_cursor_first_after(self):
  665. payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
  666. 'caseId }}'}
  667. self._subject.execute_graphql_query(payload)
  668. case_id = 2
  669. self._subject.execute_graphql_query(payload)
  670. payload = {'query': 'query { cases { edges { node { caseId name } cursor } } }'}
  671. self._subject.execute_graphql_query(payload)
  672. payload = {'query': 'query { cases(first:1, after:"YXJyYXljb25uZWN0aW9uOjA="){ edges { node { caseId } cursor } } }'}
  673. body = self._subject.execute_graphql_query(payload)
  674. for case in body['data']['cases']['edges']:
  675. test_case_id = case['node']['caseId']
  676. self.assertEqual(case_id, test_case_id)
  677. def test_graphql_cases_classificationId_should_not_fail(self):
  678. classification_id = 1
  679. payload = {
  680. 'query': f'''mutation {{ caseCreate(name: "case1", description: "Some description", clientId: 1, socId: "1",
  681. classificationId : {classification_id}) {{ case {{ caseId }} }}}}'''}
  682. self._subject.execute_graphql_query(payload)
  683. payload = {
  684. 'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 3) {case { caseId '
  685. 'classificationId}}}'}
  686. self._subject.execute_graphql_query(payload)
  687. payload = {'query': f'''mutation {{ caseCreate(name: "case3", description: "Some description", clientId: 1, socId: "1", classificationId :
  688. {classification_id}) {{ case {{ classificationId }} }} }}'''}
  689. self._subject.execute_graphql_query(payload)
  690. payload = {
  691. 'query': f'''query {{ cases(classificationId: {classification_id} )
  692. {{ edges {{ node {{ name caseId classificationId }} cursor }} }} }}'''
  693. }
  694. body = self._subject.execute_graphql_query(payload)
  695. for case in body['data']['cases']['edges']:
  696. test_classification = case['node']['classificationId']
  697. self.assertEqual(classification_id, test_classification)
  698. def test_graphql_cases_filter_clientId_should_not_fail(self):
  699. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
  700. 'clientId }}}'}
  701. response = self._subject.execute_graphql_query(payload)
  702. client_id = response['data']['caseCreate']['case']['clientId']
  703. payload = {
  704. 'query': f'''query {{ cases(clientId: {client_id}) {{ edges {{ node {{ clientId }} }} }} }}'''
  705. }
  706. body = self._subject.execute_graphql_query(payload)
  707. for case in body['data']['cases']['edges']:
  708. test_client = case['node']['clientId']
  709. self.assertEqual(client_id, test_client)
  710. def test_graphql_cases_filter_stateId_should_not_fail(self):
  711. payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
  712. 'stateId }}}'}
  713. response = self._subject.execute_graphql_query(payload)
  714. state_id = response['data']['caseCreate']['case']['stateId']
  715. payload = {
  716. 'query': f'''query {{ cases(stateId: {state_id})
  717. {{ edges {{ node {{ stateId }} }} }} }}'''
  718. }
  719. body = self._subject.execute_graphql_query(payload)
  720. for case in body['data']['cases']['edges']:
  721. test_state = case['node']['stateId']
  722. self.assertEqual(state_id, test_state)
  723. def test_graphql_cases_filter_ownerId_should_not_fail(self):
  724. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
  725. 'ownerId }}}'}
  726. response = self._subject.execute_graphql_query(payload)
  727. owner_id = response['data']['caseCreate']['case']['ownerId']
  728. payload = {
  729. 'query': f'''query {{ cases(ownerId: {owner_id})
  730. {{ edges {{ node {{ ownerId }} }} }} }}'''
  731. }
  732. body = self._subject.execute_graphql_query(payload)
  733. for case in body['data']['cases']['edges']:
  734. test_owner = case['node']['ownerId']
  735. self.assertEqual(owner_id, test_owner)
  736. def test_graphql_cases_filter_openDate_should_not_fail(self):
  737. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
  738. 'openDate clientId } } }'}
  739. response = self._subject.execute_graphql_query(payload)
  740. open_date = response['data']['caseCreate']['case']['openDate']
  741. clientId = response['data']['caseCreate']['case']['clientId']
  742. payload = {
  743. 'query': f'''query {{ cases(openDate: "{open_date}")
  744. {{ edges {{ node {{ openDate clientId }} }} }} }}'''
  745. }
  746. body = self._subject.execute_graphql_query(payload)
  747. for case in body['data']['cases']['edges']:
  748. test_id = case['node']['clientId']
  749. self.assertEqual(clientId, test_id)
  750. def test_graphql_cases_filter_name_should_not_fail(self):
  751. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
  752. 'name }}}'}
  753. response = self._subject.execute_graphql_query(payload)
  754. name = response['data']['caseCreate']['case']['name']
  755. payload = {
  756. 'query': f'''query {{ cases(name: "{name}")
  757. {{ edges {{ node {{ name }} }} }} }}'''
  758. }
  759. body = self._subject.execute_graphql_query(payload)
  760. for case in body['data']['cases']['edges']:
  761. test_name = case['node']['name']
  762. self.assertEqual(name, test_name)
  763. def test_graphql_cases_filter_socId_should_not_fail(self):
  764. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
  765. 'socId } } }'}
  766. response = self._subject.execute_graphql_query(payload)
  767. soc_id = response['data']['caseCreate']['case']['socId']
  768. payload = {
  769. 'query': f'''query {{ cases(socId: "{soc_id}")
  770. {{ edges {{ node {{ socId }} }} }} }}'''
  771. }
  772. body = self._subject.execute_graphql_query(payload)
  773. for case in body['data']['cases']['edges']:
  774. test_soc_id = case['node']['socId']
  775. self.assertEqual(soc_id, test_soc_id)
  776. def test_graphql_cases_filter_severityId_should_not_fail(self):
  777. payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
  778. 'severityId }} }'}
  779. response = self._subject.execute_graphql_query(payload)
  780. severity_id = response['data']['caseCreate']['case']['severityId']
  781. payload = {
  782. 'query': f'''query {{ cases(severityId: {severity_id})
  783. {{ edges {{ node {{ severityId }} }} }} }}'''
  784. }
  785. body = self._subject.execute_graphql_query(payload)
  786. for case in body['data']['cases']['edges']:
  787. test_severity = case['node']['severityId']
  788. self.assertEqual(severity_id, test_severity)
  789. def test_graphql_cases_parameter_totalCount_should_not_fail(self):
  790. payload = {
  791. 'query': 'query { cases { totalCount } }'
  792. }
  793. body = self._subject.execute_graphql_query(payload)
  794. test_total = body['data']['cases']['totalCount']
  795. payload = {
  796. 'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { name } }}'}
  797. self._subject.execute_graphql_query(payload)
  798. test_total += 1
  799. payload = {
  800. 'query': 'query { cases { totalCount } }'
  801. }
  802. body = self._subject.execute_graphql_query(payload)
  803. total = body['data']['cases']['totalCount']
  804. self.assertEqual(total, test_total)
  805. def test_graphql_iocs_filter_iocId_should_not_fail(self):
  806. case_identifier = self._create_case()
  807. query = f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "33") {{ ioc {{ iocId }} }} }}'
  808. payload = {'query': query}
  809. response = self._subject.execute_graphql_query(payload)
  810. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  811. payload = {'query': f'{{ case(caseId: {case_identifier}) {{ iocs(iocId: 11) {{ edges {{ node {{ iocId }} }} }} }} }}'}
  812. body = self._subject.execute_graphql_query(payload)
  813. for ioc in body['data']['case']['iocs']['edges']:
  814. test_ioc_identifier = ioc['node']['iocId']
  815. self.assertEqual(ioc_identifier, test_ioc_identifier)
  816. def test_graphql_iocs_filter_iocUuid_should_not_fail(self):
  817. case_identifier = self._create_case()
  818. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "33") {{ ioc {{ iocUuid iocId }} }} }}'}
  819. response = self._subject.execute_graphql_query(payload)
  820. ioc_uuid = response['data']['iocCreate']['ioc']['iocUuid']
  821. payload = {
  822. 'query': f'''{{
  823. case(caseId: {case_identifier}) {{
  824. iocs(iocUuid: "{ioc_uuid}") {{ edges {{ node {{ iocId iocUuid }} }} }}
  825. }}
  826. }}'''
  827. }
  828. body = self._subject.execute_graphql_query(payload)
  829. for ioc in body['data']['case']['iocs']['edges']:
  830. test_ioc_uuid = ioc['node']['iocUuid']
  831. self.assertEqual(ioc_uuid, test_ioc_uuid)
  832. def test_graphql_iocs_filter_iocValue_should_not_fail(self):
  833. case_identifier = self._create_case()
  834. ioc_value = 'test'
  835. payload = {
  836. 'query': f'''mutation {{
  837. iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
  838. ioc {{ iocValue }}
  839. }}
  840. }}'''
  841. }
  842. self._subject.execute_graphql_query(payload)
  843. payload = {
  844. 'query': f'''mutation {{
  845. iocCreate(caseId: {case_identifier}, typeId: 2, tlpId: 1, value: "{ioc_value}") {{
  846. ioc {{ iocValue }}
  847. }}
  848. }}'''
  849. }
  850. self._subject.execute_graphql_query(payload)
  851. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "testtest") {{ ioc {{ iocValue }} }} }}'}
  852. self._subject.execute_graphql_query(payload)
  853. payload = {
  854. 'query': f'''{{
  855. case(caseId: {case_identifier}) {{
  856. iocs(iocValue: "{ioc_value}") {{ edges {{ node {{ iocValue iocId }} }} }} }}
  857. }}'''
  858. }
  859. body = self._subject.execute_graphql_query(payload)
  860. for ioc in body['data']['case']['iocs']['edges']:
  861. test_ioc_value = ioc['node']['iocValue']
  862. self.assertEqual(ioc_value, test_ioc_value)
  863. def test_graphql_iocs_filter_first_should_not_fail(self):
  864. case_identifier = self._create_case()
  865. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test2") {{ ioc {{ iocValue iocId }} }} }}'}
  866. response = self._subject.execute_graphql_query(payload)
  867. ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
  868. payload = {
  869. 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "testtest") {{ ioc {{ iocValue iocId }} }} }}'}
  870. self._subject.execute_graphql_query(payload)
  871. payload = {
  872. 'query': f'''{{
  873. case(caseId: {case_identifier}) {{
  874. iocs(first: 1) {{ edges {{ node {{ iocValue iocId }} }} }} }}
  875. }}'''
  876. }
  877. body = self._subject.execute_graphql_query(payload)
  878. for ioc in body['data']['case']['iocs']['edges']:
  879. iocid = ioc['node']['iocId']
  880. self.assertEqual(ioc_identifier, iocid)
  881. def test_graphql_iocs_filter_iocTypeId_should_not_fail(self):
  882. case_identifier = self._create_case()
  883. payload = {
  884. 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTypeId }} }} }}'}
  885. response = self._subject.execute_graphql_query(payload)
  886. ioc_type_id = response['data']['iocCreate']['ioc']['iocTypeId']
  887. payload = {
  888. 'query': f'''{{
  889. case(caseId: {case_identifier}) {{
  890. iocs(iocTypeId: {ioc_type_id}) {{ edges {{ node {{ iocTypeId }} }} }} }}
  891. }}'''
  892. }
  893. body = self._subject.execute_graphql_query(payload)
  894. for ioc in body['data']['case']['iocs']['edges']:
  895. test_type_id = ioc['node']['iocTypeId']
  896. self.assertEqual(test_type_id, ioc_type_id)
  897. def test_graphql_iocs_filter_iocDescription_should_not_fail(self):
  898. case_identifier = self._create_case()
  899. payload = {
  900. 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocDescription }} }} }}'}
  901. self._subject.execute_graphql_query(payload)
  902. description = 'Some description'
  903. payload = {
  904. 'query': f'''mutation {{
  905. iocUpdate(iocId: 1, description: "{description}", typeId:1, tlpId:1, value: "test") {{
  906. ioc {{ iocDescription }}
  907. }}
  908. }}'''
  909. }
  910. self._subject.execute_graphql_query(payload)
  911. payload = {
  912. 'query': f'''{{
  913. case(caseId: {case_identifier}) {{
  914. iocs(iocDescription: "{description}") {{ edges {{ node {{ iocDescription }} }} }} }}
  915. }}'''
  916. }
  917. body = self._subject.execute_graphql_query(payload)
  918. for ioc in body['data']['case']['iocs']['edges']:
  919. test_description = ioc['node']['iocDescription']
  920. self.assertEqual(test_description, description)
  921. def test_graphql_iocs_filter_iocTlpId_should_not_fail(self):
  922. case_identifier = self._create_case()
  923. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTlpId }} }} }}'}
  924. response = self._subject.execute_graphql_query(payload)
  925. ioc_tlp_id = response['data']['iocCreate']['ioc']['iocTlpId']
  926. payload = {
  927. 'query': f'''{{
  928. case(caseId: {case_identifier}) {{
  929. iocs(iocTlpId: {ioc_tlp_id}) {{ edges {{ node {{ iocTlpId }} }} }} }}
  930. }}'''
  931. }
  932. body = self._subject.execute_graphql_query(payload)
  933. for ioc in body['data']['case']['iocs']['edges']:
  934. test_tlp_id = ioc['node']['iocTlpId']
  935. self.assertEqual(test_tlp_id, ioc_tlp_id)
  936. def test_graphql_iocs_filter_iocTags_should_not_fail(self):
  937. case_identifier = self._create_case()
  938. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTags }} }} }}'}
  939. self._subject.execute_graphql_query(payload)
  940. tags = "test"
  941. payload = {
  942. 'query': f'''mutation {{
  943. iocUpdate(iocId: 1, description: "Some description", typeId:1, tlpId:1, value: "test",
  944. tags :"{tags}") {{
  945. ioc {{ iocTags }}
  946. }}
  947. }}'''
  948. }
  949. self._subject.execute_graphql_query(payload)
  950. payload = {
  951. 'query': f'''{{
  952. case(caseId: {case_identifier}) {{
  953. iocs(iocTags: "{tags}") {{ edges {{ node {{ iocTags }} }} }} }}
  954. }}'''
  955. }
  956. body = self._subject.execute_graphql_query(payload)
  957. for ioc in body['data']['case']['iocs']['edges']:
  958. test_tags = ioc['node']['iocTags']
  959. self.assertEqual(test_tags, tags)
  960. def test_graphql_iocs_filter_iocMisp_should_not_fail(self):
  961. case_identifier = self._create_case()
  962. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocMisp }} }} }}'}
  963. self._subject.execute_graphql_query(payload)
  964. misp = "test"
  965. payload = {
  966. 'query': f'''{{
  967. case(caseId: {case_identifier}) {{
  968. iocs(iocMisp: "{misp}") {{ edges {{ node {{ iocMisp }} }} }} }}
  969. }}'''
  970. }
  971. body = self._subject.execute_graphql_query(payload)
  972. for ioc in body['data']['case']['iocs']['edges']:
  973. test_misp = ioc['node']['iocMisp']
  974. self.assertNotEqual(test_misp, misp)
  975. def test_graphql_iocs_filter_userId_should_not_fail(self):
  976. case_identifier = self._create_case()
  977. payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ userId }} }} }}'}
  978. response = self._subject.execute_graphql_query(payload)
  979. user_id = response['data']['iocCreate']['ioc']['userId']
  980. payload = {
  981. 'query': f'''{{
  982. case(caseId: {case_identifier}) {{
  983. iocs(userId: {user_id}) {{ edges {{ node {{ userId }} }} }} }}
  984. }}'''
  985. }
  986. body = self._subject.execute_graphql_query(payload)
  987. for ioc in body['data']['case']['iocs']['edges']:
  988. test_user = ioc['node']['userId']
  989. self.assertEqual(test_user, user_id)
  990. def test_graphql_case_should_return_error_cases_query_when_permission_denied(self):
  991. user = self._subject.create_dummy_user()
  992. name = "cases_query_permission_denied"
  993. case_id = None
  994. payload = {
  995. 'query': f'''mutation {{
  996. caseCreate(name: "{name}", description: "Some description", clientId: 1) {{
  997. case {{ caseId }}
  998. }}
  999. }}'''
  1000. }
  1001. self._subject.execute_graphql_query(payload)
  1002. payload = {
  1003. 'query': f'''query {{ cases (name :"{name}")
  1004. {{ edges {{ node {{ caseId }} }} }} }}'''
  1005. }
  1006. body = user.execute_graphql_query(payload)
  1007. for case in body['data']['cases']['edges']:
  1008. test_case_id = case['node']['caseId']
  1009. self.assertEqual(case_id, test_case_id)
  1010. def test_graphql_case_should_return_success_cases_query(self):
  1011. user = self._subject.create_dummy_user()
  1012. name = 'cases_query_permission_denied'
  1013. payload = {
  1014. 'query': f'''mutation {{
  1015. caseCreate(name: "{name}", description: "Some description", clientId: 1) {{
  1016. case {{ caseId }}
  1017. }}
  1018. }}'''
  1019. }
  1020. body = user.execute_graphql_query(payload)
  1021. case_id = body['data']['caseCreate']['case']['caseId']
  1022. payload = {
  1023. 'query': f'''query {{ cases (name :"{name}")
  1024. {{ edges {{ node {{ caseId }} }} }} }}'''
  1025. }
  1026. body = user.execute_graphql_query(payload)
  1027. for case in body['data']['cases']['edges']:
  1028. test_case_id = case['node']['caseId']
  1029. self.assertEqual(case_id, test_case_id)
  1030. def test_graphql_case_should_work_with_tags(self):
  1031. payload = {
  1032. 'query': 'mutation { caseCreate(name: "test_case_tag", description: "Some description", clientId: 1) { case { caseId } } }'
  1033. }
  1034. body = self._subject.execute_graphql_query(payload)
  1035. case_identifier = body['data']['caseCreate']['case']['caseId']
  1036. payload = {
  1037. 'query': f'''mutation {{
  1038. caseUpdate(caseId: {case_identifier}, tags: "test_case_number1") {{
  1039. case {{ name }}
  1040. }}
  1041. }}'''
  1042. }
  1043. self._subject.execute_graphql_query(payload)
  1044. payload = {
  1045. 'query': 'query { cases (tags :"test_case_number1"){ edges { node { caseId } } } }'
  1046. }
  1047. body = self._subject.execute_graphql_query(payload)
  1048. for case in body['data']['cases']['edges']:
  1049. test_case_id = case['node']['caseId']
  1050. self.assertEqual(case_identifier, test_case_id)
  1051. def test_graphql_case_should_work_with_open_since(self):
  1052. payload = {
  1053. 'query': 'mutation {caseCreate(name: "test_case_open_since", description: "Some description", clientId: 1) { case { caseId } } } '
  1054. }
  1055. body = self._subject.execute_graphql_query(payload)
  1056. case_id = body['data']['caseCreate']['case']['caseId']
  1057. payload = {
  1058. 'query': 'query { cases (openSince: 0, name: "test_case_open_since") { edges { node { caseId initialDate openDate } } } }'
  1059. }
  1060. body = self._subject.execute_graphql_query(payload)
  1061. for case in body['data']['cases']['edges']:
  1062. test = case['node']['caseId']
  1063. self.assertEqual(test, case_id)