This gist will describe how to run Restler with the Test Recording Proxy to capture service traffic that that later be validated by the Swagger Accuracy tooling.
We'll use the Azure App Configuration service in this example but the concepts should generalize to any Azure service.
git clone https://github.com/microsoft/restler-fuzzer.git
restler_bin=~/bin/restler
mkdir -p $restler_bin
# Need --python because it can’t find “python” — I use an alias that it did not understand.
python ./build-restler.py --dest_dir $restler_bin --python_path /opt/homebrew/bin/python3
dotnet tool update azure.sdk.tools.testproxy --global --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json --version "1.0.0-dev*"
This will install to ~/.dotnet/tools
. You need to add this to your path if not done previously.
Lets try Azure Databricks.
specs=$(find /Users/mikekistler/Projects/Azure/azure-rest-api-specs/specification/databricks/resource-manager/Microsoft.Databricks/preview/2022-04-01-preview -type f -depth 1)
dotnet $restler_bin/restler/Restler.dll generate_config --specs ${=specs}
vars='{
"subscriptionId": ["my-subscription-id"],
"resourceGroupName": ["my-resource-group"],
"location": ["my-location"]
}'
jq ".restler_custom_payload = $vars" restlerConfig/dict.json > dict.json
Also set:
"api-version": [
"2022-04-01-preview"
]
Add the host and port for the test-proxy to the RESTler engine settings. This will send traffic to the recorder.
jq '.host = "localhost" | .target_port = 5000 | .no_ssl: true' restlerConfig/engine_settings.json > engine_settings.json
We need to update config.json CustomDictionaryFilePath
to point to our modified dict.json and
AnnotationFilePath
to point to our annotations.json:
jq '.CustomDictionaryFilePath = "dict.json" | del(.AnnotationFilePath) | .DataFuzzing = false' restlerConfig/config.json > config.json
Compile using this base configuration. This is just to make sure there are no issues to this point.
dotnet $restler_bin/restler/Restler.dll compile config.json
In a separate terminal window/tab, start the test proxy with the location to save recordings.
test-proxy --storage-location c:\recordings
From your test session window, start a recording session with a request to the proxy.
The response of this request will contain an "x-recording-id" header. Save the value in recording_id
variable.
body='{ "x-recording-file": "databricks" }'
recording_id=$(curl -X POST -s -D - -d $body http://localhost:5000/Record/Start | grep 'x-recording-id' | awk '{print $2}' | sed 's/\r$//')
header='{
"x-recording-upstream-base-uri": ["https://management.azure.com"],
"x-recording-id": ["'${recording_id}'"],
"x-recording-mode": ["record"]
}'
jq ".restler_custom_payload_header = $header" dict.json > tmp.json && mv tmp.json dict.json
And recompile to incorporate these changes.
dotnet $restler_bin/restler/Restler.dll compile config.json
Now you are ready to run the Test phase of Restler.
dotnet $restler_bin/restler/Restler.dll test --dictionary_file Compile/dict.json --grammar_file Compile/grammar.py --settings Compile/engine_settings.json --token_refresh_command "bash $PWD/getToken.sh" --token_refresh_interval 60
Send the following request to the test proxy:
curl -X POST -D - -H "x-recording-id: ${recording_id}" -H 'Content-Length: 0' http://localhost:5000/Record/Stop