Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #43

Merged
merged 10 commits into from
Jun 13, 2024
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"vscode": {
"extensions": [
"CharlieGerard.pride-vscode-themes",
"junstyle.php-cs-fixer"
"junstyle.php-cs-fixer",
"stylelint.vscode-stylelint"
]
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "make build && composer install",
"postStartCommand": "make build && composer install",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/edouard-lopez/devcontainer-features/bats:0": {}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nextcloud/ocp": "dev-stable28",
"psalm/phar": "5.24.0",
"nextcloud/coding-standard": "v1.2.1",
"symfony/console": "v7.1.1"
"symfony/console": "v6.4.8"
},
"scripts": {
"lint": "find lib -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
Expand All @@ -34,4 +34,4 @@
"php": "8.1"
}
}
}
}
24 changes: 13 additions & 11 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ a {
color: blue;
}

input[type=text], input[type=password], input[type=email], input[type=number], select {
input[type=text],
input[type=password],
input[type=email],
input[type=number],
select {
width: 70%;
margin: 8px 0 8px 50px;
display: inline-block;
Expand All @@ -16,19 +20,16 @@ input[type=text], input[type=password], input[type=email], input[type=number], s
}

input.toggle-round {
display:none;
display: none;
}

input.toggle-round + label {
input.toggle-round+label {
display: block;
position: relative;
cursor: pointer;
margin-right: 20px;
margin-top: 5px;
margin-bottom: 5px;
}

input.toggle-round + label {
padding: 1px;
width: 60px;
height: 30px;
Expand All @@ -37,22 +38,23 @@ input.toggle-round + label {
border: 1px solid #ccc;
}

input.toggle-round + label:after {
input.toggle-round+label:after {
display: block;
position: absolute;
content: "";
width: 25px; height: 25px;
width: 25px;
height: 25px;
background-color: white;
border-radius: 100%;
box-shadow: 0 2px 3px #888;
transition: margin 0.5s;
}

input.toggle-round:checked + label {
input.toggle-round:checked+label {
background-color: #9bd1e3;
}

input.toggle-round:checked + label:after {
input.toggle-round:checked+label:after {
margin-left: 30px;
}

Expand All @@ -62,4 +64,4 @@ input.toggle-round:checked + label:after {

#advanced_buttons:hover {
background-color: inherit;
}
}
4 changes: 4 additions & 0 deletions empty-skeleton.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$CONFIG = array (
'skeletondirectory' => '',
);
19 changes: 15 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ setup_nextcloud () {
sleep 1
docker run -d --name nextcloud-container --rm --publish 80:80 nextcloud:28

until docker exec --user www-data -i nextcloud-container php occ status | grep "installed: false"
do
echo "waiting for nextcloud to be initialized"
sleep 2
done

echo "copy config for empty skeleton"
docker cp ./empty-skeleton.config.php nextcloud-container:/var/www/html/config/config.php
docker exec -i nextcloud-container chown www-data:www-data /var/www/html/config/config.php

until docker exec --user www-data -i nextcloud-container php occ maintenance:install --admin-user=admin --admin-pass=admin | grep "Nextcloud was successfully installed"
do
echo "Trying installation"
echo "waiting for installation to finish"
sleep 2
done

docker exec --user www-data -i nextcloud-container php occ log:manage --level DEBUG
docker exec --user www-data -i nextcloud-container php occ app:disable firstrunwizard

echo "setup nextcloud finished"
}

Expand Down Expand Up @@ -47,7 +61,4 @@ docker exec --user www-data -i nextcloud-container php occ config:app:set gdatav
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas autoScanFiles --value=true
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas scanQueueLength --value=100

docker exec --user www-data -i nextcloud-container php occ log:manage --level DEBUG
docker exec --user www-data -i nextcloud-container php occ app:disable firstrunwizard

source install.local || echo "No additional install script found."
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"dev": "webpack --node-env development --progress",
"watch": "webpack --node-env development --progress --watch",
"serve": "webpack --node-env development serve --progress",
"lint": "eslint --ext .js,.vue src",
"lint:fix": "eslint --ext .js,.vue src --fix",
"stylelint": "stylelint css/*.css css/*.scss src/**/*.scss src/**/*.vue",
"stylelint:fix": "stylelint css/*.css css/*.scss src/**/*.scss src/**/*.vue --fix"
},
Expand All @@ -39,5 +37,11 @@
"@nextcloud/eslint-config": "^8.4.1",
"@nextcloud/stylelint-config": "^3.0.1",
"@nextcloud/webpack-vue-config": "^6.0.1"
},
"overrides": {
"@nextcloud/webpack-vue-config": {
"webpack-dev-server": "^5.0.2",
"vue-loader": "17.4.2"
}
}
}
1 change: 1 addition & 0 deletions tests/functionality-parallel.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup_file() {
mkdir -p $FOLDER_PREFIX
curl --output $FOLDER_PREFIX/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
docker exec --env OC_PASS=$TESTUSER_PASSWORD --user www-data nextcloud-container php occ user:add $TESTUSER --password-from-env || echo "already exists"

docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
sleep 2
}
Expand Down
15 changes: 12 additions & 3 deletions tests/functionality-sequential.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ FOLDER_PREFIX=./tmp/functionality-sequential
TESTUSER=testuser
TESTUSER_PASSWORD=myfancysecurepassword234
EICAR_STRING='X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'
CLEAN_STRING='nothingwronghere'

setup_file() {
mkdir -p $FOLDER_PREFIX/
curl --output $FOLDER_PREFIX/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
docker exec --env OC_PASS=$TESTUSER_PASSWORD --user www-data nextcloud-container php occ user:add $TESTUSER --password-from-env || echo "already exists"

docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
BATS_NO_PARALLELIZE_WITHIN_FILE=true
}

Expand All @@ -26,40 +29,46 @@ setup_file() {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"
echo $EICAR_STRING | curl --silent -w "%{http_code}" -u admin:admin -T - http://127.0.0.1/remote.php/dav/files/admin/admin.functionality-sequential.eicar.com.txt
curl --silent -w "%{http_code}" -u admin:admin -T $FOLDER_PREFIX/pup.exe http://127.0.0.1/remote.php/dav/files/admin/admin.pup.exe
echo $CLEAN_STRING | curl --silent -w "%{http_code}" -u admin:admin -T - http://127.0.0.1/remote.php/dav/files/admin/admin.functionality-sequential.clean.txt

docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"

docker exec -i --user www-data nextcloud-container php occ gdatavaas:tag-unscanned
docker exec -i --user www-data nextcloud-container php occ gdatavaas:scan

LOGS=$(docker exec --user www-data -i nextcloud-container cat data/nextcloud.log | egrep "admin.functionality-sequential.eicar.com.txt|Readme.md|admin.pup.exe" )
LOGS=$(docker exec --user www-data -i nextcloud-container php occ log:tail -nr 5000 | egrep "admin.functionality-sequential.eicar.com.txt|admin.functionality-sequential.clean.txt|admin.pup.exe" )

curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/admin.functionality-sequential.eicar.com.txt
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/admin.pup.exe
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/admin.functionality-sequential.clean.txt

[[ $LOGS =~ ^.*admin.functionality-sequential.eicar.com.txt.*Verdict:.*Malicious ]]
[[ $LOGS =~ ^.*admin.pup.exe.*Verdict:.*Pup ]]
[[ $LOGS =~ ^.*Readme.md.*Verdict:.*Clean ]]
[[ $LOGS =~ ^.*admin.functionality-sequential.clean.txt.*Verdict:.*Clean ]]
}

@test "test croned scan for testuser files" {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"

echo $EICAR_STRING |curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.functionality-sequential.eicar.com.txt
curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T $FOLDER_PREFIX/pup.exe http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.pup.exe
echo $CLEAN_STRING |curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T - http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.functionality-sequential.clean.txt

docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"

docker exec -i --user www-data nextcloud-container php occ gdatavaas:tag-unscanned
docker exec -i --user www-data nextcloud-container php occ gdatavaas:scan

LOGS=$(docker exec --user www-data -i nextcloud-container cat data/nextcloud.log | egrep "$TESTUSER.functionality-sequential.eicar.com.txt|$TESTUSER.pup.exe")
LOGS=$(docker exec --user www-data -i nextcloud-container php occ log:tail -nr 5000 | egrep "$TESTUSER.functionality-sequential.eicar.com.txt|$TESTUSER.functionality-sequential.clean.txt|$TESTUSER.pup.exe")

curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.functionality-sequential.eicar.com.txt
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.pup.exe
curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.functionality-sequential.clean.txt

[[ $LOGS =~ ^.*$TESTUSER.functionality-sequential.eicar.com.txt.*Verdict:.*Malicious ]]
[[ $LOGS =~ ^.*$TESTUSER.pup.exe.*Verdict:.*Pup ]]
[[ $LOGS =~ ^.*$TESTUSER.functionality-sequential.clean.txt.*Verdict:.*Clean ]]

}

tearddown_file() {
Expand Down
Loading