102 lines
4.1 KiB
Bash
102 lines
4.1 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
agent=/usr/local/bin/xtao-secret-agent
|
|
docker_bin=/usr/local/bin/docker
|
|
base=https://cloud.xtao.net
|
|
user=xtao-admin
|
|
work=$(mktemp -d /tmp/xtao-nextcloud-accept.XXXXXX)
|
|
cleanup() {
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
[ "$(id -u)" = "0" ] || { echo "FAIL must_run_as_root"; exit 1; }
|
|
[ -x "$agent" ] || { echo "FAIL missing_secret_agent"; exit 2; }
|
|
command -v curl >/dev/null || { echo "FAIL missing_curl"; exit 2; }
|
|
command -v python3 >/dev/null || { echo "FAIL missing_python3"; exit 2; }
|
|
|
|
netrc="$work/netrc"
|
|
{
|
|
printf 'machine cloud.xtao.net login '
|
|
"$agent" raw-field --entry infra/nextcloud/admin --field username
|
|
printf ' password '
|
|
"$agent" raw-field --entry infra/nextcloud/admin --field password
|
|
printf '\n'
|
|
} > "$netrc"
|
|
chmod 600 "$netrc"
|
|
|
|
status_json="$work/status.json"
|
|
curl -fsS "$base/status.php" -o "$status_json"
|
|
python3 - "$status_json" <<'PY'
|
|
import json, sys
|
|
data=json.load(open(sys.argv[1], encoding="utf-8"))
|
|
assert data["installed"] is True and data["maintenance"] is False and data["needsDbUpgrade"] is False
|
|
print("PASS status installed=true maintenance=false needsDbUpgrade=false")
|
|
PY
|
|
|
|
ts=$(date -u +%Y%m%dT%H%M%SZ)
|
|
small="phase03-small-$ts.bin"
|
|
large="phase03-large-$ts.bin"
|
|
dd if=/dev/urandom of="$work/$small" bs=1M count=2 status=none
|
|
sha256sum "$work/$small" > "$work/$small.sha256"
|
|
|
|
curl -fsS --netrc-file "$netrc" -T "$work/$small" "$base/remote.php/dav/files/$user/$small"
|
|
curl -fsS --netrc-file "$netrc" "$base/remote.php/dav/files/$user/$small" -o "$work/$small.download"
|
|
sha256sum -c "$work/$small.sha256" --ignore-missing >/dev/null
|
|
printf 'PASS webdav_upload_download file=%s size=2MiB\n' "$small"
|
|
|
|
share_json="$work/share.json"
|
|
curl -fsS --netrc-file "$netrc" \
|
|
-H 'OCS-APIRequest: true' \
|
|
-H 'Accept: application/json' \
|
|
-d "path=/$small" \
|
|
-d 'shareType=3' \
|
|
"$base/ocs/v2.php/apps/files_sharing/api/v1/shares" -o "$share_json"
|
|
share_url=$(python3 - "$share_json" <<'PY'
|
|
import json, sys
|
|
data=json.load(open(sys.argv[1], encoding="utf-8"))
|
|
meta=data["ocs"]["meta"]
|
|
if meta.get("statuscode") not in (100, 200):
|
|
print("FAIL share_meta " + json.dumps(meta, ensure_ascii=False), file=sys.stderr)
|
|
raise SystemExit(3)
|
|
print(data["ocs"]["data"]["url"])
|
|
PY
|
|
)
|
|
curl -fsSL "$share_url/download" -o "$work/$small.share-download"
|
|
cmp "$work/$small" "$work/$small.share-download"
|
|
printf 'PASS share_link_create_download file=%s\n' "$small"
|
|
|
|
for path in \
|
|
"/remote.php/dav/files/$user/" \
|
|
"/remote.php/dav/calendars/$user/" \
|
|
"/remote.php/dav/addressbooks/users/$user/"; do
|
|
code=$(curl -sS --netrc-file "$netrc" -o "$work/propf.out" -w '%{http_code}' -X PROPFIND -H 'Depth: 0' "$base$path")
|
|
[ "$code" = "207" ] || { echo "FAIL propfind path=$path code=$code"; exit 3; }
|
|
done
|
|
printf 'PASS webdav_caldav_carddav_propfind code=207\n'
|
|
|
|
for path in /.well-known/caldav /.well-known/carddav; do
|
|
code=$(curl -sS -o /dev/null -w '%{http_code}' -I "$base$path")
|
|
case "$code" in 301|302|307|308) ;; *) echo "FAIL well_known path=$path code=$code"; exit 3;; esac
|
|
done
|
|
printf 'PASS well_known_redirect caldav_carddav\n'
|
|
|
|
dd if=/dev/urandom of="$work/$large" bs=1M count=64 status=none
|
|
sha256sum "$work/$large" > "$work/$large.sha256"
|
|
set +e
|
|
timeout 1 curl -sS --netrc-file "$netrc" -T "$work/$large" "$base/remote.php/dav/files/$user/interrupted-$large" >/dev/null 2>&1
|
|
interrupted_rc=$?
|
|
set -e
|
|
case "$interrupted_rc" in 0|124|28) ;; *) echo "FAIL interrupted_transfer rc=$interrupted_rc"; exit 3;; esac
|
|
curl -fsS --netrc-file "$netrc" -T "$work/$large" "$base/remote.php/dav/files/$user/$large"
|
|
curl -fsS --netrc-file "$netrc" "$base/remote.php/dav/files/$user/$large" -o "$work/$large.download"
|
|
sha256sum -c "$work/$large.sha256" --ignore-missing >/dev/null
|
|
printf 'PASS large_file_and_interrupted_transfer size=64MiB interrupted_rc=%s\n' "$interrupted_rc"
|
|
|
|
"$docker_bin" exec -u www-data nextcloud-nextcloud-web-1 php -f /var/www/html/cron.php
|
|
lastcron=$("$docker_bin" exec -u www-data nextcloud-nextcloud-web-1 php occ config:app:get core lastcron)
|
|
[ -n "$lastcron" ] && [ "$lastcron" != "0" ] || { echo "FAIL cron_lastcron_empty"; exit 3; }
|
|
printf 'PASS cron_exec lastcron=%s\n' "$lastcron"
|
|
|
|
printf 'PASS nextcloud_functional_acceptance values=redacted\n'
|