Skip to content

Commit

Permalink
Merge pull request #153 from GDATASoftwareAG/main
Browse files Browse the repository at this point in the history
Release v30
  • Loading branch information
lennartdohmann authored Oct 23, 2024
2 parents 9a989b5 + 4461e14 commit 88b789d
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 74 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/edouard-lopez/devcontainer-features/bats:0": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/wxw-matt/devcontainer-features/apt:latest": {
"packages": "bash-completion vim iputils-ping telnet"
}
}
}
19 changes: 12 additions & 7 deletions .devcontainer/postCreateCommands.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash

sudo apt-get update
sudo apt-get install -y bash-completion vim iputils-ping telnet
echo "setup php-scoper"
composer global require humbug/php-scoper
$(composer config home)/vendor/bin/php-scoper completion bash >> $HOME.bash_completion
echo "export PATH=$(composer config home)/vendor/bin/:\$PATH" >> $HOME/.bashrc
export PATH=$(composer config home)/vendor/bin/:$PATH

sudo cp memory.ini /usr/local/etc/php/conf.d/memory.ini

if [[ "$IS_CI" == "true" ]]; then
exit 0
fi

sudo bash -c "docker completion bash > /usr/share/bash-completion/completions/docker"
sudo bash -c "composer completion bash > /usr/share/bash-completion/completions/composer"
sudo bash -c "npm completion > /usr/share/bash-completion/completions/npm"
sudo cp xdebug.local.ini /usr/local/etc/php/conf.d/xdebug.ini
sudo cp memory.ini /usr/local/etc/php/conf.d/memory.ini
sudo curl -sS https://webi.sh/gh | sh

echo ". /usr/share/bash-completion/bash_completion" >> /home/vscode/.bashrc

Expand All @@ -21,7 +29,4 @@ git clone --depth 1 --recurse-submodules --single-branch --branch v$NEXTCLOUD_VE
cd nextcloud-server
git submodule update --init
cd -
composer global require humbug/php-scoper
/home/vscode/.composer/vendor/bin/php-scoper completion bash >> /home/vscode/.bash_completion
echo 'export PATH=/home/vscode/.composer/vendor/bin/:$PATH' >>~/.bashrc
./install.sh
54 changes: 40 additions & 14 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Build and Test

defaults:
run:
shell: bash
on:
push:
branches: ["main"]
Expand All @@ -17,23 +20,47 @@ jobs:
- id: get-matrix
run: echo "nextcloud_versions=$(./get-matrix.sh)" | tee -a "$GITHUB_OUTPUT"

build-devcontainer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pre-build dev container image
uses: devcontainers/[email protected]
with:
imageName: ghcr.io/gdatasoftwareag/nextcloud/builder
cacheFrom: ghcr.io/gdatasoftwareag/nextcloud/builder
push: always

test:
runs-on: ubuntu-latest
needs: define-matrix
container:
image: ghcr.io/gdatasoftwareag/nextcloud/builder:latest
env:
IS_CI: true
options: --name nextcloud-antivirus-build-container
needs:
- define-matrix
- build-devcontainer
strategy:
matrix:
nextcloud_version: ${{fromJson(needs.define-matrix.outputs.nextcloud_versions)}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
name: setup node
with:
node-version: 20

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.11.0
- name: postCreateCommands
run: |
source .devcontainer/postCreateCommands.sh
- name: add composer bin to path
run: |
echo $(composer config home --global)/vendor/bin >> $GITHUB_PATH
echo "/home/vscode/bin/" >> $GITHUB_PATH
- name: replace version in ./appinfo/info.xml
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -42,11 +69,6 @@ jobs:
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
sed -i "s/<version>0.0.0<\/version>/<version>$RELEASE_VERSION<\/version>/g" ./appinfo/info.xml
- uses: docker-practice/actions-setup-docker@master
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: unittests
env:
CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }}
Expand All @@ -66,6 +88,10 @@ jobs:
CLIENT_SECRET: ${{ secrets.VAAS_CLIENT_SECRET }}
run: ./install.sh ${{ matrix.nextcloud_version }} 1

