Skip to content

Commit

Permalink
Refactor tests (#43)
Browse files Browse the repository at this point in the history
* adds clean uploads to the cron tests instead of relieing on files that are already there

* use log:tail instead of cat the logfile

* always set client_secret (you never know if the tests are running one by one)

* an empty skeleton directory will make the tests faster

the con test do tag all files and then scan all files
with this change only the files from the test are actually processed because no sekeleton files are present

* ran `npm run stylelint:fix`

* also merged the 2 `input.toggle-round + label` selectors as suggested by stylelint:fix

* as we have no configuratioh for eslint i also removed the scripts


---------

Co-authored-by: Lennart Dohmann <[email protected]>
Co-authored-by: Simonis, Matthias <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent fdf5adf commit f3fc205
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
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
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."
2 changes: 0 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 Down
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

0 comments on commit f3fc205

Please sign in to comment.