Merge pull request #10229 from owncloud/cli-tests
[tests-only][full-ci] add tests for CLI command uploads sessions
This commit is contained in:
@@ -182,6 +182,13 @@ config = {
|
|||||||
"cliCommands",
|
"cliCommands",
|
||||||
],
|
],
|
||||||
"skip": False,
|
"skip": False,
|
||||||
|
"antivirusNeeded": True,
|
||||||
|
"extraServerEnvironment": {
|
||||||
|
"ANTIVIRUS_SCANNER_TYPE": "clamav",
|
||||||
|
"ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310",
|
||||||
|
"OCIS_ASYNC_UPLOADS": True,
|
||||||
|
"OCIS_ADD_RUN_SERVICES": "antivirus",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"apiTests": {
|
"apiTests": {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use Behat\Behat\Context\Context;
|
|||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use TestHelpers\CliHelper;
|
use TestHelpers\CliHelper;
|
||||||
use TestHelpers\OcisConfigHelper;
|
use TestHelpers\OcisConfigHelper;
|
||||||
|
use Behat\Gherkin\Node\TableNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CLI context
|
* CLI context
|
||||||
@@ -233,4 +234,92 @@ class CliContext implements Context {
|
|||||||
Assert::assertStringNotContainsString($output, $jsonResponse["message"]);
|
Assert::assertStringNotContainsString($output, $jsonResponse["message"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When the administrator lists all the upload sessions
|
||||||
|
* @When the administrator lists all the upload sessions with flag :flag
|
||||||
|
*
|
||||||
|
* @param string|null $flag
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theAdministratorListsAllTheUploadSessions(?string $flag = null): void {
|
||||||
|
if ($flag) {
|
||||||
|
$flag = "--$flag";
|
||||||
|
}
|
||||||
|
$command = "storage-users uploads sessions --json $flag";
|
||||||
|
$body = [
|
||||||
|
"command" => $command
|
||||||
|
];
|
||||||
|
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When the administrator cleans all expired upload sessions
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theAdministratorCleansAllExpiredUploadSessions(): void {
|
||||||
|
$command = "storage-users uploads sessions --expired --clean --json";
|
||||||
|
$body = [
|
||||||
|
"command" => $command
|
||||||
|
];
|
||||||
|
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then /^the CLI response (should|should not) contain these entries:$/
|
||||||
|
*
|
||||||
|
* @param string $shouldOrNot
|
||||||
|
* @param TableNode $table
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theCLIResponseShouldContainTheseEntries(string $shouldOrNot, TableNode $table): void {
|
||||||
|
$expectedFiles = $table->getColumn(0);
|
||||||
|
$responseBody = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse());
|
||||||
|
|
||||||
|
// $responseBody["message"] contains a message info with the array of output json of the upload sessions command
|
||||||
|
// Example Output: "INFO memory is not limited, skipping package=github.com/KimMachineGun/automemlimit/memlimit [{<output-json>}]"
|
||||||
|
// So, only extracting the array of output json from the message
|
||||||
|
preg_match('/(\[.*\])/', $responseBody["message"], $matches);
|
||||||
|
$responseArray = \json_decode($matches[1], null, 512, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
$resourceNames = [];
|
||||||
|
foreach ($responseArray as $item) {
|
||||||
|
if (isset($item->filename)) {
|
||||||
|
$resourceNames[] = $item->filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($shouldOrNot === "should not") {
|
||||||
|
foreach ($expectedFiles as $expectedFile) {
|
||||||
|
Assert::assertNotTrue(
|
||||||
|
\in_array($expectedFile, $resourceNames),
|
||||||
|
"The resource '$expectedFile' was found in the response."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($expectedFiles as $expectedFile) {
|
||||||
|
Assert::assertTrue(
|
||||||
|
\in_array($expectedFile, $resourceNames),
|
||||||
|
"The resource '$expectedFile' was not found in the response."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @AfterScenario @cli-uploads-sessions
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cleanUploadsSessions(): void {
|
||||||
|
$command = "storage-users uploads sessions --clean";
|
||||||
|
$body = [
|
||||||
|
"command" => $command
|
||||||
|
];
|
||||||
|
$response = CliHelper::runCommand($body);
|
||||||
|
Assert::assertEquals("200", $response->getStatusCode(), "Failed to clean upload sessions");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
@env-config @cli-uploads-sessions
|
||||||
|
Feature: List upload sessions via CLI command
|
||||||
|
As a user
|
||||||
|
I want to list the upload sessions
|
||||||
|
So that I can manage the upload sessions
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given user "Alice" has been created with default attributes and without skeleton files
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: user lists all upload sessions
|
||||||
|
Given user "Alice" has uploaded file with content "uploaded content" to "/file0.txt"
|
||||||
|
And the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt"
|
||||||
|
When the administrator lists all the upload sessions
|
||||||
|
Then the command should be successful
|
||||||
|
And the CLI response should contain these entries:
|
||||||
|
| file1.txt |
|
||||||
|
| file2.txt |
|
||||||
|
And the CLI response should not contain these entries:
|
||||||
|
| file0.txt |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: user lists all upload sessions that are currently in postprocessing
|
||||||
|
Given the following configs have been set:
|
||||||
|
| config | value |
|
||||||
|
| POSTPROCESSING_STEPS | virusscan |
|
||||||
|
| ANTIVIRUS_INFECTED_FILE_HANDLING | abort |
|
||||||
|
And user "Alice" has uploaded file "filesForUpload/filesWithVirus/eicar.com" to "/virusFile.txt"
|
||||||
|
And the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt"
|
||||||
|
When the administrator lists all the upload sessions with flag "processing"
|
||||||
|
Then the command should be successful
|
||||||
|
And the CLI response should contain these entries:
|
||||||
|
| file1.txt |
|
||||||
|
| file2.txt |
|
||||||
|
And the CLI response should not contain these entries:
|
||||||
|
| virusFile.txt |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: user lists all upload sessions that are infected by virus
|
||||||
|
Given the following configs have been set:
|
||||||
|
| config | value |
|
||||||
|
| POSTPROCESSING_STEPS | virusscan |
|
||||||
|
| ANTIVIRUS_INFECTED_FILE_HANDLING | abort |
|
||||||
|
And user "Alice" has uploaded file "filesForUpload/filesWithVirus/eicar.com" to "/virusFile.txt"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||||
|
When the administrator lists all the upload sessions with flag "has-virus"
|
||||||
|
Then the command should be successful
|
||||||
|
And the CLI response should contain these entries:
|
||||||
|
| virusFile.txt |
|
||||||
|
And the CLI response should not contain these entries:
|
||||||
|
| file1.txt |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: user lists all expired upload sessions
|
||||||
|
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt"
|
||||||
|
And the config "STORAGE_USERS_UPLOAD_EXPIRATION" has been set to "0"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt"
|
||||||
|
And user "Alice" has uploaded file with content "uploaded content" to "/file3.txt"
|
||||||
|
When the administrator lists all the upload sessions with flag "expired"
|
||||||
|
Then the command should be successful
|
||||||
|
And the CLI response should contain these entries:
|
||||||
|
| file2.txt |
|
||||||
|
| file3.txt |
|
||||||
|
And the CLI response should not contain these entries:
|
||||||
|
| file1.txt |
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: user cleans all expired upload sessions
|
||||||
|
Given the config "POSTPROCESSING_DELAY" has been set to "10s"
|
||||||
|
And user "Alice" has uploaded file with content "upload content" to "/file1.txt"
|
||||||
|
And the config "STORAGE_USERS_UPLOAD_EXPIRATION" has been set to "0"
|
||||||
|
And user "Alice" has uploaded file with content "upload content" to "/file2.txt"
|
||||||
|
And user "Alice" has uploaded file with content "upload content" to "/file3.txt"
|
||||||
|
When the administrator cleans all expired upload sessions
|
||||||
|
Then the command should be successful
|
||||||
|
And the CLI response should contain these entries:
|
||||||
|
| file2.txt |
|
||||||
|
| file3.txt |
|
||||||
|
And the CLI response should not contain these entries:
|
||||||
|
| file1.txt |
|
||||||
Reference in New Issue
Block a user