Skip to content

Commit

Permalink
run most test in bats
Browse files Browse the repository at this point in the history
  • Loading branch information
unglaublicherdude committed Jun 10, 2024
1 parent 3514288 commit 9a41de5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
7 changes: 2 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "make build && composer install",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "lts",
"nvmVersion": "latest"
}
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/edouard-lopez/devcontainer-features/bats:0": {}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
Expand Down
48 changes: 6 additions & 42 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,19 @@ jobs:
name: setup node
with:
node-version: 20

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.11.0
- uses: docker-practice/actions-setup-docker@master
- name: install nextcloud
env:
CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.VAAS_CLIENT_SECRET }}
run: ./install.sh

- name: create testuser
run: |
docker exec --env OC_PASS=myfancysecurepassword234 --user www-data nextcloud-container php occ user:add testuser --password-from-env
- name: create testfiles
run: |
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
- name: test admin eicar Upload
run: |
curl --silent -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt \
| grep -o "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." \
|| exit 1
- name: test admin clean Upload
run: |
STATUS_CODE=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/admin/clean.txt)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
- name: test admin pup Upload
run: |
STATUS_CODE=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/admin/pup.exe)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
- name: test testuser eicar Upload
run: |
curl --silent -u testuser:myfancysecurepassword234 -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/eicar.com.txt \
| grep -o "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." \
|| exit 1
- name: test testuser clean Upload
run: |
STATUS_CODE=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/testuser/clean.txt)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
- name: test testuser pup Upload
run: |
STATUS_CODE=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/testuser/pup.exe)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
- name: run tests
run: ./test.bats

- name: test upload when vaas does not function
env:
Expand Down
40 changes: 40 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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
docker exec --env OC_PASS=myfancysecurepassword234 --user www-data nextcloud-container php occ user:add testuser --password-from-env || echo "already exists"
}

@test "test admin eicar Upload" {
RESULT=$(curl --silent -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
[[ "$RESULT" =~ "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." ]]
}

@test "test admin clean Upload" {
STATUS_CODE=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/admin/clean.txt)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]]
}

@test "test admin pup Upload" {
STATUS_CODE=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/admin/pup.exe)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]]
}

@test "test testuser eicar Upload" {
RESULT=$(curl --silent -u testuser:myfancysecurepassword234 -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/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}" -u testuser:myfancysecurepassword234 -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/testuser/clean.txt)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
}

@test "test testuser pup Upload" {
STATUS_CODE=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/testuser/pup.exe)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
}

0 comments on commit 9a41de5

Please sign in to comment.