From 44db268778a36eef9dd3ce056b2a0c618d133da3 Mon Sep 17 00:00:00 2001 From: sakshamgurung Date: Fri, 29 Oct 2021 16:07:54 +0900 Subject: [PATCH] Adds cli test for cleaning the orphaned remote storage --- .../features/bootstrap/FeatureContext.php | 3 + .../features/bootstrap/OccContext.php | 57 +++++++++++++++++-- .../cliExternalStorage/Sharing.feature | 27 +++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 tests/acceptance/features/cliExternalStorage/Sharing.feature diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 0a18af1cbe21..7a9d17556800 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -1142,6 +1142,9 @@ public function usingServer(?string $server):string { $this->baseUrl = $this->remoteBaseUrl; $this->currentServer = 'REMOTE'; } + echo "\n"; + echo "$this->currentServer = "; + echo "$this->baseUrl \n"; return $previousServer; } diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index 79f67e2cf6f6..661219eeb7e1 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -385,6 +385,17 @@ public function deleteSystemConfigKeyUsingTheOccCommand(string $key):void { ); } + /** + * + * @return void + * @throws Exception + */ + public function cleanOrphanedRemoteStoragesUsingOccCommand():void { + $this->invokingTheCommand( + "sharing:cleanup-remote-storages" + ); + } + /** * @param string $user * @@ -956,6 +967,33 @@ public function theOccCommandJsonOutputShouldNotReturnAnyData():void { ); } + /** + * @Then :noOfOrphanedShare orphaned remote storage should have been cleared + * + * @param int $noOfOrphanedShare + * + * @return void + * @throws Exception + */ + public function theOrphanedRemoteStorageShouldBeCleared(int $noOfOrphanedShare):void { + $this->theCommandShouldHaveBeenSuccessful(); + $commandOutput = $this->featureContext->getStdOutOfOccCommand(); + // removing blank lines + $commandOutput = implode("\n", array_filter(explode("\n", $commandOutput))); + // splitting strings based on newline into an array + $outputLines = preg_split("/\r\n|\n|\r/", $commandOutput); + // calculating total no of shares deleted from remote storage: first getting total length of the array + // then minus 2 for first two lines of scan info message + // then divide by 2 because each share delete has message of two line + $totalSharesDeleted = (\count($outputLines) - 2) / 2; + var_dump($outputLines); + Assert::assertEquals( + $noOfOrphanedShare, + $totalSharesDeleted, + "The command should delete '$noOfOrphanedShare' orphaned shares but it deletes '$totalSharesDeleted' orphaned shares." + ); + } + /** * @Given the administrator has set the default folder for received shares to :folder * @@ -988,6 +1026,7 @@ public function theAdministratorHasSetTheDefaultFolderForReceivedSharesTo(string * @param int $depth_infinity_allowed * * @return void + * @throws Exception */ public function theAdministratorHasSetDepthInfinityAllowedTo($depth_infinity_allowed) { $this->addSystemConfigKeyUsingTheOccCommand( @@ -2208,10 +2247,10 @@ public function administratorHasDeletedLocalStorageFolderUsingTheOccCommand(stri * @param string $folder * @param bool $mustExist * - * @return integer + * @return integer|bool * @throws Exception */ - public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true):int { + public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true) { $createdLocalStorage = []; $this->listLocalStorageMount(); $commandOutput = \json_decode($this->featureContext->getStdOutOfOccCommand()); @@ -2532,6 +2571,16 @@ public function theAdministratorDeletesAllTheVersionsForUser(string $user):void $this->deleteAllVersionsForUserUsingOccCommand($user); } + /** + * @When the administrator cleanups all the orphaned remote storages of shares + * + * @return void + * @throws Exception + */ + public function theAdministratorCleanupsAllTheOrphanedRemoteStoragesOfShares():void { + $this->cleanOrphanedRemoteStoragesUsingOccCommand(); + } + /** * @When the administrator deletes all the versions for the following users: * @@ -2793,10 +2842,10 @@ public function theAdministratorHasClearedTheVersionsForAllUsers():void { * * @param string $job * - * @return string + * @return string|bool * @throws Exception */ - public function getLastJobIdForJob(string $job):string { + public function getLastJobIdForJob(string $job) { $this->getAllJobsInBackgroundQueueUsingOccCommand(); $commandOutput = $this->featureContext->getStdOutOfOccCommand(); $lines = SetupHelper::findLines( diff --git a/tests/acceptance/features/cliExternalStorage/Sharing.feature b/tests/acceptance/features/cliExternalStorage/Sharing.feature new file mode 100644 index 000000000000..fc5d3aaf4216 --- /dev/null +++ b/tests/acceptance/features/cliExternalStorage/Sharing.feature @@ -0,0 +1,27 @@ +@cli @api @federation-app-required @files_sharing-app-required +Feature: + As a admin + I want to cleanup orphaned remote storages + So that users will not get undesirable failure + + Background: + Given using server "REMOTE" + And user "Alice" has been created with default attributes and without skeleton files + And using server "LOCAL" + And user "Brian" has been created with default attributes and without skeleton files + + Scenario Outline: Clean up the orphaned remote storage after deleting the original shares + Given using OCS API version "" + And using server "REMOTE" + And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt" + And user "Alice" from server "REMOTE" has shared "/textfile0.txt" with user "Brian" from server "LOCAL" + And user "Brian" from server "LOCAL" has accepted the last pending share + And user "Alice" has deleted the last share + And using server "LOCAL" + When the administrator cleanups all the orphaned remote storages of shares + Then 1 orphaned remote storage should have been cleared + + Examples: + | ocs-api-version | + | 1 | + | 2 | \ No newline at end of file