Skip to content

Commit

Permalink
Add integration tests for merging received shares
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Jul 19, 2016
1 parent aa42b7b commit e5af146
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 25 deletions.
24 changes: 12 additions & 12 deletions build/integration/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,24 @@ public function checkSharedUserNotInResponse($user){
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;
}
}
return False;
}

/**
* @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 = [];
Expand All @@ -311,23 +311,23 @@ public function assureFileIsShared($filepath, $user1, $user2){
$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 = [];
Expand All @@ -337,13 +337,13 @@ public function assureFileIsSharedWithGroup($filepath, $user, $group){
$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));
}

/**
Expand Down
69 changes: 56 additions & 13 deletions build/integration/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,32 @@ public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) {
$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
Expand Down Expand Up @@ -293,9 +319,25 @@ public function theResponseShouldContainAnEmptyProperty($property) {
}
}


/*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(
Expand All @@ -309,17 +351,7 @@ public function listFolder($user, $path, $folderDepth, $properties = null){
$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);
}

/**
Expand Down Expand Up @@ -393,7 +425,7 @@ public function userDeletesFile($user, $file) {
*/
public function userCreatedAFolder($user, $destination){
try {
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []);
$this->response = $this->makeDavRequest($user, "MKCOL", '/' . ltrim($destination, '/'), []);
} catch (\GuzzleHttp\Exception\ServerException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
Expand Down Expand Up @@ -459,6 +491,17 @@ public function downloadingFileAs($fileName, $user) {
}
}

/**
* 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
*/
Expand Down
114 changes: 114 additions & 0 deletions build/integration/features/sharing-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,117 @@ Feature: sharing
| shareType | 0 |
Then the OCS status code should be "997"
And the HTTP status code should be "401"

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

0 comments on commit e5af146

Please sign in to comment.