Skip to content

Commit

Permalink
feat: adds --dry-run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosantos15 committed Jun 25, 2021
1 parent bb75d5f commit bb11a55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 7 additions & 1 deletion mythx_cli/fuzz/faas.py
@@ -1,3 +1,4 @@
import json
import logging
import random
import string
Expand Down Expand Up @@ -54,7 +55,7 @@ def start_faas_campaign(self, payload):
raise e
raise RequestError(f"Error starting FaaS campaign.")

def create_faas_campaign(self, campaign_data, seed_state):
def create_faas_campaign(self, campaign_data, seed_state, dry_run = False):
"""Submit a campaign to the FaaS and start that campaign.
This function takes a FaaS payload and makes an HTTP request to the Faas backend, which
Expand Down Expand Up @@ -102,6 +103,11 @@ def create_faas_campaign(self, campaign_data, seed_state):
f"Error getting Scribble arming metadata."
) from e

if dry_run:
print("Printing output \n --------")
print(f"{json.dumps(api_payload)}")
print("End of output \n --------")
return "campaign not started due to --dry-run option"
campaign_id = self.start_faas_campaign(api_payload)

return campaign_id
Expand Down
24 changes: 16 additions & 8 deletions mythx_cli/fuzz/run.py
Expand Up @@ -57,7 +57,7 @@ def determine_ide() -> IDE:
"--corpus-target",
type=click.STRING,
help="Project UUID, Campaign UUID or Corpus UUID to reuse the corpus from. "
"In case of a project, corpus from the project's latest submitted campaign will be used",
"In case of a project, corpus from the project's latest submitted campaign will be used",
default=None,
required=False,
)
Expand All @@ -69,8 +69,16 @@ def determine_ide() -> IDE:
help="Map the analyses results to the original source code, instead of the instrumented one. "
"This is meant to be used with Scribble.",
)

@click.option(
"--dry-run",
is_flag=True,
default=False,
help="Outputs the data to be sent to the FaaS API without making the request.",
)

@click.pass_obj
def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source, target):
def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source, dry_run, target):
# read YAML config params from ctx dict, e.g. ganache rpc url
# Introduce a separate `fuzz` section in the YAML file

Expand Down Expand Up @@ -119,11 +127,11 @@ def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source
if not target:
target = analyze_config["targets"]
if not map_to_original_source:
map_to_original_source = (
analyze_config["map_to_original_source"]
if "map_to_original_source" in config_options
else default_config["map_to_original_source"]
)
map_to_original_source = (
analyze_config["map_to_original_source"]
if "map_to_original_source" in config_options
else default_config["map_to_original_source"]
)
# Optional config parameters
# Here we parse the config parameters from the config file and use defaults for non available values
contract_address = analyze_config["deployed_contract_address"]
Expand Down Expand Up @@ -193,7 +201,7 @@ def fuzz_run(ctx, address, more_addresses, corpus_target, map_to_original_source
)
try:
campaign_id = faas_client.create_faas_campaign(
campaign_data=artifacts, seed_state=seed_state
campaign_data=artifacts, seed_state=seed_state, dry_run=dry_run
)
click.echo(
"You can view campaign here: " + faas_url + "/campaigns/" + str(campaign_id)
Expand Down

0 comments on commit bb11a55

Please sign in to comment.