diff --git a/tests/functionality-parallel.bats b/tests/functionality-parallel.bats index 53c4ac34..2692df68 100755 --- a/tests/functionality-parallel.bats +++ b/tests/functionality-parallel.bats @@ -1,15 +1,20 @@ #!/usr/bin/env bats FOLDER_PREFIX=./tmp/functionality-parallel/ +TESTUSER=testuser +TESTUSER_PASSWORD=myfancysecurepassword234 setup_file() { mkdir -p $FOLDER_PREFIX + 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 +} + +setup() { echo 'nothingwronghere' > $FOLDER_PREFIX/clean.txt echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > $FOLDER_PREFIX/eicar.com.txt curl --output $FOLDER_PREFIX/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe - docker exec --env OC_PASS=myfancysecurepassword234 --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 } @test "test admin eicar Upload" { @@ -19,7 +24,7 @@ setup_file() { [[ "$RESULT" =~ "Upload cannot be completed." ]] } -@test "test admin clean Upload" { +@test "test admin clean upload" { RESULT=$(curl -w "%{http_code}" -u admin:admin -T $FOLDER_PREFIX/clean.txt http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.clean.txt) 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 @@ -34,24 +39,24 @@ setup_file() { } @test "test testuser eicar Upload" { - RESULT=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T ./tmp/functionality-sequential//eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.eicar.com.txt) + RESULT=$(curl --silent -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T ./tmp/functionality-sequential//eicar.com.txt http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt) echo "Actual: $RESULT" docker exec --user www-data -i nextcloud-container php occ config:app:get gdatavaas clientSecret - curl --silent -q -u testuser:myfancysecurepassword234 -X DELETE http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.eicar.com.txt + curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.eicar.com.txt [[ "$RESULT" =~ "Upload cannot be completed." ]] } @test "test testuser clean Upload" { - STATUS_CODE=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T $FOLDER_PREFIX/clean.txt http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.clean.txt) + STATUS_CODE=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u $TESTUSER:$TESTUSER_PASSWORD -T $FOLDER_PREFIX/clean.txt http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt) echo "Actual: $RESULT" - curl --silent -q -u testuser:myfancysecurepassword234 -X DELETE http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.clean.txt + curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.clean.txt [[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1 } @test "test testuser pup Upload" { - RESULT=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -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}" -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) echo "Actual: $RESULT" - curl --silent -q -u testuser:myfancysecurepassword234 -X DELETE http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.pup.exe + curl --silent -q -u $TESTUSER:$TESTUSER_PASSWORD -X DELETE http://127.0.0.1/remote.php/dav/files/$TESTUSER/functionality-parallel.pup.exe [[ $RESULT -ge 200 && $RESULT -lt 300 ]] || exit 1 } diff --git a/tests/functionality-sequential.bats b/tests/functionality-sequential.bats index a76efeae..ae228f00 100644 --- a/tests/functionality-sequential.bats +++ b/tests/functionality-sequential.bats @@ -1,6 +1,8 @@ #!/usr/bin/env bats FOLDER_PREFIX=./tmp/functionality-sequential/ +TESTUSER=testuser +TESTUSER_PASSWORD=myfancysecurepassword234 setup_file() { mkdir -p $FOLDER_PREFIX/ @@ -38,16 +40,16 @@ setup_file() { @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" - curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T $FOLDER_PREFIX/eicar.com.txt 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/eicar.com.txt http://127.0.0.1/remote.php/dav/files/$TESTUSER/$TESTUSER.functionality-sequential.eicar.com.txt docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET" docker exec --user www-data -i nextcloud-container php ./cron.php # tag unscanned docker exec --user www-data -i nextcloud-container php ./cron.php # actual scan - LOGS=$(docker exec --user www-data -i nextcloud-container cat data/nextcloud.log | egrep "testuser.functionality-sequential.eicar.com.txt") + LOGS=$(docker exec --user www-data -i nextcloud-container cat data/nextcloud.log | egrep "$TESTUSER.functionality-sequential.eicar.com.txt") - curl --silent -q -u testuser:myfancysecurepassword234 -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.functionality-sequential.eicar.com.txt - [[ $LOGS =~ ^.*testuser.functionality-sequential.eicar.com.txt.*Verdict:.*Malicious ]] + [[ $LOGS =~ ^.*$TESTUSER.functionality-sequential.eicar.com.txt.*Verdict:.*Malicious ]] } tearddown_file() {