diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index f96bfb25ac5d..eba74fb305c7 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -711,6 +711,7 @@ default: - FederationContext: - OccContext: - WebDavPropertiesContext: + - PublicWebDavContext: cliLocalStorage: paths: diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index abb669c42789..47d2c3851cc2 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -201,23 +201,19 @@ public function setExtStorageReadOnlyUsingTheOccCommand(string $mountPoint, bool /** * @param string $mountPoint - * @param boolean $setting + * @param boolean $enable * * @return void * @throws Exception */ - public function setExtStorageSharingUsingTheOccCommand(string $mountPoint, bool $setting = true):void { + public function setExtStorageSharingUsingTheOccCommand(string $mountPoint, bool $enable = true):void { $command = "files_external:option"; $mountId = $this->featureContext->getStorageId($mountPoint); $key = "enable_sharing"; - if ($setting) { - $value = "true"; - } else { - $value = "false"; - } + $value = $enable ? "true" : "false"; $this->invokingTheCommand( "$command $mountId $key $value" @@ -1231,6 +1227,19 @@ public function theAdminHasSetTheExtStorageToSharing(string $mountPoint):void { $this->theCommandShouldHaveBeenSuccessful(); } + /** + * @When /^the administrator (enables|disables) sharing for the external storage "([^"]*)" using the occ command$/ + * + * @param string $action + * @param string $mountPoint + * + * @return void + * @throws Exception + */ + public function theAdminDisablesSharingForTheExtStorage(string $action, string $mountPoint):void { + $this->setExtStorageSharingUsingTheOccCommand($mountPoint, $action === "enables"); + } + /** * @When the administrator sets the external storage :mountPoint to be never scanned automatically using the occ command * @@ -1460,6 +1469,34 @@ public function addRemoveUserOrGroupToOrFromMount( ); } + /** + * @param string $mount + * @param string $userOrGroup + * + * @return array + * @throws Exception + */ + public function getListOfApplicableUserOrGroupForMount(string $mount, string $userOrGroup):array { + $validArgs = ["users", "groups"]; + if (!\in_array($userOrGroup, $validArgs)) { + throw new Exception( + "Invalid key provided. Expected:" . + \implode(", ", $validArgs) . + "Found: " . $userOrGroup + ); + } + $mountId = $this->getMountIdForLocalStorage($mount); + $this->featureContext->runOcc( + [ + 'files_external:applicable', + $mountId, + '--output=json' + ] + ); + $commandOutput = \json_decode($this->featureContext->getStdOutOfOccCommand()); + return ($userOrGroup === "users") ? $commandOutput->users : $commandOutput->groups; + } + /** * @param string $action * @param string $userOrGroup @@ -1559,6 +1596,62 @@ public function theAdminAddsRemovesAsTheApplicableUserForMountUsingTheOccCommand ); } + /** + * @Then /^the following (users|groups) should be listed as applicable for local storage mount "([^"]*)"$/ + * + * @param string $usersOrGroups comma separated lists eg: Alice, Brian + * @param string $localStorage + * @param TableNode $applicable + * + * @return void + * @throws Exception + */ + public function theFollowingUsersOrGroupsShouldBeListedAsApplicable(string $usersOrGroups, string $localStorage, TableNode $applicable): void { + $this->featureContext->verifyTableNodeRows( + $applicable, + [], + ["users", "groups"] + ); + $expectedApplicableList = $applicable->getRowsHash(); + $actualApplicableList = $this->getListOfApplicableUserOrGroupForMount($localStorage, $usersOrGroups); + foreach ($expectedApplicableList as $expectedApplicable) { + Assert::assertContains( + $expectedApplicable, + $actualApplicableList, + __METHOD__ + . $usersOrGroups + . " not found!\nexpected: " + . $expectedApplicable + . " to be in the list [" + . \implode(", ", $actualApplicableList) + . "]." + ); + } + } + + /** + * @Then /^the applicable (users|groups) list should be empty for local storage mount "([^"]*)"$/ + * + * @param string $usersOrGroups + * @param string $localStorage + * + * @return void + * @throws Exception + */ + public function theApplicableUsersOrGroupsListShouldBeEmptyForLocalStorageMount(string $usersOrGroups, string $localStorage): void { + $actualApplicableList = $this->getListOfApplicableUserOrGroupForMount($localStorage, $usersOrGroups); + Assert::assertEquals( + 0, + \count($actualApplicableList), + __METHOD__ + . "Expected empty list for applicable " + . $usersOrGroups + . " but found: [" + . \implode(", ", $actualApplicableList) + . "]." + ); + } + /** * @When the administrator removes all from the applicable users and groups for local storage mount :localStorage using the occ command * @@ -1603,6 +1696,35 @@ public function theAdminHasAddedRemovedTheApplicableUserForMountUsingTheOccComma $mount ); $this->theCommandShouldHaveBeenSuccessful(); + // making plural "users" or "groups" + $userOrGroup = $userOrGroup . "s"; + $actualApplicableList = $this->getListOfApplicableUserOrGroupForMount($mount, $userOrGroup); + + if ($action === "added") { + Assert::assertContains( + $user, + $actualApplicableList, + __METHOD__ + . " The expected applicable " + . $userOrGroup + . " is not present in the actual list of applicable " + . $userOrGroup + . " for mount point: " + . $mount . ".\n" + ); + } else { + Assert::assertNotContains( + $user, + $actualApplicableList, + __METHOD__ + . " The applicable " + . $userOrGroup + . " is present in the actual list of applicable " + . $userOrGroup + . " for mount point: " + . $mount . ".\n" + ); + } } /** @@ -2261,13 +2383,13 @@ public function administratorHasDeletedLocalStorageFolderUsingTheOccCommand(stri /** * @param string $folder - * @param bool $mustExist * - * @return integer|bool + * @return integer|null * @throws Exception */ - public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true) { + public function getMountIdForLocalStorage(string $folder): ?int { $createdLocalStorage = []; + $mount_id = null; $this->listLocalStorageMount(); $commandOutput = \json_decode($this->featureContext->getStdOutOfOccCommand()); foreach ($commandOutput as $i) { @@ -2278,6 +2400,20 @@ public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mount_id = $key; } } + + return (int) $mount_id; + } + + /** + * @param string $folder + * @param bool $mustExist + * + * @return integer|bool + * @throws Exception + */ + public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool $mustExist = true) { + $mount_id = $this->getMountIdForLocalStorage($folder); + if (!isset($mount_id)) { if ($mustExist) { throw new Exception("Id not found for folder to be deleted"); @@ -2285,7 +2421,7 @@ public function deleteLocalStorageFolderUsingTheOccCommand(string $folder, bool return false; } $this->invokingTheCommand('files_external:delete --yes ' . $mount_id); - return (int) $mount_id; + return $mount_id; } /** @@ -2313,7 +2449,7 @@ public function theAdministratorImportsTheMountFromFileUsingTheOccCommand(string } /** - * @When the administrator has exported the local storage mounts using the occ command + * @Given the administrator has exported the local storage mounts using the occ command * * @return void * @throws Exception @@ -2323,6 +2459,28 @@ public function theAdministratorHasExportedTheMountsUsingTheOccCommand():void { $this->theCommandShouldHaveBeenSuccessful(); } + /** + * @Then the command should output configuration for local storage mount :mount + * + * @param string $mount + * + * @return void + * @throws Exception + */ + public function theOutputShouldContainConfigurationForMount(string $mount):void { + $actualConfig = null; + + $commandOutput = \json_decode($this->featureContext->getStdOutOfOccCommand()); + foreach ($commandOutput as $i) { + if ($mount === \ltrim($i->mount_point, '/')) { + $actualConfig = $i; + break; + } + } + + Assert::assertNotNull($actualConfig, 'Configuration for local storage mount ' . $mount . ' not found.'); + } + /** * @When the administrator verifies the mount configuration for local storage :localStorage using the occ command * @@ -3224,6 +3382,30 @@ public function adminHasCreatedAnExternalMountPointWithFollowingConfigUsingTheOc $this->theCommandShouldHaveBeenSuccessful(); } + /** + * @param string $mountPoint + * + * @return void + * @throws Exception + */ + private function deleteExternalMountPointUsingTheAdmin(string $mountPoint):void { + $mount_id = $this->administratorDeletesFolder($mountPoint); + $this->featureContext->popStorageId($mount_id); + } + + /** + * @Given the administrator has deleted external storage with mount point :mountPoint + * + * @param string $mountPoint + * + * @return void + * @throws Exception + */ + public function adminHasDeletedExternalMountPoint(string $mountPoint):void { + $this->deleteExternalMountPointUsingTheAdmin($mountPoint); + $this->theCommandShouldHaveBeenSuccessful(); + } + /** * @When the administrator deletes external storage with mount point :mountPoint * @@ -3233,8 +3415,7 @@ public function adminHasCreatedAnExternalMountPointWithFollowingConfigUsingTheOc * @throws Exception */ public function adminDeletesExternalMountPoint(string $mountPoint):void { - $mount_id = $this->administratorDeletesFolder($mountPoint); - $this->featureContext->popStorageId($mount_id); + $this->deleteExternalMountPointUsingTheAdmin($mountPoint); } /** diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 75babbe4c02c..c26da3d35487 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -22,6 +22,7 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Exception\BadResponseException; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Ring\Exception\ConnectException; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; @@ -2993,6 +2994,42 @@ public function userHasUploadedAFileWithContentTo( return $fileId; } + /** + * @Given the administrator has created a json file with exported config of local storage mount :mount to :destination in temporary storage + * + * @param string $mount + * @param string $destination + * + * @return void + * @throws Exception + * @throws GuzzleException + */ + public function theAdminHasCreatedAJsonFileWithExportedMountConfig( + string $mount, + string $destination + ): void { + $actualConfig = null; + $commandOutput = \json_decode( + SetupHelper::runOcc( + ['files_external:export'], + $this->getStepLineRef() + )['stdOut'] + ); + + //identifying the correct config and also removing the "mount id" property + foreach ($commandOutput as $i) { + if ($mount === \ltrim($i->mount_point, '/')) { + unset($i->mount_id); + $actualConfig = $i; + break; + } + } + + $actualConfig = json_encode($actualConfig); + $this->copyContentToFileInTemporaryStorageOnSystemUnderTest($destination, $actualConfig); + $this->theFileWithContentShouldExistInTheServerRoot(TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER . "/$destination", $actualConfig); + } + /** * @Given /^user "([^"]*)" has uploaded the following files with content "([^"]*)"$/ * diff --git a/tests/acceptance/features/cliExternalStorage/filesExternalWebdavOwncloud.feature b/tests/acceptance/features/cliExternalStorage/filesExternalWebdavOwncloud.feature index 69b245ed5d74..bd6164237bc9 100644 --- a/tests/acceptance/features/cliExternalStorage/filesExternalWebdavOwncloud.feature +++ b/tests/acceptance/features/cliExternalStorage/filesExternalWebdavOwncloud.feature @@ -61,3 +61,189 @@ Feature: using files external service with storage as webdav_owncloud Then the command should have been successful When the administrator lists all local storage mount points using the occ command Then mount point "/TestMountPoint1" should not be listed as an external storage + + + Scenario: adding an user to a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + When the administrator adds user "Brian" as the applicable user for local storage mount "TestMountPoint" using the occ command + Then the command should have been successful + And the following users should be listed as applicable for local storage mount "TestMountPoint" + | users | Brian | + And as "Brian" file "TestMountPoint/test.txt" should exist + + + Scenario: removing an user from a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And the administrator has added user "Brian" as the applicable user for local storage mount "TestMountPoint" + And the administrator has added user "admin" as the applicable user for local storage mount "TestMountPoint" + When the administrator removes user "Brian" from the applicable user for local storage mount "TestMountPoint" using the occ command + Then the command should have been successful + And the following users should be listed as applicable for local storage mount "TestMountPoint" + | users | admin | + And as "Brian" file "TestMountPoint/test.txt" should not exist + + + Scenario: adding a group to a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + When the administrator adds group "grp1" as the applicable group for local storage mount "TestMountPoint" using the occ command + Then the command should have been successful + And the following groups should be listed as applicable for local storage mount "TestMountPoint" + | groups | grp1 | + And as "Brian" file "TestMountPoint/test.txt" should exist + + + Scenario: removing a group from a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And the administrator has added group "grp1" as the applicable group for local storage mount "TestMountPoint" + And the administrator has added user "admin" as the applicable user for local storage mount "TestMountPoint" + When the administrator removes group "grp1" from the applicable group for local storage mount "TestMountPoint" using the occ command + Then the command should have been successful + And the applicable groups list should be empty for local storage mount "TestMountPoint" + And as "Brian" file "TestMountPoint/test.txt" should not exist + + + Scenario: removing all users and groups from a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And the administrator has added group "grp1" as the applicable group for local storage mount "TestMountPoint" + And the administrator has added user "admin" as the applicable user for local storage mount "TestMountPoint" + And the administrator has added user "Brian" as the applicable user for local storage mount "TestMountPoint" + When the administrator removes all from the applicable users and groups for local storage mount "TestMountPoint" using the occ command + Then the command should have been successful + And the applicable users list should be empty for local storage mount "TestMountPoint" + And the applicable groups list should be empty for local storage mount "TestMountPoint" + + + Scenario: exporting config from existing webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "Brian" has been created with default attributes and without skeleton files + And group "grp1" has been created + And user "Brian" has been added to group "grp1" + And the administrator has added group "grp1" as the applicable group for local storage mount "TestMountPoint" + And the administrator has added user "admin" as the applicable user for local storage mount "TestMountPoint" + And the administrator has added user "Brian" as the applicable user for local storage mount "TestMountPoint" + When the administrator exports the local storage mounts using the occ command + Then the command should have been successful + And the command should output configuration for local storage mount "TestMountPoint" + + + Scenario: importing config to create a webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And the administrator has created a json file with exported config of local storage mount "TestMountPoint" to "mountConfig.json" in temporary storage + And the administrator has deleted external storage with mount point "TestMountPoint" + When the administrator imports the local storage mount from file "mountConfig.json" using the occ command + Then the command should have been successful + + + Scenario: setting read-only option for webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And the administrator has added user "Brian" as the applicable user for local storage mount "TestMountPoint" + When the administrator sets the external storage "TestMountPoint" to read-only using the occ command + Then the command should have been successful + And user "Brian" should not be able to delete file "TestMountPoint/test.txt" + And using server "REMOTE" + And user "Alice" should be able to delete file "TestMnt/test.txt" + + + Scenario: disabling and enabling share option for webdav_owncloud external storage + Given the administrator has created an external mount point with the following configuration about user "Alice" using the occ command + | host | %remote_server% | + | root | TestMnt | + | secure | false | + | user | %username% | + | password | %password% | + | storage_backend | owncloud | + | mount_point | TestMountPoint | + | authentication_backend | password::password | + And user "admin" has uploaded file with content "Hello from Local!" to "TestMountPoint/test.txt" + And user "Brian" has been created with default attributes and without skeleton files + And user "Carol" has been created with default attributes and without skeleton files + And the administrator has added user "Brian" as the applicable user for local storage mount "TestMountPoint" + When the administrator disables sharing for the external storage "TestMountPoint" using the occ command + Then the command should have been successful + And user "Brian" should not be able to share file "TestMountPoint/test.txt" with user "Carol" using the sharing API + When the administrator enables sharing for the external storage "TestMountPoint" using the occ command + Then user "Brian" should be able to share file "TestMountPoint/test.txt" with user "Carol" using the sharing API + And as "Carol" file "test.txt" should exist +