Skip to content

Commit

Permalink
Fix failing unittests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinenar committed Aug 7, 2024
1 parent 9bcb81b commit 15efb51
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/ostorlab/serve_app/oxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
from graphene_file_upload import scalars
from graphql.execution import base as graphql_base

from ostorlab import configuration_manager
from ostorlab import exceptions
from ostorlab.assets import android_aab as android_aab_asset
from ostorlab.assets import android_apk as android_apk_asset
from ostorlab.assets import android_store as android_store_asset
from ostorlab.assets import asset as ostorlab_asset
from ostorlab.assets import domain_name as domain_name_asset
from ostorlab.assets import ios_ipa as ios_ipa_asset
from ostorlab.assets import ios_store as ios_store_asset
from ostorlab.assets import ipv4 as ipv4_address_asset
from ostorlab.assets import ipv6 as ipv6_address_asset
from ostorlab.assets import link as link_asset
from ostorlab.cli import agent_fetcher, install_agent
from ostorlab.runtimes import definitions
from ostorlab.utils import defintions as utils_definitions
from ostorlab.runtimes.local import runtime
from ostorlab import configuration_manager
from ostorlab.runtimes.local import runtime as local_runtime
from ostorlab.runtimes.local.models import models
from ostorlab.serve_app import common, export_utils
from ostorlab.serve_app import import_utils
from ostorlab.serve_app import types
from ostorlab.runtimes.local import runtime as local_runtime
from ostorlab.assets import android_apk as android_apk_asset
from ostorlab.assets import android_aab as android_aab_asset
from ostorlab.assets import ios_ipa as ios_ipa_asset
from ostorlab.assets import android_store as android_store_asset
from ostorlab.assets import ios_store as ios_store_asset
from ostorlab.assets import ipv4 as ipv4_address_asset
from ostorlab.assets import ipv6 as ipv6_address_asset
from ostorlab.assets import link as link_asset
from ostorlab.assets import domain_name as domain_name_asset
from ostorlab.assets import asset as ostorlab_asset
from ostorlab.utils import defintions as utils_definitions

DEFAULT_NUMBER_ELEMENTS = 15

Expand Down Expand Up @@ -793,6 +793,10 @@ def mutate(
scan_assets = RunScanMutation._prepare_assets(scan.asset_ids)

runtime_instance: runtime.LocalRuntime = runtime.LocalRuntime()
try:
runtime_instance.can_run(agent_group_definition=agent_group)
except exceptions.OstorlabError as e:
raise graphql.GraphQLError(f"Runtime encountered an error to run scan: {e}")
runtime_instance.follow = []
created_scan = runtime_instance.prepare_scan(
assets=scan_assets, title=scan.title
Expand Down Expand Up @@ -837,33 +841,24 @@ def _run_scan_background(
scan: types.OxoAgentScanInputType,
scan_assets: List[ostorlab_asset.Asset],
) -> None:
"""Run scan in background.
"""Run scan in the background.
Args:
runtime_instance: The runtime instance.
agent_group: The agent group.
scan: The scan information.
scan_assets: The scan assets.
"""

try:
can_run_scan = runtime_instance.can_run(agent_group_definition=agent_group)
except exceptions.OstorlabError as e:
raise graphql.GraphQLError(f"Runtime encountered an error to run scan: {e}")

if can_run_scan is True:
RunScanMutation._install_agents(agent_group, runtime_instance)
try:
runtime_instance.scan(
title=scan.title,
agent_group_definition=agent_group,
assets=scan_assets,
)
runtime_instance.scan(
title=scan.title,
agent_group_definition=agent_group,
assets=scan_assets,
)

except exceptions.OstorlabError as e:
raise graphql.GraphQLError(
f"Runtime encountered an error to run scan: {e}"
)
except exceptions.OstorlabError as e:
raise graphql.GraphQLError(f"Runtime encountered an error to run scan: {e}")


class Mutations(graphene.ObjectType):
Expand Down

0 comments on commit 15efb51

Please sign in to comment.