|
| 1 | +# flake8: noqa |
| 2 | + |
| 3 | +import sys |
| 4 | +import time |
| 5 | +from os import path |
| 6 | + |
| 7 | +from graphqler.__main__ import run_compile_mode, run_fuzz_mode |
| 8 | + |
| 9 | +from graphqler import config |
| 10 | +import multiprocessing |
| 11 | + |
| 12 | + |
| 13 | +# Dictionary specifying the API URL and path |
| 14 | +APIS_TO_TEST = [ |
| 15 | + ("https://countries.trevorblades.com/", "ablation-test-oob/countries-test/"), |
| 16 | + ("https://api.react-finland.fi/graphql", "ablation-test-oob/react-finland-test/"), |
| 17 | + ("https://rickandmortyapi.com/graphql", "ablation-test-oob/rick-and-morty-test/"), |
| 18 | + ("https://graphqlzero.almansi.me/api", "ablation-test-oob/graphql-zero-test/"), |
| 19 | + ("https://graphql.anilist.co/", "ablation-test-oob/anilist-test"), |
| 20 | + ("https://portal.ehri-project.eu/api/graphql", "ablation-test-oob/ehri-test/"), |
| 21 | + ("https://www.universe.com/graphql", "ablation-test-oob/universe-test"), |
| 22 | + ("https://beta.pokeapi.co/graphql/v1beta", "ablation-test-oob/pokeapi-test"), |
| 23 | + ("https://hivdb.stanford.edu/graphql", "ablation-test-oob/hivdb-test"), |
| 24 | + ("https://api.tcgdex.net/v2/graphql", "ablation-test-oob/tcgdex-test/"), |
| 25 | + # ('http://localhost:4000/graphql', 'benchmark-tests/user-wallet-test/'), |
| 26 | + # ("https://api.spacex.land/graphql/", "spacex-test/"), |
| 27 | + # ('http://localhost:4000/graphql', 'benchmark-tests/food-delivery-test/') |
| 28 | + # ('https://graphql.anilist.co/', 'benchmark-tests/anilist-test/'), |
| 29 | + # ('https://www.universe.com/graphql', 'benchmark-tests/universe-test/'), |
| 30 | + # ('https://beta.pokeapi.co/graphql/v1beta', 'benchmark-tests/pokeapi-test/'), |
| 31 | + # ('http://localhost:3000/', 'benchmark-tests/json-graphql-server/'), |
| 32 | +] |
| 33 | + |
| 34 | +# MAX_TIMES = [5, 10, 20, 30, 60] |
| 35 | +MAX_TIMES = [60] |
| 36 | +NUM_RETRIES = 1 |
| 37 | + |
| 38 | +# Set the constants |
| 39 | +config.USE_OBJECTS_BUCKET = True |
| 40 | +config.USE_DEPENDENCY_GRAPH = False |
| 41 | +config.NO_DATA_COUNT_AS_SUCCESS = False |
| 42 | +config.SKIP_DOS_ATTACKS = True |
| 43 | +config.SKIP_MISC_ATTACKS = True |
| 44 | +config.SKIP_INJECTION_ATTACKS = True |
| 45 | +config.SKIP_MAXIMAL_PAYLOADS = True |
| 46 | +config.DEBUG = False |
| 47 | +# config.TIME_BETWEEN_REQUESTS = 0.5 |
| 48 | + |
| 49 | + |
| 50 | +# Run the command multiple times |
| 51 | +def run_api(api_to_test): |
| 52 | + api_name = api_to_test[1] |
| 53 | + api_url = api_to_test[0] |
| 54 | + for max_time in MAX_TIMES: |
| 55 | + output_path = f"{api_name}/{max_time}/" |
| 56 | + is_success = False |
| 57 | + num_tries = 0 |
| 58 | + while is_success is False and num_tries < NUM_RETRIES: |
| 59 | + try: |
| 60 | + print(f"Running the API {api_name} with path {output_path} and max time {max_time}") |
| 61 | + config.MAX_TIME = max_time |
| 62 | + run_compile_mode(output_path, api_url) |
| 63 | + run_fuzz_mode(output_path, api_url) |
| 64 | + is_success = True |
| 65 | + except Exception as e: |
| 66 | + print(e) |
| 67 | + num_tries += 1 |
| 68 | + config.TIME_BETWEEN_REQUESTS = 0.1 * num_tries |
| 69 | + time.sleep(10 * num_tries) |
| 70 | + if is_success is False: |
| 71 | + # Getting here means the API failed to run through retries |
| 72 | + print(f"Error running the API {api_name} with path {output_path} and max time {max_time}") |
| 73 | + |
| 74 | + |
| 75 | +# Run each of the APIs in parallel |
| 76 | +if __name__ == "__main__": |
| 77 | + processes = [] |
| 78 | + for api_to_test in APIS_TO_TEST: |
| 79 | + p = multiprocessing.Process(target=run_api, args=(api_to_test,)) |
| 80 | + processes.append(p) |
| 81 | + p.start() |
| 82 | + |
| 83 | + for process in processes: |
| 84 | + process.join() |
0 commit comments