Skip to content

Commit 6dc15a9

Browse files
committed
build: Add OpenAPI fuzzer script
Signed-off-by: provokateurin <[email protected]>
1 parent e8aacb5 commit 6dc15a9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
4+
# SPDX-License-Identifier: AGPL-3.0-or-later
5+
6+
set -euo pipefail
7+
8+
user="$1"
9+
spec="$2"
10+
11+
python -m venv venv
12+
source venv/bin/activate
13+
pip install schemathesis==4.1.3
14+
15+
rm data config/config.php -rf
16+
17+
./occ maintenance:install --admin-pass admin
18+
./occ config:system:set auth.bruteforce.protection.enabled --value=false --type=boolean
19+
20+
if [[ "$user" != "admin" ]]; then
21+
./occ app:disable password_policy
22+
NC_PASS="$user" ./occ user:add "$user" --password-from-env
23+
fi
24+
25+
app_password="$(echo "$user" | ./occ user:auth-tokens:add "$user" | tail -n 1)"
26+
27+
# Ensure enough workers will be available to handle all requests
28+
NEXTCLOUD_WORKERS=100 composer serve &> /dev/null &
29+
pid=$!
30+
function cleanup() {
31+
kill "$pid"
32+
}
33+
trap cleanup EXIT
34+
35+
until curl -s -o /dev/null http://localhost:8080/status.php; do sleep 1s; done
36+
37+
schemathesis run \
38+
"$spec" \
39+
--checks all \
40+
--exclude-checks missing_required_header,unsupported_method \
41+
--workers auto \
42+
--url http://localhost:8080 \
43+
-H "OCS-APIRequest: true" \
44+
-H "Accept: application/json" \
45+
-H "Authorization: Bearer $app_password"

0 commit comments

Comments
 (0)