- name: add builder into nextcloud network
run: |
docker network connect nextcloud-gdata-antivirus_nextcloud-network nextcloud-antivirus-build-container
- name: run tests
id: bats-tests
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ core.1
nextcloud-server/
core-dump.zip
apache/
**/vendor/*
**/vendor/*
test.sh
4 changes: 3 additions & 1 deletion Dockerfile.Nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ ARG INSTALL_XDEBUG=1

FROM nextcloud:${NEXTCLOUD_VERSION}

RUN apt update && apt install -y \
SHELL [ "/bin/bash", "-c" ]

RUN apt-get -q update && apt-get -q install -y \
less vim telnet iputils-ping gdb libexpat1-dev libapr1-dev libaprutil1-dev devscripts debmake \
bison jdupes libbrotli-dev liblua5.4-dev libnghttp2-dev libssl-dev libxml2-dev libcurl4-openssl-dev libjansson-dev
# RUN curl -L -o /tmp/apache2_2.4.61.orig.tar.gz https://launchpad.net/debian/+archive/primary/+sourcefiles/apache2/2.4.61-1/apache2_2.4.61.orig.tar.gz \
Expand Down
2 changes: 1 addition & 1 deletion compose-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- smtp
restart: unless-stopped
networks:
- nextcloud-network
nextcloud-network:
smtp:
image: rnwood/smtp4dev:v3
container_name: smtp
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nextcloud/ocp": "v30.0.0",
"psalm/phar": "5.26.1",
"nextcloud/coding-standard": "v1.3.1",
"phpunit/phpunit": "10.5.35",
"phpunit/phpunit": "10.5.36",
"symfony/console": "6.4.12"
},
"autoload": {
Expand Down
Empty file added foobar.json
Empty file.
10 changes: 7 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

export NEXTCLOUD_VERSION=${1:-30.0.0}
export INSTALL_XDEBUG=${2:-1}
Expand All @@ -12,7 +13,7 @@ setup_nextcloud () {
docker compose -f compose-install.yaml rm --force --stop --volumes
docker compose -f compose-install.yaml up --build --quiet-pull --wait -d --force-recreate --renew-anon-volumes --remove-orphans

docker exec -i nextcloud-container ulimit -c unlimited
docker exec -i nextcloud-container bash -c 'ulimit -c unlimited'
docker exec -i nextcloud-container bash -c 'echo "/tmp/apache2-coredump/core-%e-%s-%u-%g-%p-%t" > /proc/sys/kernel/core_pattern'

until docker exec --user www-data -i nextcloud-container php occ status | grep "installed: false"
Expand All @@ -35,6 +36,7 @@ setup_nextcloud () {
docker exec --user www-data -i nextcloud-container php occ app:disable firstrunwizard
docker exec --user www-data -i nextcloud-container php occ app:disable weather_status
docker exec --user www-data -i nextcloud-container php occ config:system:set trusted_domains 2 --value=192.168.5.80
docker exec --user www-data -i nextcloud-container php occ config:system:set trusted_domains 3 --value=nextcloud-container

echo "setup nextcloud finished"
}
Expand All @@ -43,7 +45,7 @@ build_app () {
echo "build app"
make distclean
make appstore
tar -xf ./build/artifacts/gdatavaas.tar.gz -C ./build/artifacts
tar -xf ./build/artifacts/gdatavaas.tar.gz -C ./build/artifacts
echo "build app finished"
}

Expand All @@ -53,8 +55,10 @@ if [ -z "$CLIENT_ID" ] || [ -z "$CLIENT_SECRET" ]; then
fi

setup_nextcloud &
setup_nextcloud_pid=$!
build_app &
wait
wait %2 || exit 1
wait %1 || exit 1

docker cp ./build/artifacts/gdatavaas nextcloud-container:/var/www/html/apps/
docker exec -i nextcloud-container chown -R www-data:www-data /var/www/html/apps/gdatavaas
Expand Down
31 changes: 19 additions & 12 deletions lib/Db/DbFileMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
use OCP\IDBConnection;

class DbFileMapper extends QBMapper {
private string $stringType;

public function __construct(IDBConnection $db) {
parent::__construct($db, 'filecache');
$this->stringType = $this->getStringTypeDeclarationSQL();
}

/**
Expand All @@ -26,11 +29,15 @@ public function getFileIdsWithoutTags(array $excludedTagIds, int $limit, int $of

$qb->select('f.fileid')
->from($this->getTableName(), 'f')
->leftJoin('f', 'systemtag_object_mapping', 'o', $qb->expr()->eq('f.fileid', $qb->createFunction($this->getPlatformSpecificCast())))
->leftJoin('f', 'systemtag_object_mapping', 'o', $qb->expr()->eq('o.objectid', $qb->createFunction(sprintf('CAST(f.fileid AS %s)', $this->stringType))))
->leftJoin('f', 'mimetypes', 'm', $qb->expr()->eq('f.mimetype', 'm.id'))
->where($qb->expr()->notIn('o.systemtagid', $qb->createNamedParameter($excludedTagIds, IQueryBuilder::PARAM_INT_ARRAY)))
->orWhere($qb->expr()->isNull('o.systemtagid'))
->andWhere($qb->expr()->notLike('m.mimetype', $qb->createNamedParameter('%unix-directory%')))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('o.objecttype', $qb->createNamedParameter('files')),
$qb->expr()->isNull('o.objecttype')
))
->andWhere($qb->expr()->orX(
$qb->expr()->like('f.path', $qb->createNamedParameter('files/%')),
$qb->expr()->like('f.path', $qb->createNamedParameter('__groupfolders/%'))
Expand Down Expand Up @@ -61,10 +68,11 @@ public function getFileIdsWithTags(array $includedTagIds, int $limit, int $offse

$qb->select('f.fileid')
->from($this->getTableName(), 'f')
->leftJoin('f', 'systemtag_object_mapping', 'o', $qb->expr()->eq('f.fileid', $qb->createFunction($this->getPlatformSpecificCast())))
->leftJoin('f', 'systemtag_object_mapping', 'o', $qb->expr()->eq('o.objectid', $qb->createFunction(sprintf('CAST(f.fileid AS %s)', $this->stringType))))
->leftJoin('f', 'mimetypes', 'm', $qb->expr()->eq('f.mimetype', 'm.id'))
->where($qb->expr()->in('o.systemtagid', $qb->createNamedParameter($includedTagIds, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->notLike('m.mimetype', $qb->createNamedParameter('%unix-directory%')))
->andWhere($qb->expr()->eq('o.objecttype', $qb->createNamedParameter('files')))
->andWhere($qb->expr()->orX(
$qb->expr()->like('f.path', $qb->createNamedParameter('files/%')),
$qb->expr()->like('f.path', $qb->createNamedParameter('__groupfolders/%'))
Expand All @@ -82,22 +90,21 @@ public function getFileIdsWithTags(array $includedTagIds, int $limit, int $offse
}

/**
* Create a platform-specific cast function
* @return string the database platform-specific cast function
* Get the DB type for a string
* @return string the database string type
* @throws Exception if the database platform is not supported
*/
private function getPlatformSpecificCast(): string {
private function getStringTypeDeclarationSQL(): string {
$platform = $this->db->getDatabaseProvider();
if ($platform === 'mysql') {
$cast = 'CAST(' . 'o.objectid' . ' AS UNSIGNED)';
} elseif ($platform === 'sqlite') {
$cast = 'CAST(' . 'o.objectid' . ' AS INTEGER)';
} elseif ($platform === 'postgres') {
$cast = 'CAST(' . 'o.objectid' . ' AS BIGINT)';
if ($platform === "mysql") {
$stringType = 'CHAR(64)';
}
else if ($platform === 'sqlite' || $platform === 'postgres') {
$stringType = 'VARCHAR(64)';
} else {
throw new Exception('Unsupported database platform: ' . $platform);
}
return $cast;
return $stringType;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/bats/.env-test
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#!/bin/bash

if [[ "$IS_CI" == "true" ]]; then
export HOSTNAME=nextcloud-container
else
export HOSTNAME=127.0.0.1
fi

if [[ "$IS_CI" == "true" ]]; then
export MAIL_HOSTNAME=smtp
else
export MAIL_HOSTNAME=127.0.0.1:8001
fi

export FOLDER_PREFIX=./tmp/functionality-parallel
export TESTUSER=testuser
export TESTUSER_PASSWORD=myfancysecurepassword234
Expand Down
24 changes: 12 additions & 12 deletions tests/bats/functionality-parallel.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setup_file() {

@test "test admin eicar Upload" {
EICAR_LENGTH=$(echo $EICAR_STRING | wc -c)
RESULT=$(echo $EICAR_STRING | curl -v -X PUT -d"$EICAR_STRING" -w "%{http_code}" -u admin:admin -T - http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt || echo "curl failed")
RESULT=$(echo $EICAR_STRING | curl -v -X PUT -d"$EICAR_STRING" -w "%{http_code}" -u admin:admin -T - http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt || echo "curl failed")

if [[ "$RESULT" =~ "curl failed" ]]; then
echo "debugging stuff"
Expand All @@ -38,12 +38,12 @@ setup_file() {
fi

echo "Actual: $RESULT"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt || echo "file not found"
curl --silent -q -u admin:admin -X DELETE http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt || echo "file not found"
[[ "$RESULT" =~ "Upload cannot be completed." ]]
}

@test "test admin clean upload" {
RESULT=$(echo $CLEAN_STRING | curl -w "%{http_code}" -u admin:admin -T - http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.clean.txt || echo "curl failed")
RESULT=$(echo $CLEAN_STRING | curl -w "%{http_code}" -u admin:admin -T - http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.clean.txt || echo "curl failed")

if [[ "$RESULT" =~ "curl failed" ]]; then
echo "debugging stuff"
Expand All @@ -61,36 +61,36 @@ setup_file() {
fi

echo "Actual: $RESULT"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.clean.txt || echo "file not found"
curl --silent -q -u admin:admin -X DELETE http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.clean.txt || echo "file not found"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test admin pup Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T $FOLDER_PREFIX/pup.exe http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.pup.exe)
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T $FOLDER_PREFIX/pup.exe http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.pup.exe)
echo "Actual: $RESULT"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.pup.exe || echo "file not found"
curl --silent -q -u admin:admin -X DELETE http://$HOSTNAME/remote.php/dav/files/admin/functionality-parallel.pup.exe || echo "file not found"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test testuser eicar Upload" {
RESULT=$(echo $EICAR_STRING | curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt)
RESULT=$(echo $EICAR_STRING | curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt)
echo "Actual: $RESULT"
$DOCKER_EXEC_WITH_USER -i nextcloud-container php occ config:app:get gdatavaas clientSecret
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt || echo "file not found"
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt || echo "file not found"
[[ "$RESULT" =~ "Upload cannot be completed." ]]
}

@test "test testuser clean Upload" {
STATUS_CODE=$(echo $CLEAN_STRING | curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt)
STATUS_CODE=$(echo $CLEAN_STRING | curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt)
echo "Actual: $RESULT"
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt || echo "file not found"
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt || echo "file not found"
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
}

@test "test testuser pup Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T $FOLDER_PREFIX/pup.exe http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.pup.exe)
RESULT=$(curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T $FOLDER_PREFIX/pup.exe http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.pup.exe)
echo "Actual: $RESULT"
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.pup.exe || echo "file not found"
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://$HOSTNAME/remote.php/dav/files/$TESTUSER/functionality-parallel.pup.exe || echo "file not found"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]] || exit 1
}

Expand Down
Loading

0 comments on commit 88b789d

Please sign in to comment.