diff --git a/docs/ocis/development/testing.md b/docs/ocis/development/testing.md index 1d329591533..4bcc91c6053 100644 --- a/docs/ocis/development/testing.md +++ b/docs/ocis/development/testing.md @@ -74,7 +74,21 @@ To run the tests that require an email server (tests tagged with `@email`), you ```bash START_EMAIL=true \ -BEHAT_FEATURE='tests/acceptance/features/apiEmailNotification/emailNotification.feature' \ +BEHAT_FEATURE='tests/acceptance/features/apiNotification/emailNotification.feature' \ +make -C tests/acceptance/docker test-ocis-feature-ocis-storage +``` + +{{< /hint >}} + +{{< hint info >}} +To run the tests that require an antivirus service (tests tagged with `@antivirus`), you need to provide the following environment variables while running the tests. + +```bash +START_ANTIVIRUS=true \ +OCIS_ASYNC_UPLOADS=true \ +OCIS_ADD_RUN_SERVICES=antivirus \ +POSTPROCESSING_STEPS=virusscan \ +BEHAT_FEATURE='tests/acceptance/features/apiAntivirus/antivirus.feature' \ make -C tests/acceptance/docker test-ocis-feature-ocis-storage ``` @@ -428,7 +442,7 @@ The commands are ubuntu specific and may differ according to your system. You ca #### 2. Setup clamAV With Docker ##### a. Create a Volume -For `clamAV` only local sockets can currently be configured we need to create a volume in order to share the socket with `oCIS server`. Run the following command to do so: +For `clamAV` only local sockets can currently be configured, we need to create a volume in order to share the socket with `oCIS server`. Run the following command to do so: ```bash docker volume create -d local -o device=/your/local/filesystem/path/ -o o=bind -o type=none clamav_vol ``` @@ -442,7 +456,7 @@ The path to the socket i.e. `/var/run/clamav/` may differ as per the image you a {{< /hint>}} ##### b. Change Ownership -Change the ownership of the path of your local filesystem that the volume `clamav_vol` is mounted on. After running `clamav` through docker the ownership of the bound path gets changed. As we need to provide this path to ocis server the ownership should be changed back to $USER or whatever ownership that your server requires. +Change the ownership of the path of your local filesystem that the volume `clamav_vol` is mounted on. After running `clamav` through docker the ownership of the bound path gets changed. As we need to provide this path to ocis server, the ownership should be changed back to $USER or whatever ownership that your server requires. ```bash sudo chown -R $USER:$USER /your/local/filesystem/path/ ``` @@ -451,7 +465,7 @@ Make sure that `clamAV` is fully up before running this command. The command is {{< /hint>}} {{< hint info >}} -If you want to use the same volume after the container is down. Before running the container once again you need to either remove all the data inside `/your/local/filesystem/path/` or give the ownership back. For instance, it ubuntu it might be `sudo chown -R systemd-network:systemd-journal /your/local/filesystem/path/` and repeat step 2 and 3` +If you want to use the same volume after the container is down then before running the container once again, you either need to remove all the data inside `/your/local/filesystem/path/` or give the ownership back. For instance, on Ubuntu it might be `sudo chown -R systemd-network:systemd-journal /your/local/filesystem/path/` and repeat `step 2 and 3` {{< /hint>}} ### Run oCIS diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 2b63ad7e5c7..0631ee4066c 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -205,6 +205,7 @@ default: - FilesVersionsContext: - SettingsContext: - OcisConfigContext: + - PublicWebDavContext: extensions: rdx\behatvars\BehatVariablesExtension: ~ diff --git a/tests/acceptance/docker/Makefile b/tests/acceptance/docker/Makefile index eddf0f2314d..2303b5d4ecb 100644 --- a/tests/acceptance/docker/Makefile +++ b/tests/acceptance/docker/Makefile @@ -186,11 +186,19 @@ testSuite: $(OCIS_WRAPPER) build-dev-image clean-docker-container COMPOSE_FILE=src/email.yml \ docker-compose run start_email; \ fi; \ + if [ "${START_ANTIVIRUS}" == "true" ]; then \ + COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \ + COMPOSE_FILE=src/antivirus.yml \ + docker-compose run start_antivirus; \ + fi; \ COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \ COMPOSE_FILE=$(COMPOSE_FILE) \ STORAGE_DRIVER=$(STORAGE_DRIVER) \ TEST_SOURCE=$(TEST_SOURCE) \ WITH_WRAPPER=$(WITH_WRAPPER) \ + OCIS_ASYNC_UPLOADS=$(OCIS_ASYNC_UPLOADS) \ + OCIS_ADD_RUN_SERVICES=$(OCIS_ADD_RUN_SERVICES) \ + POSTPROCESSING_STEPS=$(POSTPROCESSING_STEPS) \ OCIS_IMAGE_TAG=$(OCIS_IMAGE_TAG) \ BEHAT_SUITE=$(BEHAT_SUITE) \ BEHAT_FEATURE=$(BEHAT_FEATURE) \ diff --git a/tests/acceptance/docker/src/antivirus.yml b/tests/acceptance/docker/src/antivirus.yml new file mode 100644 index 00000000000..33e2a8259f8 --- /dev/null +++ b/tests/acceptance/docker/src/antivirus.yml @@ -0,0 +1,14 @@ +services: + start_antivirus: + image: dadarek/wait-for-dependencies + depends_on: + - clamav + command: clamav:3310 + clamav: + image: owncloudci/clamavd + volumes: + - clamavSocket:/var/run/clamav/ + +volumes: + clamavSocket: + diff --git a/tests/acceptance/docker/src/ocis-base.yml b/tests/acceptance/docker/src/ocis-base.yml index d6716720dfe..6694dee935b 100644 --- a/tests/acceptance/docker/src/ocis-base.yml +++ b/tests/acceptance/docker/src/ocis-base.yml @@ -22,6 +22,9 @@ services: IDM_CREATE_DEMO_USERS: "true" IDM_ADMIN_PASSWORD: "admin" FRONTEND_SEARCH_MIN_LENGTH: "2" + OCIS_ASYNC_UPLOADS: $OCIS_ASYNC_UPLOADS + OCIS_ADD_RUN_SERVICES: $OCIS_ADD_RUN_SERVICES + # s3ng specific settings STORAGE_USERS_S3NG_ENDPOINT: http://ceph:8080 STORAGE_USERS_S3NG_REGION: default @@ -32,6 +35,19 @@ services: NOTIFICATIONS_SMTP_HOST: email NOTIFICATIONS_SMTP_PORT: 2500 NOTIFICATIONS_SMTP_INSECURE: "true" + + # antivirus + ANTIVIRUS_SCANNER_TYPE: "clamav" + ANTIVIRUS_CLAMAV_SOCKET: "/var/run/clamav/clamd.sock" + + # postprocessing step + POSTPROCESSING_STEPS: $POSTPROCESSING_STEPS volumes: - ../../../config:/drone/src/tests/config - ../../../ociswrapper/bin/ociswrapper:/usr/bin/ociswrapper + - clamavSocket:/var/run/clamav/ + +volumes: + clamavSocket: + external: + name: ocis-acceptance-tests_clamavSocket diff --git a/tests/acceptance/features/apiAntivirus/antivirus.feature b/tests/acceptance/features/apiAntivirus/antivirus.feature index 0bb5e2b1a19..a74dd31ddd7 100644 --- a/tests/acceptance/features/apiAntivirus/antivirus.feature +++ b/tests/acceptance/features/apiAntivirus/antivirus.feature @@ -1,10 +1,9 @@ -@api @antivirus +@api @antivirus @skipOnReva Feature: antivirus As a system administrator and user I want to protect myself and others from known viruses So that I can prevent files with viruses from being uploaded - Background: Given user "Alice" has been created with default attributes and without skeleton files @@ -24,12 +23,9 @@ Feature: antivirus | dav-path-version | | old | | new | - - @skipOnRevaMaster - Examples: - | dav-path-version | | spaces | + Scenario Outline: upload a file with virus Given using DAV path When user "Alice" uploads file "filesForUpload/filesWithVirus/eicar.com" to "/aFileWithVirus.txt" using the WebDAV API @@ -43,10 +39,6 @@ Feature: antivirus | dav-path-version | | old | | new | - - @skipOnRevaMaster - Examples: - | dav-path-version | | spaces | @@ -72,10 +64,6 @@ Feature: antivirus | dav-path-version | | old | | new | - - @skipOnRevaMaster - Examples: - | dav-path-version | | spaces | @@ -95,8 +83,214 @@ Feature: antivirus Examples: | dav-path-version | | old | + | spaces | - @skipOnRevaMaster + + Scenario Outline: upload a file with the virus to a public share + Given using DAV path + And user "Alice" has created folder "/uploadFolder" + And user "Alice" has created a public link share with settings + | path | /uploadFolder | + | name | sharedlink | + | permissions | change | + | expireDate | 2040-01-01T23:59:59+0100 | + When user "Alice" uploads file "filesForUpload/filesWithVirus/" to "/" using the WebDAV API + Then the HTTP status code should be "201" + And user "Alice" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | dav-path-version | filename | newfilename | + | old | eicar.com | virusFile1.txt | + | old | eicar_com.zip | virusFile2.zip | + | new | eicar.com | virusFile1.txt | + | new | eicar_com.zip | virusFile2.zip | + | spaces | eicar.com | virusFile1.txt | + | spaces | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with the virus to a password-protected public share + Given using DAV path + And user "Alice" has created folder "/uploadFolder" + And user "Alice" has created a public link share with settings + | path | /uploadFolder | + | name | sharedlink | + | permissions | change | + | password | newpasswd | + | expireDate | 2040-01-01T23:59:59+0100 | + When user "Alice" uploads file "filesForUpload/filesWithVirus/" to "/" using the WebDAV API + Then the HTTP status code should be "201" + And user "Alice" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | dav-path-version | filename | newfilename | + | old | eicar.com | virusFile1.txt | + | old | eicar_com.zip | virusFile2.zip | + | new | eicar.com | virusFile1.txt | + | new | eicar_com.zip | virusFile2.zip | + | spaces | eicar.com | virusFile1.txt | + | spaces | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a user share + Given using DAV path + And user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has created folder "uploadFolder" + And user "Alice" has shared folder "uploadFolder" with user "Brian" with permissions "all" + And user "Brian" has accepted share "/uploadFolder" offered by user "Alice" + When user "Brian" uploads file "filesForUpload/filesWithVirus/" to "/Shares/uploadFolder/" using the WebDAV API + Then the HTTP status code should be "201" + And user "Brian" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Brian" file "/Shares/uploadFolder/" should not exist + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | dav-path-version | filename | newfilename | + | old | eicar.com | virusFile1.txt | + | old | eicar_com.zip | virusFile2.zip | + | new | eicar.com | virusFile1.txt | + | new | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a user share using spaces dav endpoint + Given using spaces DAV path + And user "Brian" has been created with default attributes and without skeleton files + And user "Alice" has created folder "uploadFolder" + And user "Alice" has shared folder "uploadFolder" with user "Brian" with permissions "all" + And user "Brian" has accepted share "/uploadFolder" offered by user "Alice" + When user "Brian" uploads a file "filesForUpload/filesWithVirus/" to "/uploadFolder/" in space "Shares" using the WebDAV API + Then the HTTP status code should be "201" + And user "Brian" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Brian" file "/Shares/uploadFolder/" should not exist + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | filename | newfilename | + | eicar.com | virusFile1.txt | + | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a group share + Given using DAV path + And user "Brian" has been created with default attributes and without skeleton files + And group "group1" has been created + And user "Brian" has been added to group "group1" + And user "Alice" has created folder "uploadFolder" + And user "Alice" has shared folder "uploadFolder" with group "group1" + And user "Brian" has accepted share "/uploadFolder" offered by user "Alice" + When user "Brian" uploads file "filesForUpload/filesWithVirus/" to "/Shares/uploadFolder/" using the WebDAV API + Then the HTTP status code should be "201" + And user "Brian" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Brian" file "/Shares/uploadFolder/" should not exist + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | dav-path-version | filename | newfilename | + | old | eicar.com | virusFile1.txt | + | old | eicar_com.zip | virusFile2.zip | + | new | eicar.com | virusFile1.txt | + | new | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a group share using spaces dav endpoint + Given using spaces DAV path + And user "Brian" has been created with default attributes and without skeleton files + And group "group1" has been created + And user "Brian" has been added to group "group1" + And user "Alice" has created folder "uploadFolder" + And user "Alice" has shared folder "uploadFolder" with group "group1" + And user "Brian" has accepted share "/uploadFolder" offered by user "Alice" + When user "Brian" uploads a file "filesForUpload/filesWithVirus/" to "/uploadFolder/" in space "Shares" using the WebDAV API + Then the HTTP status code should be "201" + And user "Brian" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Brian" file "/Shares/uploadFolder/" should not exist + And as "Alice" file "/uploadFolder/" should not exist + Examples: + | filename | newfilename | + | eicar.com | virusFile1.txt | + | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a project space + Given using spaces DAV path + And the administrator has given "Alice" the role "Space Admin" using the settings api + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + And user "Alice" has created a folder "uploadFolder" in space "new-space" + When user "Alice" uploads a file "filesForUpload/filesWithVirus/" to "/uploadFolder/" in space "new-space" using the WebDAV API + Then the HTTP status code should be "201" + And user "Alice" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And for user "Alice" the space "new-space" should not contain these entries: + | /uploadFolder/ | + When user "Alice" uploads a file "filesForUpload/filesWithVirus/" to "/" in space "new-space" using the WebDAV API + Then the HTTP status code should be "201" + And user "Alice" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And for user "Alice" the space "new-space" should not contain these entries: + | / | + Examples: + | filename | newfilename | + | eicar.com | virusFile1.txt | + | eicar_com.zip | virusFile2.zip | + + + Scenario Outline: upload a file with virus to a shared project space + Given using spaces DAV path + And user "Brian" has been created with default attributes and without skeleton files + And the administrator has given "Alice" the role "Space Admin" using the settings api + And user "Alice" has created a space "new-space" with the default quota using the GraphApi + And user "Alice" has shared a space "new-space" with settings: + | shareWith | Brian | + | role | editor | + When user "Brian" uploads a file "/filesForUpload/filesWithVirus/" to "/" in space "new-space" using the WebDAV API + Then the HTTP status code should be "201" + And user "Brian" should get a notification with subject "Virus found" and message: + | message | + | Virus found in . Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And for user "Brian" the space "new-space" should not contain these entries: + | / | + And for user "Alice" the space "new-space" should not contain these entries: + | / | + Examples: + | filename | newfilename | + | eicar.com | virusFile1.txt | + | eicar_com.zip | virusFile2.zip | + + @env-config + Scenario Outline: upload a file with virus smaller than the upload threshold + Given the config "ANTIVIRUS_MAX_SCAN_SIZE" has been set to "100" + And using DAV path + When user "Alice" uploads file "filesForUpload/filesWithVirus/eicar.com" to "/aFileWithVirus.txt" using the WebDAV API + Then the HTTP status code should be "201" + And user "Alice" should get a notification with subject "Virus found" and message: + | message | + | Virus found in aFileWithVirus.txt. Upload not possible. Virus: Win.Test.EICAR_HDB-1 | + And as "Alice" file "/aFileWithVirus.txt" should not exist Examples: | dav-path-version | + | old | + | new | | spaces | + + @env-config + Scenario Outline: upload a file with virus larger than the upload threshold + Given the config "ANTIVIRUS_MAX_SCAN_SIZE" has been set to "100" + And using DAV path + When user "Alice" uploads file "filesForUpload/filesWithVirus/eicar_com.zip" to "/aFileWithVirus.txt" using the WebDAV API + Then the HTTP status code should be "201" + And as "Alice" file "/aFileWithVirus.txt" should exist + Examples: + | dav-path-version | + | old | + | new | + | spaces | \ No newline at end of file diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 30bdfe02708..d985c95a5d4 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -1228,6 +1228,28 @@ class SpacesContext implements Context { $this->featureContext->uploadFileWithContent($user, $content, $destination); } + /** + * @When /^user "([^"]*)" uploads a file "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $source + * @param string $destination + * @param string $spaceName + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function theUserUploadsALocalFileToSpace( + string $user, + string $source, + string $destination, + string $spaceName + ): void { + $this->setSpaceIDByName($user, $spaceName); + $this->featureContext->userUploadsAFileTo($user, $source, $destination); + } + /** * @When /^user "([^"]*)" uploads a file inside space "([^"]*)" owned by the user "([^"]*)" with content "([^"]*)" to "([^"]*)" using the WebDAV API$/ * diff --git a/tests/acceptance/filesForUpload/filesWithVirus/eicarcom2.zip b/tests/acceptance/filesForUpload/filesWithVirus/eicarcom2.zip deleted file mode 100644 index 4bda6119ad1..00000000000 Binary files a/tests/acceptance/filesForUpload/filesWithVirus/eicarcom2.zip and /dev/null differ