Skip to content

Commit f7af459

Browse files
Add fetchZAPResults.sh script to download ZAP reports from a URL.
Adds a shell script that downloads a ZAP XML report from a remote ZAP instance via its REST API and saves it to the results/ directory. This enables scorecard generation when ZAP and Benchmark run in separate Docker containers without a shared filesystem. Closes #21
1 parent b7b159c commit f7af459

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

scripts/fetchZAPResults.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# Downloads a ZAP XML report from a URL and saves it to the results/ directory.
4+
# After downloading, run createScorecards.sh to generate the scorecard.
5+
#
6+
# Usage: scripts/fetchZAPResults.sh <ZAP_REPORT_URL> [OUTPUT_FILENAME]
7+
#
8+
# Examples:
9+
# scripts/fetchZAPResults.sh http://172.17.0.3:8090/OTHER/core/other/xmlreport/
10+
# scripts/fetchZAPResults.sh "http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123"
11+
# scripts/fetchZAPResults.sh http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml
12+
13+
source scripts/requireCommand.sh
14+
15+
requireCommand curl
16+
17+
if [ $# -eq 0 ]; then
18+
echo "Usage: $0 <ZAP_REPORT_URL> [OUTPUT_FILENAME]"
19+
echo ""
20+
echo "Downloads a ZAP XML report from the given URL and saves it to results/."
21+
echo "After downloading, run createScorecards.sh to generate the scorecard."
22+
echo ""
23+
echo "Examples:"
24+
echo " $0 http://172.17.0.3:8090/OTHER/core/other/xmlreport/"
25+
echo " $0 \"http://zap:8090/OTHER/core/other/xmlreport/?apikey=abc123\""
26+
echo " $0 http://zap:8090/OTHER/core/other/xmlreport/ my-zap-results.xml"
27+
exit 1
28+
fi
29+
30+
zap_url="$1"
31+
32+
if [ $# -ge 2 ]; then
33+
filename="$2"
34+
else
35+
benchmark_version=$(scripts/getBenchmarkVersion.sh)
36+
date_stamp=$(date +%Y%m%d)
37+
filename="Benchmark_${benchmark_version}-ZAP-${date_stamp}.xml"
38+
fi
39+
40+
output="results/${filename}"
41+
42+
echo "Downloading ZAP report from: ${zap_url}"
43+
http_code=$(curl -sS -o "${output}" -w '%{http_code}' --connect-timeout 10 --max-time 120 "${zap_url}")
44+
45+
if [ "${http_code}" -ne 200 ]; then
46+
echo "ERROR: Download failed with HTTP status ${http_code}"
47+
rm -f "${output}"
48+
exit 1
49+
fi
50+
51+
if ! head -2 "${output}" | grep -q "OWASPZAPReport"; then
52+
echo "ERROR: Downloaded file does not appear to be a ZAP XML report."
53+
echo "First 3 lines of downloaded content:"
54+
head -3 "${output}"
55+
rm -f "${output}"
56+
exit 1
57+
fi
58+
59+
echo "ZAP report saved to: ${output}"
60+
echo "To generate the scorecard, run: ./createScorecards.sh"

0 commit comments

Comments
 (0)