def test_create_audit(self, mock_gmp: GmpMockFactory): audit_id = str(uuid4()) policy_id = str(uuid4()) target_id = str(uuid4()) scanner_id = str(uuid4()) mock_gmp.mock_response( 'create_audit', f''' <create_task_response id="{audit_id}" status="200" status_text="OK"/> ''', ) self.login('foo', 'bar') response = self.query(f''' mutation {{ createAudit(input: {{ name: "bar", scannerId: "{scanner_id}", policyId: "{policy_id}", targetId: "{target_id}", scannerType: 2, hostsOrdering: "reverse", maxChecks: 7, maxHosts: 13, sourceIface: "foo", autoDelete: "keep", autoDeleteData: 4, inAssets: true, applyOverrides: false }}) {{ id }} }} ''') json = response.json() self.assertResponseNoErrors(response) uuid = json['data']['createAudit']['id'] self.assertEqual(uuid, audit_id) mock_gmp.gmp_protocol.create_audit.assert_called_with( "bar", policy_id, target_id, scanner_id, alert_ids=None, alterable=None, comment=None, hosts_ordering=get_hosts_ordering_from_string('reverse'), observers=None, preferences={ 'auto_delete': 'keep', 'auto_delete_data': 4, 'max_checks': 7, 'max_hosts': 13, 'source_iface': 'foo', 'in_assets': 'yes', 'assets_apply_overrides': 'no', }, schedule_id=None, schedule_periods=None, )
def mutate(root, info, input_object): name = input_object.name alterable = input_object.alterable schedule_periods = input_object.schedule_periods comment = input_object.comment if input_object.alert_ids is not None: alert_ids = [str(alert_id) for alert_id in input_object.alert_ids] else: alert_ids = None if input_object.observers is not None: observers = [str(observer) for observer in input_object.observers] else: observers = None schedule_id = (str(input_object.schedule_id) if input_object.schedule_id is not None else None) scanner_id = (str(input_object.scanner_id) if input_object.scanner_id is not None else None) target_id = (str(input_object.target_id) if input_object.target_id is not None else None) config_id = (str(input_object.config_id) if input_object.config_id is not None else None) if input_object.hosts_ordering is not None: hosts_ordering = get_hosts_ordering_from_string( input_object.hosts_ordering) else: hosts_ordering = None preferences = {} if input_object.apply_overrides is not None: preferences['assets_apply_overrides'] = ( "yes" if input_object.apply_overrides == 1 else "no") if input_object.min_qod is not None: preferences['assets_min_qod'] = input_object.min_qod if input_object.auto_delete is not None: preferences['auto_delete'] = input_object.auto_delete if input_object.auto_delete_data is not None: preferences['auto_delete_data'] = input_object.auto_delete_data if input_object.in_assets is not None: preferences['in_assets'] = ("yes" if input_object.in_assets == 1 else "no") if input_object.scanner_type == 2: if input_object.max_checks is not None: preferences['max_checks'] = input_object.max_checks if input_object.max_hosts is not None: preferences['max_hosts'] = input_object.max_hosts if input_object.source_iface is not None: preferences['source_iface'] = input_object.source_iface else: # config_id is required for create_task in python-gvm hosts_ordering = None gmp = get_gmp(info) resp = gmp.create_task( name, str(config_id), str(target_id), str(scanner_id), alterable=alterable, comment=comment, alert_ids=alert_ids, hosts_ordering=hosts_ordering, schedule_id=schedule_id, schedule_periods=schedule_periods, observers=observers, preferences=preferences, ) return CreateTask(task_id=resp.get('id'))
def mutate(root, info, input_object): audit_id = str(input_object.audit_id) name = input_object.name comment = input_object.comment schedule_periods = input_object.schedule_periods alterable = input_object.alterable if input_object.alert_ids is not None: alert_ids = [str(alert_id) for alert_id in input_object.alert_ids] else: alert_ids = None if input_object.observers is not None: observers = [str(observer) for observer in input_object.observers] else: observers = None schedule_id = (str(input_object.schedule_id) if input_object.schedule_id is not None else None) scanner_id = (str(input_object.scanner_id) if input_object.scanner_id is not None else None) target_id = (str(input_object.target_id) if input_object.target_id is not None else None) policy_id = (str(input_object.policy_id) if input_object.policy_id is not None else None) if input_object.hosts_ordering is not None: hosts_ordering = get_hosts_ordering_from_string( input_object.hosts_ordering) else: hosts_ordering = None preferences = {} if input_object.apply_overrides is not None: preferences['assets_apply_overrides'] = ( "yes" if input_object.apply_overrides == 1 else "no") if input_object.min_qod is not None: preferences['assets_min_qod'] = input_object.min_qod if input_object.auto_delete is not None: preferences['auto_delete'] = input_object.auto_delete if input_object.auto_delete_data is not None: preferences['auto_delete_data'] = input_object.auto_delete_data if input_object.in_assets is not None: preferences['in_assets'] = ("yes" if input_object.in_assets == 1 else "no") if input_object.scanner_type == 2: if input_object.max_checks is not None: preferences['max_checks'] = input_object.max_checks if input_object.max_hosts is not None: preferences['max_hosts'] = input_object.max_hosts if input_object.source_iface is not None: preferences['source_iface'] = input_object.source_iface else: policy_id = None hosts_ordering = None gmp = get_gmp(info) gmp.modify_audit( audit_id, name=name, policy_id=policy_id, target_id=target_id, scanner_id=scanner_id, alterable=alterable, hosts_ordering=hosts_ordering, schedule_id=schedule_id, schedule_periods=schedule_periods, comment=comment, alert_ids=alert_ids, observers=observers, preferences=preferences, ) return ModifyAudit(ok=True)
def test_modify_task(self, mock_gmp: GmpMockFactory): task_id = str(uuid4()) config_id = str(uuid4()) mock_gmp.mock_response( 'modify_task', ''' <modify_task_response status="200" status_text="OK"/> ''', ) self.login('foo', 'bar') response = self.query(f''' mutation {{ modifyTask(input: {{ id: "{task_id}", name: "bar" scannerType: 2, applyOverrides: false, inAssets: true, configId: "{config_id}", hostsOrdering: "reverse", maxChecks: 7, maxHosts: 13, sourceIface: "foo", autoDelete: "keep", autoDeleteData: 4 }}) {{ ok }} }} ''') json = response.json() self.assertResponseNoErrors(response) ok = json['data']['modifyTask']['ok'] self.assertEqual(ok, True) mock_gmp.gmp_protocol.modify_task.assert_called_with( str(task_id), alert_ids=None, alterable=None, comment=None, config_id=config_id, hosts_ordering=get_hosts_ordering_from_string('reverse'), name="bar", observers=None, preferences={ 'auto_delete': 'keep', 'auto_delete_data': 4, 'max_checks': 7, 'max_hosts': 13, 'source_iface': 'foo', 'assets_apply_overrides': 'no', 'in_assets': 'yes', }, scanner_id=None, schedule_id=None, schedule_periods=None, target_id=None, )