Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .woodpecker.star
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ config = {
],
"skip": False,
"antivirusNeeded": True,
"generateVirusFiles": True,
"extraServerEnvironment": {
"ANTIVIRUS_SCANNER_TYPE": "clamav",
"ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310",
Expand Down Expand Up @@ -301,7 +300,6 @@ config = {
"skip": False,
"withRemotePhp": [True],
"antivirusNeeded": True,
"generateVirusFiles": True,
"extraServerEnvironment": {
"ANTIVIRUS_SCANNER_TYPE": "clamav",
"ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310",
Expand Down Expand Up @@ -1234,7 +1232,6 @@ def localApiTestPipeline(ctx):
"withRemotePhp": [True],
"enableWatchFs": [False],
"ldapNeeded": False,
"generateVirusFiles": False,
}

if "localApiTests" in config:
Expand Down Expand Up @@ -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 []) +
Expand All @@ -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)

Expand All @@ -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))
Expand Down
9 changes: 0 additions & 9 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
15 changes: 11 additions & 4 deletions tests/acceptance/TestHelpers/UploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
}
}
3 changes: 2 additions & 1 deletion tests/acceptance/bootstrap/ChecksumContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Psr\Http\Message\ResponseInterface;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
use TestHelpers\UploadHelper;

require_once 'bootstrap.php';

Expand All @@ -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,
Expand Down
42 changes: 34 additions & 8 deletions tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() . "/";
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
use TestHelpers\UploadHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/bootstrap/TUSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use TestHelpers\HttpRequestHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\BehatHelper;
use TestHelpers\UploadHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1781,7 +1781,7 @@ public function userUploadsAFileInChunk(
}
return $this->uploadFileWithHeaders(
$user,
$this->acceptanceTestsDirLocation() . $source,
UploadHelper::getAcceptanceTestsDir() . $source,
$destination,
$headers,
$noOfChunks
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/features/cliCommands/uploadSessions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down
19 changes: 0 additions & 19 deletions tests/acceptance/scripts/generate-virus-files.sh

This file was deleted.

1 change: 0 additions & 1 deletion tests/acceptance/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down