# Wait for testing to complete if api fuzzer is scanning
# Start API Fuzzing provided worker if no other worker present
-if [ "$FUZZAPI_HAR$FUZZAPI_OPENAPI" != "" ]; then echo "Waiting for API Fuzzer to exit"; docker wait apifuzzer; fi
-|
if [ "$FUZZAPI_D_WORKER_IMAGE" == "" ]; then \
docker run \
--name worker \
--network $FUZZAPI_D_NETWORK \
-e TZ=America/Los_Angeles \
-e FUZZAPI_API=http://apifuzzer:80 \
-e FUZZAPI_PROJECT \
-e FUZZAPI_PROFILE \
-e FUZZAPI_CONFIG \
-e FUZZAPI_REPORT \
-e FUZZAPI_HAR \
-e FUZZAPI_OPENAPI \
-e FUZZAPI_TARGET_URL \
-e FUZZAPI_OVERRIDES_FILE \
-e FUZZAPI_OVERRIDES_ENV \
-e FUZZAPI_OVERRIDES_CMD \
-e FUZZAPI_OVERRIDES_INTERVAL \
-e FUZZAPI_TIMEOUT \
-e FUZZAPI_VERBOSE \
-e FUZZAPI_SERVICE_START_TIMEOUT \
-e FUZZAPI_HTTP_USERNAME \
-e FUZZAPI_HTTP_PASSWORD \
-v $CI_PROJECT_DIR:/app \
-p 81:80 \
-p 8001:8000 \
-p 515:514 \
--restart=no \
$FUZZAPI_IMAGE \
worker-entry \
; fi
#
#
# Propagate exit code from api fuzzer (if any)
# Propagate exit code from api fuzzing scanner (if any)
-if [[ $(docker inspect apifuzzer --format='{{.State.ExitCode}}') != "0" ]]; then echo "API Fuzzing exited with an error. Logs are available as job artifacts."; docker logs apifuzzer; exit 1; fi
-if [[ $(docker inspect apifuzzer --format='{{.State.ExitCode}}') != "0" ]]; then echo "API Fuzzing scanner exited with an error. Logs are available as job artifacts."; exit 1; fi
#
#
# Run user provided pre-script
# Run user provided post-script
-sh -c "$FUZZAPI_POST_SCRIPT"
-sh -c "$FUZZAPI_POST_SCRIPT"
#
#
after_script:
after_script:
...
@@ -129,13 +204,13 @@ apifuzzer_fuzz:
...
@@ -129,13 +204,13 @@ apifuzzer_fuzz:
# Shutdown all containers
# Shutdown all containers
-echo "Stopping all containers"
-echo "Stopping all containers"
-if [ "$FUZZAPI_D_TARGET_IMAGE" != "" ]; then docker stop target; fi
-if [ "$FUZZAPI_D_TARGET_IMAGE" != "" ]; then docker stop target; fi
-if [ "$FUZZAPI_D_WORKER_IMAGE" != "" ]; then docker stop worker; fi
-docker stop worker
-docker stop apifuzzer
-docker stop apifuzzer
#
#
# Save docker logs
# Save docker logs
-docker logs apifuzzer &> gl-api_fuzzing-logs.log
-docker logs apifuzzer &> gl-api_fuzzing-logs.log
-if [ "$FUZZAPI_D_TARGET_IMAGE" != "" ]; then docker logs target &> gl-api_fuzzing-target-logs.log; fi
-if [ "$FUZZAPI_D_TARGET_IMAGE" != "" ]; then docker logs target &> gl-api_fuzzing-target-logs.log; fi
-if [ "$FUZZAPI_D_WORKER_IMAGE" != "" ]; then docker logs worker &> gl-api_fuzzing-worker-logs.log; fi