diff --git a/.woodpecker.star b/.woodpecker.star index fb14c356d9..487a19d312 100644 --- a/.woodpecker.star +++ b/.woodpecker.star @@ -234,7 +234,6 @@ config = { ], "skip": False, "antivirusNeeded": True, - "generateVirusFiles": True, "extraServerEnvironment": { "ANTIVIRUS_SCANNER_TYPE": "clamav", "ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310", @@ -301,7 +300,6 @@ config = { "skip": False, "withRemotePhp": [True], "antivirusNeeded": True, - "generateVirusFiles": True, "extraServerEnvironment": { "ANTIVIRUS_SCANNER_TYPE": "clamav", "ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310", @@ -1234,7 +1232,6 @@ def localApiTestPipeline(ctx): "withRemotePhp": [True], "enableWatchFs": [False], "ldapNeeded": False, - "generateVirusFiles": False, } if "localApiTests" in config: @@ -1290,7 +1287,7 @@ def localApiTestPipeline(ctx): (opencloudServer(storage, params["accounts_hash_difficulty"], deploy_type = "federation", extra_server_environment = params["extraServerEnvironment"], watch_fs_enabled = run_with_watch_fs_enabled) if params["federationServer"] else []) + ((wopiCollaborationService("fakeoffice") + wopiCollaborationService("collabora") + wopiCollaborationService("onlyoffice")) if params["collaborationServiceNeeded"] else []) + (openCloudHealthCheck("wopi", ["wopi-collabora:9304", "wopi-onlyoffice:9304", "wopi-fakeoffice:9304"]) if params["collaborationServiceNeeded"] else []) + - localApiTest(params["suites"], storage, params["extraTestEnvironment"], run_with_remote_php, params["generateVirusFiles"]) + + localApiTest(params["suites"], storage, params["extraTestEnvironment"], run_with_remote_php) + logRequests(), "services": (emailService() if params["emailNeeded"] else []) + (clamavService() if params["antivirusNeeded"] else []) + @@ -1314,7 +1311,7 @@ def localApiTestPipeline(ctx): pipelines.append(pipeline) return pipelines -def localApiTest(suites, storage = "decomposed", extra_environment = {}, with_remote_php = False, generate_virus_files = False): +def localApiTest(suites, storage = "decomposed", extra_environment = {}, with_remote_php = False): test_dir = "%s/tests/acceptance" % dirs["base"] expected_failures_file = "%s/expected-failures-%s-storage.md" % (test_dir, storage) @@ -1339,11 +1336,6 @@ def localApiTest(suites, storage = "decomposed", extra_environment = {}, with_re commands = [] - # Generate EICAR virus test files if needed - if generate_virus_files: - commands.append("chmod +x %s/tests/acceptance/scripts/generate-virus-files.sh" % dirs["base"]) - commands.append("bash %s/tests/acceptance/scripts/generate-virus-files.sh" % dirs["base"]) - # Merge expected failures if not with_remote_php: commands.append("cat %s/expected-failures-without-remotephp.md >> %s" % (test_dir, expected_failures_file)) diff --git a/tests/README.md b/tests/README.md index fa290e93c3..04df56e24f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -466,15 +466,6 @@ For antivirus running localy on Linux OS, use `ANTIVIRUS_CLAMAV_SOCKET= "/var/ru For antivirus running localy on Mac OS, use `ANTIVIRUS_CLAMAV_SOCKET= "/tmp/clamd.sock"`. For antivirus running with docker, use `ANTIVIRUS_CLAMAV_SOCKET= "tcp://host.docker.internal:3310"` -#### Create Virus Files - -The antivirus tests require EICAR test files which are not stored in the repository -They are generated dynamically when needed for testing. - -```bash -tests/acceptance/scripts/generate-virus-files.sh -``` - #### Run the Acceptance Test Run the acceptance test with the following command: diff --git a/tests/acceptance/TestHelpers/HttpRequestHelper.php b/tests/acceptance/TestHelpers/HttpRequestHelper.php index 60b6486029..f36ecea49a 100644 --- a/tests/acceptance/TestHelpers/HttpRequestHelper.php +++ b/tests/acceptance/TestHelpers/HttpRequestHelper.php @@ -62,7 +62,7 @@ public static function numRetriesOnHttpTooEarly(): int { /** * - * @param string|null $url + * @param string $url * @param string|null $xRequestId * @param string|null $method * @param string|null $user @@ -80,8 +80,8 @@ public static function numRetriesOnHttpTooEarly(): int { * @throws GuzzleException */ public static function sendRequestOnce( - ?string $url, - ?string $xRequestId, + string $url, + ?string $xRequestId = null, ?string $method = 'GET', ?string $user = null, ?string $password = null, diff --git a/tests/acceptance/TestHelpers/UploadHelper.php b/tests/acceptance/TestHelpers/UploadHelper.php index 52fe8fef98..66d05f1e94 100644 --- a/tests/acceptance/TestHelpers/UploadHelper.php +++ b/tests/acceptance/TestHelpers/UploadHelper.php @@ -195,13 +195,20 @@ public static function createFileWithText(?string $name, ?string $text): void { } /** - * get the path of a file from FilesForUpload directory + * get the path of the acceptance tests directory * - * @param string|null $name name of the file to upload + * @return string + */ + public static function getAcceptanceTestsDir(): string { + return \dirname(__FILE__) . "/../"; + } + + /** + * get the path of the filesForUpload directory * * @return string */ - public static function getUploadFilesDir(?string $name): string { - return \getenv("FILES_FOR_UPLOAD") . $name; + public static function getFilesForUploadDir(): string { + return \dirname(__FILE__) . "/../filesForUpload/"; } } diff --git a/tests/acceptance/bootstrap/ChecksumContext.php b/tests/acceptance/bootstrap/ChecksumContext.php index 50a6d58f79..8d5183d9ff 100644 --- a/tests/acceptance/bootstrap/ChecksumContext.php +++ b/tests/acceptance/bootstrap/ChecksumContext.php @@ -25,6 +25,7 @@ use Psr\Http\Message\ResponseInterface; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; +use TestHelpers\UploadHelper; require_once 'bootstrap.php'; @@ -49,7 +50,7 @@ public function uploadFileToWithChecksumUsingTheAPI( string $checksum ): ResponseInterface { $file = \file_get_contents( - $this->featureContext->acceptanceTestsDirLocation() . $source + UploadHelper::getAcceptanceTestsDir() . $source ); return $this->featureContext->makeDavRequest( $user, diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index a5cf981a4a..a5e843e683 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -43,6 +43,7 @@ use TestHelpers\SettingsHelper; use TestHelpers\OcConfigHelper; use TestHelpers\BehatHelper; +use TestHelpers\UploadHelper; use Swaggest\JsonSchema\InvalidValue as JsonSchemaException; use Swaggest\JsonSchema\Exception\ArrayException; use Swaggest\JsonSchema\Exception\ConstException; @@ -562,6 +563,38 @@ public static function setupLogDir(BeforeSuiteScope $scope): void { } } + /** + * @BeforeScenario @antivirus + * + * @return void + * @throws Exception + */ + public function createTestVirusFiles(): void { + $uploadDir = UploadHelper::getFilesForUploadDir() . 'filesWithVirus/'; + $virusFile = $uploadDir . 'eicar.com'; + $virusZipFile = $uploadDir . 'eicar_com.zip'; + + if (file_exists($virusFile) && file_exists($virusZipFile)) { + return; + } + + if (!is_dir($uploadDir)) { + mkdir($uploadDir, 0755); + } + + $res1 = HttpRequestHelper::sendRequestOnce('https://secure.eicar.org/eicar.com'); + if ($res1->getStatusCode() !== 200) { + throw new Exception("Could not download eicar.com test virus file"); + } + file_put_contents($virusFile, $res1->getBody()->getContents()); + + $res2 = HttpRequestHelper::sendRequestOnce('https://secure.eicar.org/eicar_com.zip'); + file_put_contents($virusZipFile, $res2->getBody()->getContents()); + if ($res2->getStatusCode() !== 200) { + throw new Exception("Could not download eicar_com.zip test virus file"); + } + } + /** * * @BeforeScenario @@ -2596,18 +2629,11 @@ public function temporaryStorageSubfolderName(): string { return "work_tmp"; } - /** - * @return string - */ - public function acceptanceTestsDirLocation(): string { - return \dirname(__FILE__) . "/../"; - } - /** * @return string */ public function workStorageDirLocation(): string { - return $this->acceptanceTestsDirLocation() . $this->temporaryStorageSubfolderName() . "/"; + return UploadHelper::getAcceptanceTestsDir() . $this->temporaryStorageSubfolderName() . "/"; } /** diff --git a/tests/acceptance/bootstrap/PublicWebDavContext.php b/tests/acceptance/bootstrap/PublicWebDavContext.php index b6fc3583c4..968ca3e43b 100644 --- a/tests/acceptance/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/bootstrap/PublicWebDavContext.php @@ -26,6 +26,7 @@ use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; +use TestHelpers\UploadHelper; require_once 'bootstrap.php'; @@ -862,7 +863,7 @@ public function thePublicUploadsFileToInsideLastLinkSharedFolderUsingThePublicWe string $destination, ): void { $content = \file_get_contents( - $this->featureContext->acceptanceTestsDirLocation() . $source + UploadHelper::getAcceptanceTestsDir() . $source ); $response = $this->publicUploadContent( $destination, @@ -888,7 +889,7 @@ public function thePublicUploadsFileToInsideLastLinkSharedFolderWithPasswordUsin string $password ): void { $content = \file_get_contents( - $this->featureContext->acceptanceTestsDirLocation() . $source + UploadHelper::getAcceptanceTestsDir() . $source ); $response = $this->publicUploadContent( $destination, diff --git a/tests/acceptance/bootstrap/TUSContext.php b/tests/acceptance/bootstrap/TUSContext.php index 425555c6ef..6e6d208e6b 100644 --- a/tests/acceptance/bootstrap/TUSContext.php +++ b/tests/acceptance/bootstrap/TUSContext.php @@ -32,6 +32,7 @@ use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; +use TestHelpers\UploadHelper; require_once 'bootstrap.php'; @@ -364,7 +365,7 @@ public function uploadFileUsingTus( $client->setChecksumAlgorithm('sha1'); $client->setApiPath(WebDavHelper::getDavPath($davPathVersion, $suffixPath)); $client->setMetadata($uploadMetadata); - $sourceFile = $this->featureContext->acceptanceTestsDirLocation() . $source; + $sourceFile = UploadHelper::getAcceptanceTestsDir() . $source; $client->setKey((string)rand())->file($sourceFile, $destination); $this->featureContext->pauseUploadDelete(); @@ -518,7 +519,7 @@ public function userUploadsFileWithContentToWithMtimeUsingTUS( */ public function writeDataToTempFile(string $content): string { $temporaryFileName = \tempnam( - $this->featureContext->acceptanceTestsDirLocation(), + UploadHelper::getAcceptanceTestsDir(), "tus-upload-test-" ); if ($temporaryFileName === false) { diff --git a/tests/acceptance/bootstrap/WebDav.php b/tests/acceptance/bootstrap/WebDav.php index 033501b6cf..b4c3ab2e8d 100644 --- a/tests/acceptance/bootstrap/WebDav.php +++ b/tests/acceptance/bootstrap/WebDav.php @@ -1648,7 +1648,7 @@ public function uploadFile( ?bool $isGivenStep = false ): ResponseInterface { $user = $this->getActualUsername($user); - $file = \fopen($this->acceptanceTestsDirLocation() . $source, 'r'); + $file = \fopen(UploadHelper::getAcceptanceTestsDir() . $source, 'r'); $this->pauseUploadDelete(); $response = $this->makeDavRequest( $user, @@ -1781,7 +1781,7 @@ public function userUploadsAFileInChunk( } return $this->uploadFileWithHeaders( $user, - $this->acceptanceTestsDirLocation() . $source, + UploadHelper::getAcceptanceTestsDir() . $source, $destination, $headers, $noOfChunks @@ -2222,7 +2222,7 @@ public function userUploadsFileToWithMtimeUsingTheWebdavApi( $this->getBaseUrl(), $user, $this->getPasswordForUser($user), - $this->acceptanceTestsDirLocation() . $source, + UploadHelper::getAcceptanceTestsDir() . $source, $destination, $this->getStepLineRef(), ["X-OC-Mtime" => $mtime], @@ -2257,7 +2257,7 @@ public function userHasUploadedFileToWithMtimeUsingTheWebdavApi( $this->getBaseUrl(), $user, $this->getPasswordForUser($user), - $this->acceptanceTestsDirLocation() . $source, + UploadHelper::getAcceptanceTestsDir() . $source, $destination, $this->getStepLineRef(), ["X-OC-Mtime" => $mtime], diff --git a/tests/acceptance/features/cliCommands/uploadSessions.feature b/tests/acceptance/features/cliCommands/uploadSessions.feature index 169cd095ac..4def4cecb3 100644 --- a/tests/acceptance/features/cliCommands/uploadSessions.feature +++ b/tests/acceptance/features/cliCommands/uploadSessions.feature @@ -21,7 +21,7 @@ Feature: List upload sessions via CLI command And the CLI response should not contain these entries: | file0.txt | - + @antivirus Scenario: list all upload sessions that are currently in postprocessing Given the following configs have been set: | config | value | @@ -39,7 +39,7 @@ Feature: List upload sessions via CLI command And the CLI response should not contain these entries: | virusFile.txt | - + @antivirus Scenario: list all upload sessions that are infected by virus Given the following configs have been set: | config | value | @@ -109,7 +109,7 @@ Feature: List upload sessions via CLI command And the CLI response should not contain these entries: | file2.txt | - + @antivirus Scenario: clean all upload sessions that are not in post-processing Given the following configs have been set: | config | value | @@ -126,7 +126,7 @@ Feature: List upload sessions via CLI command And the CLI response should not contain these entries: | file1.txt | - + @antivirus Scenario: clean upload sessions that are not in post-processing and is not virus infected Given the following configs have been set: | config | value | diff --git a/tests/acceptance/scripts/generate-virus-files.sh b/tests/acceptance/scripts/generate-virus-files.sh deleted file mode 100755 index 1b53495c0c..0000000000 --- a/tests/acceptance/scripts/generate-virus-files.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# tests/acceptance/scripts/generate-virus-files.sh - -set -e - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -TARGET_DIR="$SCRIPT_DIR/../filesForUpload/filesWithVirus" - -echo "Generating EICAR test files..." - -mkdir -p "$TARGET_DIR" - -cd "$TARGET_DIR" - -echo "Downloading eicar.com..." -curl -s -o eicar.com https://secure.eicar.org/eicar.com - -echo "Downloading eicar_com.zip..." -curl -s -o eicar_com.zip https://secure.eicar.org/eicar_com.zip \ No newline at end of file diff --git a/tests/acceptance/scripts/run.sh b/tests/acceptance/scripts/run.sh index 408a4f3025..7eff837a75 100755 --- a/tests/acceptance/scripts/run.sh +++ b/tests/acceptance/scripts/run.sh @@ -547,7 +547,6 @@ fi export IPV4_URL export IPV6_URL -export FILES_FOR_UPLOAD="${SCRIPT_PATH}/filesForUpload/" TEST_LOG_FILE=$(mktemp) SCENARIOS_THAT_PASSED=0