Skip to content

Commit 358d64d

Browse files
committed
build: Add OpenAPI fuzzer script
Signed-off-by: provokateurin <[email protected]>
1 parent eda72da commit 358d64d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,5 @@ cypress/snapshots
186186
cypress/videos
187187

188188
/.direnv
189+
190+
/.hypothesis/

build/openapi-fuzzer.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
4+
# SPDX-License-Identifier: AGPL-3.0-or-later
5+
6+
set -euo pipefail
7+
8+
if [ "$#" -ne 2 ]; then
9+
echo "Usage ./build/openapi-fuzzer.sh <user> <path/to/openapi.json>"
10+
exit 1
11+
fi
12+
13+
user="$1"
14+
spec="$(readlink -f "$2")"
15+
16+
python -m venv venv
17+
source venv/bin/activate
18+
pip install schemathesis==4.1.4
19+
20+
rm data config/config.php -rf
21+
22+
./occ maintenance:install --admin-pass admin
23+
./occ config:system:set auth.bruteforce.protection.enabled --value=false --type=boolean
24+
25+
app="$(echo "$spec" | pcregrep -o1 -e "^.+\/apps[^\/]*\/([a-z_]+)\/openapi[a-z-]*\.json$" || echo "")"
26+
if [[ "$app" != "" ]]; then
27+
./occ app:enable "$app"
28+
fi
29+
30+
if [[ "$user" != "admin" ]]; then
31+
is_password_policy_available="$(./occ app:list --output json | jq -r .enabled.password_policy)"
32+
33+
if [[ "$is_password_policy_available" != "null" ]]; then
34+
./occ app:disable password_policy
35+
fi
36+
37+
NC_PASS="$user" ./occ user:add "$user" --password-from-env
38+
39+
if [[ "$is_password_policy_available" != "null" ]]; then
40+
./occ app:enable password_policy
41+
fi
42+
fi
43+
44+
app_password="$(echo "$user" | ./occ user:auth-tokens:add "$user" | tail -n 1)"
45+
46+
# Ensure enough workers will be available to handle all requests
47+
NEXTCLOUD_WORKERS=100 composer serve &> /dev/null &
48+
pid=$!
49+
function cleanup() {
50+
kill "$pid"
51+
}
52+
trap cleanup EXIT
53+
54+
until curl -s -o /dev/null http://localhost:8080/status.php; do sleep 1s; done
55+
56+
schemathesis run \
57+
"$spec" \
58+
--checks all \
59+
--exclude-checks missing_required_header,unsupported_method \
60+
--workers auto \
61+
--url http://localhost:8080 \
62+
-H "OCS-APIRequest: true" \
63+
-H "Accept: application/json" \
64+
-H "Authorization: Bearer $app_password"

0 commit comments

Comments
 (0)