From 56918ebf0b8c945b1aa86f3a9d6322f0d5763d43 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Fri, 29 Nov 2024 13:37:32 +0100 Subject: [PATCH] ci: Add ci job to run wopi-validator-core Signed-off-by: Julius Knorr --- .github/workflows/wopi.yml | 114 +++++++++++++++++++++++++++++++++++++ tests/wopi-test.sh | 40 +++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 .github/workflows/wopi.yml create mode 100755 tests/wopi-test.sh diff --git a/.github/workflows/wopi.yml b/.github/workflows/wopi.yml new file mode 100644 index 0000000000..f84ea0856f --- /dev/null +++ b/.github/workflows/wopi.yml @@ -0,0 +1,114 @@ +# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT +name: WOPI validator tests + +on: + pull_request: + push: + branches: + - main + - stable* + +env: + APP_NAME: richdocuments + +jobs: + changes: + runs-on: ubuntu-latest + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'templates/**' + - 'tests/**' + - 'vendor/**' + - 'vendor-bin/**' + - '.php-cs-fixer.dist.php' + - 'composer.json' + - 'composer.lock' + + sqlite: + runs-on: ubuntu-latest + + needs: changes + if: needs.changes.outputs.src != 'false' + + strategy: + # do not stop on another job's failure + fail-fast: false + matrix: + php-versions: ['8.1'] + server-versions: ['master'] + + name: wopi-${{ matrix.php-versions }}-${{ matrix.server-versions }} + + services: + collabora: + image: collabora/code:latest + env: + extra_params: '--o:ssl.enable=false' + aliasgroup1: 'http://nextcloud' + ports: + - "9980:9980" + + steps: + - name: Checkout server + uses: actions/checkout@v2 + with: + repository: nextcloud/server + ref: ${{ matrix.server-versions }} + + - name: Checkout submodules + shell: bash + run: | + auth_header="$(git config --local --get http.https://github.com/.extraheader)" + git submodule sync --recursive + git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 + + - name: Checkout app + uses: actions/checkout@v2 + with: + path: apps/${{ env.APP_NAME }} + + - name: Set up php ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: phpunit:8.5.14 + extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, gd, zip, apcu + ini-values: + apc.enable_cli=on + coverage: none + + - name: Set up Nextcloud + env: + DB_PORT: 4444 + run: | + mkdir data + echo '"\OC\Memcache\APCu","hashing_default_password"=>true];' > config/config.php + ./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin + ./occ config:system:set trusted_domains 1 --value=172.17.0.1 + ./occ app:enable --force ${{ env.APP_NAME }} + + # For now we require a some wopi server to be setup to generate a token + ./occ config:app:set richdocuments wopi_url --value="http://localhost:9980" + ./occ config:app:set richdocuments public_wopi_url --value="http://localhost:9980" + ./occ config:system:set allow_local_remote_servers --value true --type bool + ./occ richdocuments:activate-config + + + - name: Run WOPI validator tests + working-directory: apps/${{ env.APP_NAME }} + run: | + PHP_CLI_SERVER_WORKERS=10 php -S 172.17.0.1:8080 -t ../../ & + NEXTCLOUD_URL=http://172.17.0.1:8080 ./tests/wopi-test.sh diff --git a/tests/wopi-test.sh b/tests/wopi-test.sh new file mode 100755 index 0000000000..520bbfa9ba --- /dev/null +++ b/tests/wopi-test.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e +set -x + + +# current timestamp as filename +FILENAME=$(date +%s) + +NEXTCLOUD_URL=${NEXTCLOUD_URL:-http://nextcloud.local} +USERNAME=${USERNAME:-admin} +PASSWORD=${PASSWORD:-admin} +HOST_IP=${HOST_IP:-172.17.0.1} + +curl $NEXTCLOUD_URL/status.php --max-time 5 --retry 5 --retry-delay 0 --retry-max-time 30 --retry-connrefused + +curl -X PUT -u $USERNAME:$PASSWORD $NEXTCLOUD_URL/remote.php/webdav/$FILENAME.odt -s + +PROPFIND_RESULT=$(curl -X PROPFIND -u $USERNAME:$PASSWORD $NEXTCLOUD_URL/remote.php/webdav/$FILENAME.odt --data '' -s) +FILE_ID=$(echo $PROPFIND_RESULT | grep -ohE '(.*)' | cut -d'>' -f 2 | cut -d'<' -f 1) + +COOKIEJAR=/tmp/cookie-jar +rm -f $COOKIEJAR +CSRF_TOKEN=$(curl $NEXTCLOUD_URL/index.php/login --cookie-jar $COOKIEJAR -s | grep requesttoken | grep -ohE 'data-requesttoken="(.*)"' | cut -d'"' -f 2) + +echo "File id: $FILE_ID" +echo "CSRF token: $CSRF_TOKEN" + + +WOPI_TOKEN=$(curl -u $USERNAME:$PASSWORD --cookie-jar $COOKIEJAR $NEXTCLOUD_URL/index.php/apps/richdocuments/token?fileId=$FILE_ID -X POST -H "requesttoken: $CSRF_TOKEN" -s | jq -r .token) + +# Nextcloud needed a valid mimetype before ut the wopi test can only be ran with a .wopitest file +curl -X MOVE -u $USERNAME:$PASSWORD $NEXTCLOUD_URL/remote.php/webdav/$FILENAME.odt -H "Destination: $NEXTCLOUD_URL/remote.php/webdav/$FILENAME.wopitest" + +WOPI_URL="$NEXTCLOUD_URL/index.php/apps/richdocuments/wopi/files/$FILE_ID" + +echo "WOPI URL: $WOPI_URL" +echo "WOPI token generated: $WOPI_TOKEN" + +docker run --add-host nextcloud.local:${HOST_IP} --rm tylerbutler/wopi-validator -- -w $WOPI_URL -t $WOPI_TOKEN -l 0 "$@"