Skip to content

Commit

Permalink
try to make them more rubust
Browse files Browse the repository at this point in the history
  • Loading branch information
unglaublicherdude committed Jun 11, 2024
1 parent bdfde15 commit b8f1d7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ js/
*.cache
.uuid
eicar.com.txt
tmp/
35 changes: 21 additions & 14 deletions tests/functionality-parallel.bats
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
#!/usr/bin/env bats

setup_file() {
echo 'nothingwronghere' > /tmp/clean.txt
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.com.txt
curl --output /tmp/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
mkdir -p ./tmp/functionality-parallel/
echo 'nothingwronghere' > ./tmp/functionality-parallel//clean.txt
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > ./tmp/functionality-parallel/eicar.com.txt
curl --output ./tmp/functionality-parallel/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" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T ./tmp/functionality-parallel/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt)
echo "Actual: $RESULT"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.eicar.com.txt
[[ "$RESULT" =~ "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." ]]
}

@test "test admin clean Upload" {
RESULT=$(curl -w "%{http_code}" -u admin:admin -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/admin/clean.txt)
RESULT=$(curl -w "%{http_code}" -u admin:admin -T ./tmp/functionality-parallel/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/clean.txt
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.clean.txt
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test admin pup Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/admin/pup.exe)
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T ./tmp/functionality-parallel/pup.exe http://127.0.0.1/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/pup.exe
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-parallel.pup.exe
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test testuser eicar Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/eicar.com.txt)
RESULT=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T ./tmp/functionality-parallel/eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.eicar.com.txt)
echo "Actual: $RESULT"
curl --silent -q -u testuser:myfancysecurepassword234 -X DELETE http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.eicar.com.txt
[[ "$RESULT" =~ "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." ]]
}

@test "test testuser clean Upload" {
STATUS_CODE=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/testuser/clean.txt)
STATUS_CODE=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T ./tmp/functionality-parallel/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/clean.txt
curl --silent -q -u testuser:myfancysecurepassword234 -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 /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/testuser/pup.exe)
RESULT=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T ./tmp/functionality-parallel/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/pup.exe
curl --silent -q -u testuser:myfancysecurepassword234 -X DELETE http://127.0.0.1/remote.php/dav/files/testuser/functionality-parallel.pup.exe
[[ $RESULT -ge 200 && $RESULT -lt 300 ]] || exit 1
}

@tearddown_file() {
rm -rf ./tmp/functionality-parallel/
}

22 changes: 12 additions & 10 deletions tests/functionality-sequential.bats
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/usr/bin/env bats

setup_file() {
echo 'nothingwronghere' > /tmp/clean.txt
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.com.txt
curl --output /tmp/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
mkdir -p ./tmp/functionality-sequential/
echo 'nothingwronghere' > ./tmp/functionality-sequential/clean.txt
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > ./tmp/functionality-sequential//eicar.com.txt
curl --output ./tmp/functionality-sequential/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
BATS_NO_PARALLELIZE_WITHIN_FILE=true
}

setup() {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"
}

@test "test upload when vaas does not function" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T ./tmp/functionality-sequential/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/functionality-sequential.eicar.com.txt)
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/functionality-sequential.eicar.com.txt

echo "Actual: $RESULT"
curl --silent -q -u admin:admin -X DELETE http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

tearddown() {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
tearddown_file() {
sleep 2
rm -rf ./tmp/functionality-sequential/
}

0 comments on commit b8f1d7e

Please sign in to comment.