From bf63318cc27666161c0e0590504e9747952cca03 Mon Sep 17 00:00:00 2001 From: Hari Bhandari Date: Mon, 29 Jul 2019 14:53:45 +0545 Subject: [PATCH] acceptance test for attempt to modify group share permissions when group sharing is off --- .../features/bootstrap/WebUIFilesContext.php | 4 +- .../bootstrap/WebUISharingContext.php | 57 +++++++++++++++---- tests/acceptance/features/lib/FilesPage.php | 2 +- .../lib/FilesPageElement/SharingDialog.php | 33 ++++++++--- .../restrictReSharing.feature | 2 +- .../restrictSharing.feature | 36 ++++++++++++ .../federationSharing.feature | 6 +- .../shareWithUsers.feature | 16 +++--- 8 files changed, 121 insertions(+), 35 deletions(-) diff --git a/tests/acceptance/features/bootstrap/WebUIFilesContext.php b/tests/acceptance/features/bootstrap/WebUIFilesContext.php index 12f2d39c5b8a..bd8de17d9e24 100644 --- a/tests/acceptance/features/bootstrap/WebUIFilesContext.php +++ b/tests/acceptance/features/bootstrap/WebUIFilesContext.php @@ -301,8 +301,8 @@ public function theUserTriesToBrowseDirectlyToDetailsTabOfFileInFolder( } /** - * @Given the user has browsed directly to display the details of file :fileName in folder :folderName - * @When the user browses directly to display the details of file :fileName in folder :folderName + * @Given the user has browsed directly to display the details of file/folder :fileName in folder :folderName + * @When the user browses directly to display the details of file/folder :fileName in folder :folderName * * @param string $fileName * @param string $folderName diff --git a/tests/acceptance/features/bootstrap/WebUISharingContext.php b/tests/acceptance/features/bootstrap/WebUISharingContext.php index 7b106c26d142..b10f490d5a7a 100644 --- a/tests/acceptance/features/bootstrap/WebUISharingContext.php +++ b/tests/acceptance/features/bootstrap/WebUISharingContext.php @@ -247,6 +247,37 @@ public function theUserOpensTheShareDialogForFileFolder($name) { ); } + /** + * @Then /^group ((?:'[^']*')|(?:"[^"]*")) should (not|)\s?be listed in the shared with list$/ + * + * @param string $groupName + * @param string $shouldOrNot + * + * @return void + * @throws \Exception + */ + public function shouldBeListedInTheSharedWithList( + $groupName, + $shouldOrNot + ) { + $should = ($shouldOrNot !== "not"); + // The capturing groups of the regex include the quotes at each + // end of the captured string, so trim them. + $groupName = \trim($groupName, '""'); + $presence = $this->sharingDialog->isGroupPresentInShareWithList($groupName); + if ($should) { + PHPUnit\Framework\Assert::assertTrue( + $presence, + "group $groupName is not listed in share with list" + ); + } else { + PHPUnit\Framework\Assert::assertFalse( + $presence, + "group $groupName is listed in share with list" + ); + } + } + /** * @Given the user has opened the public link share tab * @When the user opens the public link share tab @@ -566,9 +597,10 @@ public function theUserTypesInTheShareWithField($input) { } /** - * @When the user sets the sharing permissions of :userName for :fileName using the webUI to - * @Given the user has set the sharing permissions of :userName for :fileName using the webUI to + * @When /^the user sets the sharing permissions of (user|group) ((?:[^']*)|(?:[^"]*)) for ((?:'[^']*')|(?:"[^"]*")) using the webUI to$/ + * @Given /^the user has set the sharing permissions of (user|group) ((?:'[^']*')|(?:"[^"]*")) for ((?:'[^']*')|(?:"[^"]*")) using the webUI to$/ * + * @param string $userOrGroup * @param string $userName * @param string $fileName * @param TableNode $permissionsTable table with two columns and no heading @@ -582,19 +614,22 @@ public function theUserTypesInTheShareWithField($input) { * @throws \Exception */ public function theUserSetsTheSharingPermissionsOfForOnTheWebUI( - $userName, $fileName, TableNode $permissionsTable + $userOrGroup, $userName, $fileName, TableNode $permissionsTable ) { - $userName = $this->featureContext->substituteInLineCodes($userName); - $this->theUserOpensTheShareDialogForFileFolder($fileName); + // The capturing groups of the regex include the quotes at each + // end of the captured string, so trim them. + $userName = $this->featureContext->substituteInLineCodes(\trim($userName, '""')); + $this->theUserOpensTheShareDialogForFileFolder(\trim($fileName, '""')); $this->sharingDialog->setSharingPermissions( - $userName, $permissionsTable->getRowsHash(), $this->getSession() + $userOrGroup, $userName, $permissionsTable->getRowsHash(), $this->getSession() ); } /** - * @Then the following permissions are seen for :fileName in the sharing dialog for user :userName + * @Then /^the following permissions are seen for ((?:[^']*)|(?:[^"]*)) in the sharing dialog for (user|group) ((?:[^']*)|(?:[^"]*))$/ * * @param string $fileName + * @param string $userOrGroup * @param string $userName * @param TableNode $permissionsTable table with two columns and no heading * first column one of the permissions @@ -607,12 +642,12 @@ public function theUserSetsTheSharingPermissionsOfForOnTheWebUI( * @throws \Exception */ public function theFollowingPermissionsAreSeenForInTheSharingDialogFor( - $fileName, $userName, TableNode $permissionsTable + $fileName, $userOrGroup, $userName, TableNode $permissionsTable ) { - $userName = $this->featureContext->substituteInLineCodes($userName); - $this->theUserOpensTheShareDialogForFileFolder($fileName); + $userName = $this->featureContext->substituteInLineCodes(\trim($userName, '""')); + $this->theUserOpensTheShareDialogForFileFolder(\trim($fileName, '""')); $this->sharingDialog->checkSharingPermissions( - $userName, $permissionsTable->getRowsHash(), $this->getSession() + $userOrGroup, $userName, $permissionsTable->getRowsHash(), $this->getSession() ); } diff --git a/tests/acceptance/features/lib/FilesPage.php b/tests/acceptance/features/lib/FilesPage.php index 36198bfb402b..2b25cdfc55a9 100644 --- a/tests/acceptance/features/lib/FilesPage.php +++ b/tests/acceptance/features/lib/FilesPage.php @@ -74,7 +74,7 @@ protected function getFileNameMatchXpath() { protected function getEmptyContentXpath() { return $this->emptyContentXpath; } - + /** * {@inheritDoc} * diff --git a/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php b/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php index 4f712a66c4ef..e29479568064 100644 --- a/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php +++ b/tests/acceptance/features/lib/FilesPageElement/SharingDialog.php @@ -53,6 +53,7 @@ class SharingDialog extends OwncloudPage { private $sharerInformationXpath = ".//*[@class='reshare']"; private $sharedWithAndByRegEx = "^(?:[A-Z]\s)?Shared with you(?: and the group (.*))? by (.*)$"; private $permissionsFieldByUserName = ".//*[@id='shareWithList']//*[@class='has-tooltip username' and .='%s']/.."; + private $permissionsFieldByGroupName = ".//*[@id='shareWithList']//*[@class='has-tooltip username' and .='%s (group)']/.."; private $permissionLabelXpath = ".//label[@for='%s']"; private $showCrudsXpath = ".//*[@class='showCruds']"; private $publicLinksShareTabXpath = ".//li[contains(@class,'subtab-publicshare')]"; @@ -323,6 +324,7 @@ public function shareWithGroup( /** * + * @param string $userOrGroup * @param string $shareReceiverName * @param array $permissions [['permission' => 'yes|no']] * @param Session $session @@ -331,13 +333,20 @@ public function shareWithGroup( * @return void */ public function setSharingPermissions( + $userOrGroup, $shareReceiverName, $permissions, Session $session ) { - $xpathLocator = \sprintf( - $this->permissionsFieldByUserName, $shareReceiverName - ); + if ($userOrGroup == "group") { + $xpathLocator = \sprintf( + $this->permissionsFieldByGroupName, $shareReceiverName + ); + } else { + $xpathLocator = \sprintf( + $this->permissionsFieldByUserName, $shareReceiverName + ); + } $permissionsField = $this->waitTillElementIsNotNull($xpathLocator); $this->assertElementNotNull( $permissionsField, @@ -410,6 +419,7 @@ public function setSharingPermissions( /** * + * @param string $userOrGroup * @param string $shareReceiverName * @param array $permissions [['permission' => 'yes|no']] * @param Session $session @@ -418,13 +428,20 @@ public function setSharingPermissions( * @return void */ public function checkSharingPermissions( + $userOrGroup, $shareReceiverName, $permissions, Session $session ) { - $xpathLocator = \sprintf( - $this->permissionsFieldByUserName, $shareReceiverName - ); + if ($userOrGroup == "group") { + $xpathLocator = \sprintf( + $this->permissionsFieldByGroupName, $shareReceiverName + ); + } else { + $xpathLocator = \sprintf( + $this->permissionsFieldByUserName, $shareReceiverName + ); + } $permissionsField = $this->waitTillElementIsNotNull($xpathLocator); $this->assertElementNotNull( $permissionsField, @@ -718,9 +735,7 @@ public function isGroupPresentInShareWithList($groupName) { $shareWithList = $this->getShareWithList(); foreach ($shareWithList as $group) { $actualGroupName = $group->find('xpath', $this->userOrGroupNameSpanXpath); - if ($actualGroupName->getHtml() === \sprintf($this->groupFramework, $groupName)) { - return true; - } + return $actualGroupName->getHtml() === \sprintf($this->groupFramework, $groupName); } return false; } diff --git a/tests/acceptance/features/webUIRestrictSharing/restrictReSharing.feature b/tests/acceptance/features/webUIRestrictSharing/restrictReSharing.feature index d444e26ee0b9..1b1520abcdf4 100644 --- a/tests/acceptance/features/webUIRestrictSharing/restrictReSharing.feature +++ b/tests/acceptance/features/webUIRestrictSharing/restrictReSharing.feature @@ -25,7 +25,7 @@ Feature: restrict resharing Given the setting "Allow resharing" in the section "Sharing" has been enabled And the user has browsed to the files page When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | share | no | And the user re-logs in as "user1" using the webUI Then it should not be possible to share folder "simple-folder (2)" using the webUI diff --git a/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature b/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature index 87d7b3ad044e..02f1168e4665 100644 --- a/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature +++ b/tests/acceptance/features/webUIRestrictSharing/restrictSharing.feature @@ -60,3 +60,39 @@ Feature: restrict Sharing When the user shares folder "simple-folder" with user "User One" using the webUI And the user re-logs in as "user1" using the webUI Then folder "simple-folder (2)" should be listed on the webUI + + Scenario: Editing share permission of existing share when sharing with groups is forbidden + Given the user has shared folder "simple-folder" with group "grp1" + And the setting "Allow sharing with groups" in the section "Sharing" has been disabled + When the user opens the share dialog for folder "simple-folder" + Then group "grp1" should be listed in the shared with list + When the user sets the sharing permissions of group "grp1" for "simple-folder" using the webUI to + | share | no | + Then dialog should be displayed on the webUI + | title | content | + | Error while sharing |Group sharing is not allowed | + When the user reloads the current page of the webUI + Then the following permissions are seen for "simple-folder" in the sharing dialog for group "grp1" + | share | yes | + + Scenario: Editing create permission of existing share when sharing with groups is forbidden + Given the user has shared folder "simple-folder" with group "grp1" + And the setting "Allow sharing with groups" in the section "Sharing" has been disabled + When the user opens the share dialog for folder "simple-folder" + Then group "grp1" should be listed in the shared with list + When the user sets the sharing permissions of group "grp1" for "simple-folder" using the webUI to + | create | no | + Then dialog should be displayed on the webUI + | title | content | + | Error while sharing |Group sharing is not allowed | + When the user reloads the current page of the webUI + Then the following permissions are seen for "simple-folder" in the sharing dialog for group "grp1" + | create | yes | + + Scenario: Deleting group share when sharing with groups is forbidden + Given the user has shared folder "simple-folder" with group "grp1" + And the setting "Allow sharing with groups" in the section "Sharing" has been disabled + When the user opens the share dialog for folder "simple-folder" + Then group "grp1" should be listed in the shared with list + When the user deletes share with user "grp1 (group)" for the current file + Then group "grp1" should not be listed in the shared with list diff --git a/tests/acceptance/features/webUISharingExternal/federationSharing.feature b/tests/acceptance/features/webUISharingExternal/federationSharing.feature index 325e644ef471..93b4b64cc8db 100644 --- a/tests/acceptance/features/webUISharingExternal/federationSharing.feature +++ b/tests/acceptance/features/webUISharingExternal/federationSharing.feature @@ -127,7 +127,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages @skipOnMICROSOFTEDGE Scenario: share a folder with an remote user and prohibit deleting - local server shares - remote server receives When the user shares folder "simple-folder" with remote user "user1@%remote_server_without_scheme%" using the webUI - And the user sets the sharing permissions of "user1@%remote_server_without_scheme% (federated)" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "user1@%remote_server_without_scheme% (federated)" for "simple-folder" using the webUI to | delete | no | And user "user1" re-logs in to "%remote_server%" using the webUI And the user accepts the offered remote shares using the webUI @@ -278,7 +278,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages And user "user1" re-logs in to "%remote_server%" using the webUI And the user accepts the offered remote shares using the webUI And user "user1" from server "REMOTE" shares "/simple-folder (2)" with user "user2" from server "LOCAL" using the sharing API - And the user sets the sharing permissions of "user2@%local_server%/ (federated)" for "simple-folder (2)" using the webUI to + And the user sets the sharing permissions of user "user2@%local_server%/ (federated)" for "simple-folder (2)" using the webUI to | edit | no | And user "user2" re-logs in to "%local_server%" using the webUI And the user accepts the offered remote shares using the webUI @@ -297,7 +297,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages And user "user1" from server "REMOTE" shares "/simple-folder (2)" with user "user2" from server "LOCAL" using the sharing API And user "user1" re-logs in to "%local_server%" using the webUI And the user opens the share dialog for folder "simple-folder" - And the user sets the sharing permissions of "user2@%local_server% (federated)" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "user2@%local_server% (federated)" for "simple-folder" using the webUI to | edit | no | And user "user2" re-logs in to "%local_server%" using the webUI And the user accepts the offered remote shares using the webUI diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature index 200f1e4f9cdb..603b290ba479 100644 --- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature @@ -99,7 +99,7 @@ Feature: Sharing files and folders with internal users | user2 | And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | delete | no | And the user re-logs in as "user1" using the webUI And the user opens folder "simple-folder (2)" using the webUI @@ -431,7 +431,7 @@ Feature: Sharing files and folders with internal users And user "user2" has uploaded file "filesForUpload/lorem.txt" to "simple-folder/lorem.txt" And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | edit | no | And the user re-logs in as "user1" using the webUI And the user opens folder "simple-folder" using the webUI @@ -455,7 +455,7 @@ Feature: Sharing files and folders with internal users And user "user2" has uploaded file "filesForUpload/lorem.txt" to "simple-folder/lorem.txt" And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | change | no | | delete | no | And the user re-logs in as "user1" using the webUI @@ -475,7 +475,7 @@ Feature: Sharing files and folders with internal users And user "user2" has uploaded file "filesForUpload/lorem.txt" to "simple-folder/lorem.txt" And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | create | no | | delete | no | And the user re-logs in as "user1" using the webUI @@ -495,7 +495,7 @@ Feature: Sharing files and folders with internal users And user "user2" has uploaded file "filesForUpload/lorem.txt" to "simple-folder/lorem.txt" And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | change | no | | create | no | And the user re-logs in as "user1" using the webUI @@ -515,7 +515,7 @@ Feature: Sharing files and folders with internal users And user "user2" has uploaded file "filesForUpload/lorem.txt" to "simple-folder/lorem.txt" And user "user2" has logged in using the webUI When the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | share | no | And the user re-logs in as "user1" using the webUI And the user opens folder "simple-folder" using the webUI @@ -628,7 +628,7 @@ Feature: Sharing files and folders with internal users When the administrator disables permission delete for default user and group share using the webUI And the user re-logs in as "user2" using the webUI And the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | delete | yes | And the user re-logs in as "user1" using the webUI And the user opens folder "simple-folder" using the webUI @@ -650,7 +650,7 @@ Feature: Sharing files and folders with internal users And the administrator disables permission share for default user and group share using the webUI And the user re-logs in as "user2" using the webUI And the user shares folder "simple-folder" with user "User One" using the webUI - And the user sets the sharing permissions of "User One" for "simple-folder" using the webUI to + And the user sets the sharing permissions of user "User One" for "simple-folder" using the webUI to | share | yes | And the user re-logs in as "user1" using the webUI And the user opens folder "simple-folder" using the webUI