| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135 |
- # IRIS Source Code
- # Copyright (C) 2023 - DFIR-IRIS
- # contact@dfir-iris.org
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 3 of the License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software Foundation,
- # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- from unittest import TestCase
- from iris import Iris
- from iris import API_URL
- from graphql_api import GraphQLApi
- from base64 import b64encode
- class TestsGraphQL(TestCase):
- def setUp(self) -> None:
- self._subject = Iris()
- def tearDown(self):
- self._subject.clear_database()
- @staticmethod
- def _get_first_case(body):
- for case in body['data']['cases']['edges']:
- if case['node']['name'] == '#1 - Initial Demo':
- return case
- def _create_case(self):
- payload = {
- 'query': 'mutation { caseCreate(name: "case name", description: "Some description", clientId: 1) {case { caseId } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- return int(body['data']['caseCreate']['case']['caseId'])
- def test_graphql_endpoint_should_reject_requests_with_wrong_authentication_token(self):
- graphql_api = GraphQLApi(API_URL + '/graphql', 64 * '0')
- payload = {
- 'query': 'query { cases { edges { node { name } } } }'
- }
- response = graphql_api.execute(payload)
- self.assertEqual(401, response.status_code)
- def test_graphql_cases_should_contain_the_initial_case(self):
- payload = {
- 'query': 'query { cases { edges { node { name } } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- case_names = []
- for case in body['data']['cases']['edges']:
- case_names.append(case['node']['name'])
- self.assertIn('#1 - Initial Demo', case_names)
- def test_graphql_cases_should_have_a_global_identifier(self):
- payload = {
- 'query': 'query { cases { edges { node { id name } } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- first_case = self._get_first_case(body)
- self.assertEqual(b64encode(b'CaseObject:1').decode(), first_case['node']['id'])
- def test_graphql_create_ioc_should_not_fail(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocValue }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- test_ioc_value = response['data']['iocCreate']['ioc']['iocValue']
- self.assertEqual(test_ioc_value, ioc_value)
- def test_graphql_delete_ioc_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocDelete(iocId: {ioc_identifier}) {{
- message
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(f'IOC {int(ioc_identifier)} deleted', response['data']['iocDelete']['message'])
- def test_graphql_create_ioc_should_allow_optional_description_to_be_set(self):
- case_identifier = self._create_case()
- description = 'Some description'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
- description: "{description}") {{
- ioc {{ iocDescription }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(description, response['data']['iocCreate']['ioc']['iocDescription'])
- def test_graphql_create_ioc_should_allow_optional_tags_to_be_set(self):
- case_identifier = self._create_case()
- tags = 'tag1,tag2'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
- tags: "{tags}") {{
- ioc {{ iocTags }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(tags, response['data']['iocCreate']['ioc']['iocTags'])
- def test_graphql_update_ioc_should_update_tlp(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}") {{
- ioc {{ iocTlpId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(2, response['data']['iocUpdate']['ioc']['iocTlpId'])
- def test_graphql_update_ioc_should_not_update_typeId(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId iocTypeId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- ioc_type = response['data']['iocCreate']['ioc']['iocTypeId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, tlpId:1, value: "{ioc_value}") {{
- ioc {{ iocTypeId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(ioc_type, response['data']['iocUpdate']['ioc']['iocTypeId'])
- def test_graphql_update_ioc_should_fail_when_missing_iocId(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''mutation {{
- iocUpdate(typeId:1, tlpId:1, value: "{ioc_value}") {{
- ioc {{ iocTlpId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertIn('errors', response)
- def test_graphql_update_ioc_should_not_update_tlpId(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId iocTlpId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- ioc_tlp = response['data']['iocCreate']['ioc']['iocTlpId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId:1, value: "{ioc_value}") {{
- ioc {{ iocId iocTlpId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(ioc_tlp, response['data']['iocUpdate']['ioc']['iocTlpId'])
- def test_graphql_update_ioc_should_not_update_value(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
- ioc {{ iocId iocValue }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- ioc_value = response['data']['iocCreate']['ioc']['iocValue']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId:1, tlpId:1) {{
- ioc {{ iocValue }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(ioc_value, response['data']['iocUpdate']['ioc']['iocValue'])
- def test_graphql_update_ioc_should_update_optional_parameter_description(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- description = 'Some description'
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}",
- description: "{description}") {{
- ioc {{ iocDescription }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(description, response['data']['iocUpdate']['ioc']['iocDescription'])
- def test_graphql_update_ioc_should_update_optional_parameter_tags(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- tags = 'tag1,tag2'
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, value: "{ioc_value}",
- tags: "{tags}") {{
- ioc {{ iocTags }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(tags, response['data']['iocUpdate']['ioc']['iocTags'])
- def test_graphql_case_should_return_a_case_by_its_identifier(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- caseId
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(case_identifier, response['data']['case']['caseId'])
- def test_graphql_iocs_should_return_all_iocs_of_a_case(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs {{ edges {{ node {{ iocId }} }} }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertNotIn('errors', response)
- def test_graphql_case_should_return_error_log_uuid_when_permission_denied(self):
- user = self._subject.create_dummy_user()
- case_identifier = self._create_case()
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- caseId
- }}
- }}'''
- }
- response = user.execute_graphql_query(payload)
- self.assertRegex(response['errors'][0]['message'], r'Permission denied \(EID [0-9a-f-]{36}\)')
- def test_graphql_case_should_return_error_ioc_when_permission_denied(self):
- user = self._subject.create_dummy_user()
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
- ioc {{ iocId iocValue }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs {{ totalCount edges {{ node {{ iocId }} }} }}
- }}
- }}'''
- }
- response = user.execute_graphql_query(payload)
- self.assertIn('errors', response)
- def test_graphql_create_case_should_not_fail(self):
- test_description = 'Some description'
- payload = {'query': f''' mutation {{ caseCreate(name: "case2", description: "{test_description}", clientId: 1) {{ case {{ description }} }} }} '''}
- body = self._subject.execute_graphql_query(payload)
- description = body['data']['caseCreate']['case']['description']
- self.assertEqual(description, test_description)
- def test_graphql_update_case_fail_due_to_delete_case(self):
- payload = {
- 'query': '''mutation {
- caseCreate(name: "case2", description: "Some description", clientId: 1) {
- case { caseId }
- }
- }'''
- }
- response = self._subject.execute_graphql_query(payload)
- case_identifier = response['data']['caseCreate']['case']['caseId']
- payload2 = {
- 'query': f'''mutation {{
- caseDelete(caseId: {case_identifier}) {{
- case {{ caseId }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload2)
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, name: "test_delete_case") {{
- case {{ name }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertIn('errors', body)
- def test_graphql_delete_case_should_fail(self):
- payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1) { case { caseId } } }'}
- response = self._subject.execute_graphql_query(payload)
- case_identifier = response['data']['caseCreate']['case']['caseId']
- payload2 = {
- 'query': f'''mutation {{
- caseDelete(caseId: {case_identifier}, cur_id: 1) {{
- case {{ caseId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload2)
- self.assertIn('errors', body)
- def test_graphql_update_case_should_not_fail(self):
- case_identifier = self._create_case()
- test_name = 'new name'
- expected_name = f'#{case_identifier} - new name'
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, name: "{test_name}") {{
- case {{ name }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- name = body['data']['caseUpdate']['case']['name']
- self.assertEqual(name, expected_name)
- def test_graphql_create_case_should_use_optionals_parameters(self):
- id_client = 1
- payload = {
- 'query': f''' mutation {{
- caseCreate(name: "case2", description: "Some description", clientId: {id_client},
- socId: "1", classificationId : 1) {{
- case {{ clientId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- client_id = body['data']['caseCreate']['case']['clientId']
- self.assertEqual(client_id, id_client)
- def test_graphql_update_case_should_use_optionals_parameters(self):
- id_case = 1
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {id_case}, description: "Some description", clientId: 1, socId: "1",
- classificationId : 1) {{
- case {{ caseId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- case_id = body['data']['caseUpdate']['case']['caseId']
- self.assertEqual(case_id, id_case)
- def test_graphql_cases_should_return_newly_created_case(self):
- payload = {
- 'query': ''' mutation { caseCreate(name: "case2", description: "Some description", clientId: 1) {
- case { caseId }
- }
- }'''
- }
- response = self._subject.execute_graphql_query(payload)
- case_identifier = response['data']['caseCreate']['case']['caseId']
- payload = {
- 'query': 'query { cases { edges { node { caseId } } } }'
- }
- response = self._subject.execute_graphql_query(payload)
- case_identifiers = []
- for case in response['data']['cases']['edges']:
- case_identifiers.append(case['node']['caseId'])
- self.assertIn(case_identifier, case_identifiers)
- def test_graphql_update_case_should_update_optional_parameter_description(self):
- payload = {
- 'query': ''' mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
- classificationId : 1) {
- case { caseId }
- }
- }'''
- }
- body = self._subject.execute_graphql_query(payload)
- case_identifier = body['data']['caseCreate']['case']['caseId']
- description = 'Some description'
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, description: "{description}") {{
- case {{ description }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(description, response['data']['caseUpdate']['case']['description'])
- def test_graphql_update_case_should_update_optional_parameter_socId(self):
- payload = {
- 'query': ''' mutation {
- caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
- classificationId : 1) {
- case { caseId }
- }
- }'''
- }
- body = self._subject.execute_graphql_query(payload)
- case_identifier = body['data']['caseCreate']['case']['caseId']
- soc_id = '17'
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, socId: "{soc_id}") {{
- case {{ socId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(soc_id, response['data']['caseUpdate']['case']['socId'])
- def test_graphql_update_case_should_update_optional_parameter_classificationId(self):
- payload = {
- 'query': ''' mutation {
- caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1",
- classificationId : 1) {
- case { caseId }
- }
- }'''
- }
- body = self._subject.execute_graphql_query(payload)
- case_identifier = body['data']['caseCreate']['case']['caseId']
- classification_id = 2
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, classificationId: {classification_id}) {{
- case {{ classificationId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(2, response['data']['caseUpdate']['case']['classificationId'])
- def test_graphql_update_case_with_optional_parameter_severityId(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ caseUpdate(caseId: {case_identifier}, severityId: 1) {{ case {{ severityId }} }} }}'}
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, body['data']['caseUpdate']['case']['severityId'])
- def test_graphql_update_case_with_optional_parameter_ownerId(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, ownerId: 1) {{
- case {{ ownerId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, body['data']['caseUpdate']['case']['ownerId'])
- def test_graphql_update_case_with_optional_parameter_stateId_reviewerId(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, reviewerId: 1) {{
- case {{ reviewerId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, body['data']['caseUpdate']['case']['reviewerId'])
- def test_graphql_update_case_with_optional_parameter_stateId(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, stateId: 1) {{
- case {{ stateId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, body['data']['caseUpdate']['case']['stateId'])
- def test_graphql_update_case_with_optional_parameter_reviewStatusId(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, reviewStatusId: 1) {{
- case {{ reviewStatusId }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, body['data']['caseUpdate']['case']['reviewStatusId'])
- def test_graphql_query_ioc_should_not_fail(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''query {{
- ioc(iocId: {ioc_identifier}) {{ iocValue }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- self.assertEqual(ioc_value, body['data']['ioc']['iocValue'])
- def test_graphql_cases_should_not_fail(self):
- test_name = '#1 - Initial Demo'
- payload = {
- 'query': '{ cases(first: 1) { edges { node { id name } } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- name = case['node']['name']
- self.assertEqual(test_name, name)
- def test_graphql_update_ioc_should_update_misp(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, iocMisp: "test",
- value: "{ioc_value}") {{
- ioc {{ iocMisp }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual("test", response['data']['iocUpdate']['ioc']['iocMisp'])
- def test_graphql_update_ioc_should_update_userId(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, userId: 1, value: "{ioc_value}") {{
- ioc {{ userId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual(1, response['data']['iocUpdate']['ioc']['userId'])
- def test_graphql_update_ioc_should_update_iocEnrichment(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, iocEnrichment: "test",
- value: "{ioc_value}") {{
- ioc {{ iocEnrichment }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual('"test"', response['data']['iocUpdate']['ioc']['iocEnrichment'])
- def test_graphql_update_ioc_should_update_modificationHistory(self):
- case_identifier = self._create_case()
- ioc_value = 'IOC value'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocId }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: {ioc_identifier}, typeId: 1, tlpId: 2, modificationHistory: "test",
- value: "{ioc_value}") {{
- ioc {{ modificationHistory }}
- }}
- }}'''
- }
- response = self._subject.execute_graphql_query(payload)
- self.assertEqual('"test"', response['data']['iocUpdate']['ioc']['modificationHistory'])
- def test_cursor_first_after(self):
- payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
- 'caseId }}'}
- self._subject.execute_graphql_query(payload)
- case_id = 2
- self._subject.execute_graphql_query(payload)
- payload = {'query': 'query { cases { edges { node { caseId name } cursor } } }'}
- self._subject.execute_graphql_query(payload)
- payload = {'query': 'query { cases(first:1, after:"YXJyYXljb25uZWN0aW9uOjA="){ edges { node { caseId } cursor } } }'}
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_case_id = case['node']['caseId']
- self.assertEqual(case_id, test_case_id)
- def test_graphql_cases_classificationId_should_not_fail(self):
- classification_id = 1
- payload = {
- 'query': f'''mutation {{ caseCreate(name: "case1", description: "Some description", clientId: 1, socId: "1",
- classificationId : {classification_id}) {{ case {{ caseId }} }}}}'''}
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 3) {case { caseId '
- 'classificationId}}}'}
- self._subject.execute_graphql_query(payload)
- payload = {'query': f'''mutation {{ caseCreate(name: "case3", description: "Some description", clientId: 1, socId: "1", classificationId :
- {classification_id}) {{ case {{ classificationId }} }} }}'''}
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''query {{ cases(classificationId: {classification_id} )
- {{ edges {{ node {{ name caseId classificationId }} cursor }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_classification = case['node']['classificationId']
- self.assertEqual(classification_id, test_classification)
- def test_graphql_cases_filter_clientId_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
- 'clientId }}}'}
- response = self._subject.execute_graphql_query(payload)
- client_id = response['data']['caseCreate']['case']['clientId']
- payload = {
- 'query': f'''query {{ cases(clientId: {client_id}) {{ edges {{ node {{ clientId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_client = case['node']['clientId']
- self.assertEqual(client_id, test_client)
- def test_graphql_cases_filter_stateId_should_not_fail(self):
- payload = {'query': 'mutation {caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
- 'stateId }}}'}
- response = self._subject.execute_graphql_query(payload)
- state_id = response['data']['caseCreate']['case']['stateId']
- payload = {
- 'query': f'''query {{ cases(stateId: {state_id})
- {{ edges {{ node {{ stateId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_state = case['node']['stateId']
- self.assertEqual(state_id, test_state)
- def test_graphql_cases_filter_ownerId_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
- 'ownerId }}}'}
- response = self._subject.execute_graphql_query(payload)
- owner_id = response['data']['caseCreate']['case']['ownerId']
- payload = {
- 'query': f'''query {{ cases(ownerId: {owner_id})
- {{ edges {{ node {{ ownerId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_owner = case['node']['ownerId']
- self.assertEqual(owner_id, test_owner)
- def test_graphql_cases_filter_openDate_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
- 'openDate clientId } } }'}
- response = self._subject.execute_graphql_query(payload)
- open_date = response['data']['caseCreate']['case']['openDate']
- clientId = response['data']['caseCreate']['case']['clientId']
- payload = {
- 'query': f'''query {{ cases(openDate: "{open_date}")
- {{ edges {{ node {{ openDate clientId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_id = case['node']['clientId']
- self.assertEqual(clientId, test_id)
- def test_graphql_cases_filter_name_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) {case { '
- 'name }}}'}
- response = self._subject.execute_graphql_query(payload)
- name = response['data']['caseCreate']['case']['name']
- payload = {
- 'query': f'''query {{ cases(name: "{name}")
- {{ edges {{ node {{ name }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_name = case['node']['name']
- self.assertEqual(name, test_name)
- def test_graphql_cases_filter_socId_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
- 'socId } } }'}
- response = self._subject.execute_graphql_query(payload)
- soc_id = response['data']['caseCreate']['case']['socId']
- payload = {
- 'query': f'''query {{ cases(socId: "{soc_id}")
- {{ edges {{ node {{ socId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_soc_id = case['node']['socId']
- self.assertEqual(soc_id, test_soc_id)
- def test_graphql_cases_filter_severityId_should_not_fail(self):
- payload = {'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { '
- 'severityId }} }'}
- response = self._subject.execute_graphql_query(payload)
- severity_id = response['data']['caseCreate']['case']['severityId']
- payload = {
- 'query': f'''query {{ cases(severityId: {severity_id})
- {{ edges {{ node {{ severityId }} }} }} }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_severity = case['node']['severityId']
- self.assertEqual(severity_id, test_severity)
- def test_graphql_cases_parameter_totalCount_should_not_fail(self):
- payload = {
- 'query': 'query { cases { totalCount } }'
- }
- body = self._subject.execute_graphql_query(payload)
- test_total = body['data']['cases']['totalCount']
- payload = {
- 'query': 'mutation { caseCreate(name: "case2", description: "Some description", clientId: 1, socId: "1", classificationId : 1) { case { name } }}'}
- self._subject.execute_graphql_query(payload)
- test_total += 1
- payload = {
- 'query': 'query { cases { totalCount } }'
- }
- body = self._subject.execute_graphql_query(payload)
- total = body['data']['cases']['totalCount']
- self.assertEqual(total, test_total)
- def test_graphql_iocs_filter_iocId_should_not_fail(self):
- case_identifier = self._create_case()
- query = f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "33") {{ ioc {{ iocId }} }} }}'
- payload = {'query': query}
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {'query': f'{{ case(caseId: {case_identifier}) {{ iocs(iocId: 11) {{ edges {{ node {{ iocId }} }} }} }} }}'}
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_ioc_identifier = ioc['node']['iocId']
- self.assertEqual(ioc_identifier, test_ioc_identifier)
- def test_graphql_iocs_filter_iocUuid_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "33") {{ ioc {{ iocUuid iocId }} }} }}'}
- response = self._subject.execute_graphql_query(payload)
- ioc_uuid = response['data']['iocCreate']['ioc']['iocUuid']
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocUuid: "{ioc_uuid}") {{ edges {{ node {{ iocId iocUuid }} }} }}
- }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_ioc_uuid = ioc['node']['iocUuid']
- self.assertEqual(ioc_uuid, test_ioc_uuid)
- def test_graphql_iocs_filter_iocValue_should_not_fail(self):
- case_identifier = self._create_case()
- ioc_value = 'test'
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocValue }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''mutation {{
- iocCreate(caseId: {case_identifier}, typeId: 2, tlpId: 1, value: "{ioc_value}") {{
- ioc {{ iocValue }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "testtest") {{ ioc {{ iocValue }} }} }}'}
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocValue: "{ioc_value}") {{ edges {{ node {{ iocValue iocId }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_ioc_value = ioc['node']['iocValue']
- self.assertEqual(ioc_value, test_ioc_value)
- def test_graphql_iocs_filter_first_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test2") {{ ioc {{ iocValue iocId }} }} }}'}
- response = self._subject.execute_graphql_query(payload)
- ioc_identifier = response['data']['iocCreate']['ioc']['iocId']
- payload = {
- 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "testtest") {{ ioc {{ iocValue iocId }} }} }}'}
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(first: 1) {{ edges {{ node {{ iocValue iocId }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- iocid = ioc['node']['iocId']
- self.assertEqual(ioc_identifier, iocid)
- def test_graphql_iocs_filter_iocTypeId_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTypeId }} }} }}'}
- response = self._subject.execute_graphql_query(payload)
- ioc_type_id = response['data']['iocCreate']['ioc']['iocTypeId']
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocTypeId: {ioc_type_id}) {{ edges {{ node {{ iocTypeId }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_type_id = ioc['node']['iocTypeId']
- self.assertEqual(test_type_id, ioc_type_id)
- def test_graphql_iocs_filter_iocDescription_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {
- 'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocDescription }} }} }}'}
- self._subject.execute_graphql_query(payload)
- description = 'Some description'
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: 1, description: "{description}", typeId:1, tlpId:1, value: "test") {{
- ioc {{ iocDescription }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocDescription: "{description}") {{ edges {{ node {{ iocDescription }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_description = ioc['node']['iocDescription']
- self.assertEqual(test_description, description)
- def test_graphql_iocs_filter_iocTlpId_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTlpId }} }} }}'}
- response = self._subject.execute_graphql_query(payload)
- ioc_tlp_id = response['data']['iocCreate']['ioc']['iocTlpId']
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocTlpId: {ioc_tlp_id}) {{ edges {{ node {{ iocTlpId }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_tlp_id = ioc['node']['iocTlpId']
- self.assertEqual(test_tlp_id, ioc_tlp_id)
- def test_graphql_iocs_filter_iocTags_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocTags }} }} }}'}
- self._subject.execute_graphql_query(payload)
- tags = "test"
- payload = {
- 'query': f'''mutation {{
- iocUpdate(iocId: 1, description: "Some description", typeId:1, tlpId:1, value: "test",
- tags :"{tags}") {{
- ioc {{ iocTags }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocTags: "{tags}") {{ edges {{ node {{ iocTags }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_tags = ioc['node']['iocTags']
- self.assertEqual(test_tags, tags)
- def test_graphql_iocs_filter_iocMisp_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ iocMisp }} }} }}'}
- self._subject.execute_graphql_query(payload)
- misp = "test"
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(iocMisp: "{misp}") {{ edges {{ node {{ iocMisp }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_misp = ioc['node']['iocMisp']
- self.assertNotEqual(test_misp, misp)
- def test_graphql_iocs_filter_userId_should_not_fail(self):
- case_identifier = self._create_case()
- payload = {'query': f'mutation {{ iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "test") {{ ioc {{ userId }} }} }}'}
- response = self._subject.execute_graphql_query(payload)
- user_id = response['data']['iocCreate']['ioc']['userId']
- payload = {
- 'query': f'''{{
- case(caseId: {case_identifier}) {{
- iocs(userId: {user_id}) {{ edges {{ node {{ userId }} }} }} }}
- }}'''
- }
- body = self._subject.execute_graphql_query(payload)
- for ioc in body['data']['case']['iocs']['edges']:
- test_user = ioc['node']['userId']
- self.assertEqual(test_user, user_id)
- def test_graphql_case_should_return_error_cases_query_when_permission_denied(self):
- user = self._subject.create_dummy_user()
- name = "cases_query_permission_denied"
- case_id = None
- payload = {
- 'query': f'''mutation {{
- caseCreate(name: "{name}", description: "Some description", clientId: 1) {{
- case {{ caseId }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': f'''query {{ cases (name :"{name}")
- {{ edges {{ node {{ caseId }} }} }} }}'''
- }
- body = user.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_case_id = case['node']['caseId']
- self.assertEqual(case_id, test_case_id)
- def test_graphql_case_should_return_success_cases_query(self):
- user = self._subject.create_dummy_user()
- name = 'cases_query_permission_denied'
- payload = {
- 'query': f'''mutation {{
- caseCreate(name: "{name}", description: "Some description", clientId: 1) {{
- case {{ caseId }}
- }}
- }}'''
- }
- body = user.execute_graphql_query(payload)
- case_id = body['data']['caseCreate']['case']['caseId']
- payload = {
- 'query': f'''query {{ cases (name :"{name}")
- {{ edges {{ node {{ caseId }} }} }} }}'''
- }
- body = user.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_case_id = case['node']['caseId']
- self.assertEqual(case_id, test_case_id)
- def test_graphql_case_should_work_with_tags(self):
- payload = {
- 'query': 'mutation { caseCreate(name: "test_case_tag", description: "Some description", clientId: 1) { case { caseId } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- case_identifier = body['data']['caseCreate']['case']['caseId']
- payload = {
- 'query': f'''mutation {{
- caseUpdate(caseId: {case_identifier}, tags: "test_case_number1") {{
- case {{ name }}
- }}
- }}'''
- }
- self._subject.execute_graphql_query(payload)
- payload = {
- 'query': 'query { cases (tags :"test_case_number1"){ edges { node { caseId } } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test_case_id = case['node']['caseId']
- self.assertEqual(case_identifier, test_case_id)
- def test_graphql_case_should_work_with_open_since(self):
- payload = {
- 'query': 'mutation {caseCreate(name: "test_case_open_since", description: "Some description", clientId: 1) { case { caseId } } } '
- }
- body = self._subject.execute_graphql_query(payload)
- case_id = body['data']['caseCreate']['case']['caseId']
- payload = {
- 'query': 'query { cases (openSince: 0, name: "test_case_open_since") { edges { node { caseId initialDate openDate } } } }'
- }
- body = self._subject.execute_graphql_query(payload)
- for case in body['data']['cases']['edges']:
- test = case['node']['caseId']
- self.assertEqual(test, case_id)
|