From 573f6de6a038f830b45d09c36061ac44a9018660 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 11 Jul 2016 17:33:24 +0200 Subject: [PATCH] Add integration tests for merging received shares --- .../features/bootstrap/Sharing.php | 24 ++-- .../integration/features/bootstrap/WebDav.php | 67 +++++++++-- build/integration/features/sharing-v1.feature | 113 ++++++++++++++++++ 3 files changed, 180 insertions(+), 24 deletions(-) diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php index 9d230e35ac..954c273bfc 100644 --- a/build/integration/features/bootstrap/Sharing.php +++ b/build/integration/features/bootstrap/Sharing.php @@ -309,10 +309,10 @@ trait Sharing { PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user")); } - public function isUserOrGroupInSharedData($userOrGroup){ + public function isUserOrGroupInSharedData($userOrGroup, $permissions = null){ $data = $this->response->xml()->data[0]; foreach($data as $element) { - if ($element->share_with == $userOrGroup){ + if ($element->share_with == $userOrGroup && ($permissions === null || $permissions == $element->permissions)){ return True; } } @@ -320,13 +320,13 @@ trait Sharing { } /** - * @Given /^file "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"$/ + * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?$/ * * @param string $filepath * @param string $user1 * @param string $user2 */ - public function assureFileIsShared($filepath, $user1, $user2){ + public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null){ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; $client = new Client(); $options = []; @@ -336,23 +336,23 @@ trait Sharing { $options['auth'] = [$user1, $this->regularUser]; } $this->response = $client->get($fullUrl, $options); - if ($this->isUserOrGroupInSharedData($user2)){ + if ($this->isUserOrGroupInSharedData($user2, $permissions)){ return; } else { - $this->createShare($user1, $filepath, 0, $user2, null, null, null); + $this->createShare($user1, $filepath, 0, $user2, null, null, $permissions); } $this->response = $client->get($fullUrl, $options); - PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2)); + PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2, $permissions)); } /** - * @Given /^file "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"$/ + * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?$/ * * @param string $filepath * @param string $user * @param string $group */ - public function assureFileIsSharedWithGroup($filepath, $user, $group){ + public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null){ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; $client = new Client(); $options = []; @@ -362,13 +362,13 @@ trait Sharing { $options['auth'] = [$user, $this->regularUser]; } $this->response = $client->get($fullUrl, $options); - if ($this->isUserOrGroupInSharedData($group)){ + if ($this->isUserOrGroupInSharedData($group, $permissions)){ return; } else { - $this->createShare($user, $filepath, 1, $group, null, null, null); + $this->createShare($user, $filepath, 1, $group, null, null, $permissions); } $this->response = $client->get($fullUrl, $options); - PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group)); + PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group, $permissions)); } /** diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index 71f938c7ec..262955e4e5 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -259,6 +259,32 @@ trait WebDav { $this->response = $this->listFolder($user, $path, 0, $properties); } + /** + * @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" does not exist$/ + * @param string $user + * @param string $path + * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + */ + public function asTheFileOrFolderDoesNotExist($user, $entry, $path) { + $client = $this->getSabreClient($user); + $response = $client->request('HEAD', $this->makeSabrePath($path)); + if ($response['statusCode'] !== 404) { + throw new \Exception($entry . ' "' . $path . '" expected to not exist (status code ' . $response['statusCode'] . ', expected 404)'); + } + + return $response; + } + + /** + * @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" exists$/ + * @param string $user + * @param string $path + * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable + */ + public function asTheFileOrFolderExists($user, $entry, $path) { + $this->response = $this->listFolder($user, $path, 0); + } + /** * @Then the single response should contain a property :key with value :value * @param string $key @@ -327,9 +353,25 @@ trait WebDav { } } - /*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/ public function listFolder($user, $path, $folderDepth, $properties = null){ + $client = $this->getSabreClient($user); + if (!$properties) { + $properties = [ + '{DAV:}getetag' + ]; + } + + $response = $client->propfind($this->makeSabrePath($path), $properties, $folderDepth); + + return $response; + } + + public function makeSabrePath($path) { + return $this->encodePath($this->davPath . '/' . ltrim($path, '/')); + } + + public function getSabreClient($user) { $fullUrl = substr($this->baseUrl, 0, -4); $settings = array( @@ -343,17 +385,7 @@ trait WebDav { $settings['password'] = $this->regularUser; } - $client = new SClient($settings); - - if (!$properties) { - $properties = [ - '{DAV:}getetag' - ]; - } - - $response = $client->propfind($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth); - - return $response; + return new SClient($settings); } /** @@ -493,6 +525,17 @@ trait WebDav { } } + /** + * URL encodes the given path but keeps the slashes + * + * @param string $path to encode + * @return string encoded path + */ + private function encodePath($path) { + // slashes need to stay + return str_replace('%2F', '/', rawurlencode($path)); + } + /** * @When user :user favorites element :path */ diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 94d12ce3e7..69b2d6792c 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -775,3 +775,116 @@ Feature: sharing And Deleting last share Then the OCS status code should be "404" And the HTTP status code should be "200" + + Scenario: Merging shares for recipient when shared from outside with group and member + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And user "user1" belongs to group "group1" + And user "user0" created a folder "merge-test-outside" + When folder "merge-test-outside" of user "user0" is shared with group "group1" + And folder "merge-test-outside" of user "user0" is shared with user "user1" + Then as "user1" the folder "merge-test-outside" exists + And as "user1" the folder "merge-test-outside (2)" does not exist + + Scenario: Merging shares for recipient when shared from outside with group and member with different permissions + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And user "user1" belongs to group "group1" + And user "user0" created a folder "merge-test-outside-perms" + When folder "merge-test-outside-perms" of user "user0" is shared with group "group1" with permissions 1 + And folder "merge-test-outside-perms" of user "user0" is shared with user "user1" with permissions 31 + Then as "user1" gets properties of folder "merge-test-outside-perms" with + |{http://owncloud.org/ns}permissions| + And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" + And as "user1" the folder "merge-test-outside-perms (2)" does not exist + + Scenario: Merging shares for recipient when shared from outside with two groups + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And group "group2" exists + And user "user1" belongs to group "group1" + And user "user1" belongs to group "group2" + And user "user0" created a folder "merge-test-outside-twogroups" + When folder "merge-test-outside-twogroups" of user "user0" is shared with group "group1" + And folder "merge-test-outside-twogroups" of user "user0" is shared with group "group2" + Then as "user1" the folder "merge-test-outside-twogroups" exists + And as "user1" the folder "merge-test-outside-twogroups (2)" does not exist + + Scenario: Merging shares for recipient when shared from outside with two groups with different permissions + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And group "group2" exists + And user "user1" belongs to group "group1" + And user "user1" belongs to group "group2" + And user "user0" created a folder "merge-test-outside-twogroups-perms" + When folder "merge-test-outside-twogroups-perms" of user "user0" is shared with group "group1" with permissions 1 + And folder "merge-test-outside-twogroups-perms" of user "user0" is shared with group "group2" with permissions 31 + Then as "user1" gets properties of folder "merge-test-outside-twogroups-perms" with + |{http://owncloud.org/ns}permissions| + And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" + And as "user1" the folder "merge-test-outside-twogroups-perms (2)" does not exist + + Scenario: Merging shares for recipient when shared from outside with two groups and member + Given As an "admin" + And user "user0" exists + And user "user1" exists + And group "group1" exists + And group "group2" exists + And user "user1" belongs to group "group1" + And user "user1" belongs to group "group2" + And user "user0" created a folder "merge-test-outside-twogroups-member-perms" + When folder "merge-test-outside-twogroups-member-perms" of user "user0" is shared with group "group1" with permissions 1 + And folder "merge-test-outside-twogroups-member-perms" of user "user0" is shared with group "group2" with permissions 31 + And folder "merge-test-outside-twogroups-member-perms" of user "user0" is shared with user "user1" with permissions 1 + Then as "user1" gets properties of folder "merge-test-outside-twogroups-member-perms" with + |{http://owncloud.org/ns}permissions| + And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK" + And as "user1" the folder "merge-test-outside-twogroups-member-perms (2)" does not exist + + Scenario: Merging shares for recipient when shared from inside with group + Given As an "admin" + And user "user0" exists + And group "group1" exists + And user "user0" belongs to group "group1" + And user "user0" created a folder "merge-test-inside-group" + When folder "/merge-test-inside-group" of user "user0" is shared with group "group1" + Then as "user0" the folder "merge-test-inside-group" exists + And as "user0" the folder "merge-test-inside-group (2)" does not exist + + Scenario: Merging shares for recipient when shared from inside with two groups + Given As an "admin" + And user "user0" exists + And group "group1" exists + And group "group2" exists + And user "user0" belongs to group "group1" + And user "user0" belongs to group "group2" + And user "user0" created a folder "merge-test-inside-twogroups" + When folder "merge-test-inside-twogroups" of user "user0" is shared with group "group1" + And folder "merge-test-inside-twogroups" of user "user0" is shared with group "group2" + Then as "user0" the folder "merge-test-inside-twogroups" exists + And as "user0" the folder "merge-test-inside-twogroups (2)" does not exist + And as "user0" the folder "merge-test-inside-twogroups (3)" does not exist + + Scenario: Merging shares for recipient when shared from inside with group with less permissions + Given As an "admin" + And user "user0" exists + And group "group1" exists + And group "group2" exists + And user "user0" belongs to group "group1" + And user "user0" belongs to group "group2" + And user "user0" created a folder "merge-test-inside-twogroups-perms" + When folder "merge-test-inside-twogroups-perms" of user "user0" is shared with group "group1" + And folder "merge-test-inside-twogroups-perms" of user "user0" is shared with group "group2" + Then as "user0" gets properties of folder "merge-test-inside-twogroups-perms" with + |{http://owncloud.org/ns}permissions| + And the single response should contain a property "{http://owncloud.org/ns}permissions" with value "RDNVCK" + And as "user0" the folder "merge-test-inside-twogroups-perms (2)" does not exist + And as "user0" the folder "merge-test-inside-twogroups-perms (3)" does not exist