Commit e260aee6 authored by Vincent Petry's avatar Vincent Petry Committed by GitHub

Merge pull request #27526 from owncloud/inttest-multipublicshares

Added test scenario for multiple link shares
parents 97b5989e 882f42de
......@@ -174,7 +174,8 @@ trait Sharing {
$shareWith = null,
$publicUpload = null,
$password = null,
$permissions = null){
$permissions = null,
$linkName = null) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
$client = new Client();
$options = [];
......@@ -203,6 +204,9 @@ trait Sharing {
if (!is_null($permissions)){
$fd['permissions'] = $permissions;
}
if (!is_null($linkName)){
$fd['name'] = $linkName;
}
$options['body'] = $fd;
......@@ -507,5 +511,82 @@ trait Sharing {
throw new \Exception('Expected the same link share to be returned');
}
}
/* Returns shares of a file or folders as an array of elements */
public function getShares($user, $path) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
$fullUrl = $fullUrl . '?path=' . $path;
$client = new Client();
$options = [];
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$user, $this->regularUser];
}
$this->response = $client->send($client->createRequest("GET", $fullUrl, $options));
return $this->response->xml()->data->element;
}
/**
* @When /^user "([^"]*)" checks public shares of (file|folder) "([^"]*)"$/
* @param string $user
* @param string $type
* @param string $path
* @param \Behat\Gherkin\Node\TableNode|null $body
*/
public function checkPublicShares($user, $type, $path, $TableNode){
$dataResponded = $this->getShares($user, $path);
if ($TableNode instanceof \Behat\Gherkin\Node\TableNode) {
$elementRows = $TableNode->getRows();
if ($elementRows[0][0] === '') {
//It shouldn't have public shares
PHPUnit_Framework_Assert::assertEquals(count($dataResponded), 0);
return 0;
}
foreach($elementRows as $expectedElementsArray) {
//0 path, 1 permissions, 2 name
$nameFound = false;
foreach ($dataResponded as $elementResponded) {
if ((string)$elementResponded->name[0] === $expectedElementsArray[2]) {
PHPUnit_Framework_Assert::assertEquals($expectedElementsArray[0], (string)$elementResponded->path[0]);
PHPUnit_Framework_Assert::assertEquals($expectedElementsArray[1], (string)$elementResponded->permissions[0]);
$nameFound = true;
break;
}
}
PHPUnit_Framework_Assert::assertTrue($nameFound, "Shared link name " . $expectedElementsArray[2] . " not found");
}
}
}
public function getPublicShareIDByName($user, $path, $name) {
$dataResponded = $this->getShares($user, $path);
foreach ($dataResponded as $elementResponded) {
if ((string)$elementResponded->name[0] === $name){
return (int)$elementResponded->id[0];
}
}
return null;
}
/**
* @When /^user "([^"]*)" deletes public share named "([^"]*)" in (file|folder) "([^"]*)"$/
* @param string $user
* @param string $name
* @param string $type
* @param string $path
*/
public function deletingPublicShareNamed($user, $name, $type, $path){
$share_id = $this->getPublicShareIDByName($user, $path, $name);
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
$this->sendingToWith("DELETE", $url, null);
}
}
Feature: multilinksharing
Background:
Given using api version "1"
Given using old dav path
Scenario: Creating three public shares of a folder
Given user "user0" exists
And As an "user0"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink2 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink3 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
When Updating last share with
| permissions | 1 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "user0" checks public shares of folder "/FOLDER"
| /FOLDER | 15 | sharedlink2 |
| /FOLDER | 15 | sharedlink1 |
| /FOLDER | 1 | sharedlink3 |
Scenario: Creating three public shares of a file
Given user "user0" exists
And As an "user0"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink2 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink3 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
When Updating last share with
| permissions | 1 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "user0" checks public shares of file "/textfile0.txt"
| /textfile0.txt | 1 | sharedlink2 |
| /textfile0.txt | 1 | sharedlink1 |
| /textfile0.txt | 1 | sharedlink3 |
Scenario: Check that updating password doesn't remove name of links
Given user "user0" exists
And As an "user0"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink2 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
When Updating last share with
| password | newpassword |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "user0" checks public shares of folder "/FOLDER"
| /FOLDER | 15 | sharedlink2 |
| /FOLDER | 15 | sharedlink1 |
Scenario: Deleting a file deletes also its public links
Given user "user0" exists
And As an "user0"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink2 |
And User "user0" deletes file "/textfile0.txt"
And the HTTP status code should be "204"
When User "user0" uploads file "data/textfile.txt" to "/textfile0.txt"
Then the HTTP status code should be "201"
And user "user0" checks public shares of file "/textfile0.txt"
| | | |
Scenario: Deleting one public share of a file doesn't affect the rest
Given user "user0" exists
And As an "user0"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink2 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink3 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
When user "user0" deletes public share named "sharedlink2" in file "/textfile0.txt"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "user0" checks public shares of file "/textfile0.txt"
| /textfile0.txt | 1 | sharedlink1 |
| /textfile0.txt | 1 | sharedlink3 |
Scenario: Overwriting a file doesn't remove its public shares
Given user "user0" exists
And As an "user0"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | textfile0.txt |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| permissions | 1 |
| name | sharedlink2 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
When User "user0" uploads file "data/textfile.txt" to "/textfile0.txt"
Then user "user0" checks public shares of file "/textfile0.txt"
| /textfile0.txt | 1 | sharedlink1 |
| /textfile0.txt | 1 | sharedlink2 |
Scenario: Renaming a folder doesn't remove its public shares
Given user "user0" exists
And As an "user0"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink1 |
And the OCS status code should be "100"
And the HTTP status code should be "200"
And creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
| expireDate | +3 days |
| publicUpload | true |
| permissions | 15 |
| name | sharedlink2 |
When User "user0" moves folder "/FOLDER" to "/FOLDER_RENAMED"
Then user "user0" checks public shares of file "/FOLDER_RENAMED"
| /FOLDER_RENAMED | 15 | sharedlink1 |
| /FOLDER_RENAMED | 15 | sharedlink2 |
......@@ -1160,4 +1160,3 @@ Feature: sharing
And as "user0" the folder "/shared/sub" does not exist
And as "user0" the folder "/sub" exists in trash
And as "user0" the file "/sub/shared_file.txt" exists in trash
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment