From 67c93f70b7447e1b2505b50fe643ca16422e2e49 Mon Sep 17 00:00:00 2001 From: Valina Li Date: Tue, 16 May 2023 11:31:00 -0700 Subject: [PATCH] feat: add fuzzing core-data dockerfile and script Closes: issue #4568 Signed-off-by: Valina Li --- .gitignore | 2 ++ Dockerfile.fuzz | 16 ++++++++++++++++ fuzzing_docker.sh | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 Dockerfile.fuzz create mode 100755 fuzzing_docker.sh diff --git a/.gitignore b/.gitignore index eccbd71e12..02372b71c2 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ stage/* snap/.snapcraft/* squashfs-root/ +# result files +fuzz_results/* \ No newline at end of file diff --git a/Dockerfile.fuzz b/Dockerfile.fuzz new file mode 100644 index 0000000000..df72cb9f0e --- /dev/null +++ b/Dockerfile.fuzz @@ -0,0 +1,16 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine as builder + +RUN apk add --no-cache python3 py3-pip bash + +RUN wget https://github.com/microsoft/restler-fuzzer/archive/refs/tags/v9.2.0.tar.gz +RUN tar -xvf v9.2.0.tar.gz && mv restler-fuzzer-9.2.0 restler-fuzzer + +RUN cd restler-fuzzer; mkdir -p restler_bin +WORKDIR /restler-fuzzer +RUN python3 ./build-restler.py --dest_dir ./restler_bin/ + +COPY fuzzing_docker.sh /restler-fuzzer/fuzzing.sh +COPY /openapi/v3/core-data.yaml /restler-fuzzer/ + +ENTRYPOINT ["/restler-fuzzer/fuzzing.sh"] +CMD ["core-data", "/restler-fuzzer", "core-data.yaml"] \ No newline at end of file diff --git a/fuzzing_docker.sh b/fuzzing_docker.sh new file mode 100755 index 0000000000..88433be9e3 --- /dev/null +++ b/fuzzing_docker.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +EDGEX_PROJECT_NAME=${1} +echo $EDGEX_PROJECT_NAME +SWAGGER_FILE_PATH=${2} +echo $SWAGGER_FILE_PATH +SWAGGER_FILE_NAME=${3} +echo $SWAGGER_FILE_NAME + +echo "--compile from swagger file" +./restler_bin/restler/Restler compile --api_spec /$SWAGGER_FILE_PATH/$SWAGGER_FILE_NAME + +echo "--test the grammar" +./restler_bin/restler/Restler test --grammar_file ./Compile/grammar.py --dictionary_file ./Compile/dict.json --settings ./Compile/engine_settings.json --no_ssl + +# assuming edgex service is already running on host +echo "--run fuzz-lean" +./restler_bin/restler/Restler fuzz-lean --grammar_file ./Compile/grammar.py --dictionary_file ./Compile/dict.json --settings ./Compile/engine_settings.json --no_ssl + +echo "--copy result logs into $EDGEX_PROJECT_NAME" +mkdir -p /fuzz_result/$EDGEX_PROJECT_NAME +cp -r ./Test/RestlerResults/ /fuzz_results/$EDGEX_PROJECT_NAME/