Merge pull request #20587 from owncloud/sharing-api-integration-tests-roelandcases

Requested sharing API test cases.
This commit is contained in:
Thomas Müller 2015-11-23 13:34:40 +01:00
commit a1c4e2e635
3 changed files with 262 additions and 19 deletions

View File

@ -27,6 +27,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var int */
private $sharingApiVersion = 1;
/** @var string*/
private $davPath = "remote.php/webdav";
/** @var SimpleXMLElement */
private $lastShareData = null;
@ -211,6 +214,13 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->apiVersion = $version;
}
/**
* @Given /^using dav path "([^"]*)"$/
*/
public function usingDavPath($davPath) {
$this->davPath = $davPath;
}
/**
* @Given /^user "([^"]*)" exists$/
*/
@ -238,8 +248,23 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
* @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
*/
public function checkThatUserBelongsToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$this->response = $client->get($fullUrl, $options);
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
sort($respondedArray);
PHPUnit_Framework_Assert::assertContains($group, $respondedArray);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
}
public function userBelongsToGroup($user, $group) {
$fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
$client = new Client();
@ -251,8 +276,26 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->response = $client->get($fullUrl, $options);
$groups = array($group);
$respondedArray = $this->getArrayOfGroupsResponded($this->response);
PHPUnit_Framework_Assert::assertEquals($groups, $respondedArray, "", 0.0, 10, true);
PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
if (array_key_exists($group, $respondedArray)) {
return True;
} else{
return False;
}
}
/**
* @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
*/
public function assureUserBelongsToGroup($user, $group){
if (!$this->userBelongsToGroup($user, $group)){
$previous_user = $this->currentUser;
$this->currentUser = "admin";
$this->addingUserToGroup($user, $group);
$this->currentUser = $previous_user;
}
$this->checkThatUserBelongsToGroup($user, $group);
}
/**
@ -566,10 +609,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
* @When /^creating a public share with$/
* @When /^creating a share with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
public function createPublicShare($body) {
public function creatingShare($body) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares";
$client = new Client();
$options = [];
@ -767,7 +810,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
elseif($contentExpected == "AN_URL"){
return $this->isExpectedUrl((string)$element->$field, "index.php/s/");
}
elseif ($element->$field == $contentExpected){
elseif ((string)$element->$field == $contentExpected){
return True;
}
}
@ -818,10 +861,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
PHPUnit_Framework_Assert::assertEquals(False, $this->isFieldInResponse('share_with', "$user"));
}
public function isUserInSharedData($user){
public function isUserOrGroupInSharedData($userOrGroup){
$data = $this->response->xml()->data[0];
foreach($data as $element) {
if ($element->share_with == $user){
if ($element->share_with == $userOrGroup){
return True;
}
}
@ -841,13 +884,71 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$options['auth'] = [$user1, $this->regularUser];
}
$this->response = $client->get($fullUrl, $options);
if ($this->isUserInSharedData($user2)){
if ($this->isUserOrGroupInSharedData($user2)){
return;
} else {
$this->createShare($user1, $filepath, 0, $user2, null, null, null);
}
$this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserInSharedData($user2));
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($user2));
}
/**
* @Given /^file "([^"]*)" from user "([^"]*)" is shared with group "([^"]*)"$/
*/
public function assureFileIsSharedWithGroup($filepath, $user, $group){
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
$client = new Client();
$options = [];
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$user, $this->regularUser];
}
$this->response = $client->get($fullUrl, $options);
if ($this->isUserOrGroupInSharedData($group)){
return;
} else {
$this->createShare($user, $filepath, 1, $group, null, null, null);
}
$this->response = $client->get($fullUrl, $options);
PHPUnit_Framework_Assert::assertEquals(True, $this->isUserOrGroupInSharedData($group));
}
public function makeDavRequest($user, $method, $path, $headers){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
$client = new Client();
$options = [];
if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
$options['auth'] = [$user, $this->regularUser];
}
$request = $client->createRequest($method, $fullUrl, $options);
foreach ($headers as $key => $value) {
$request->addHeader($key, $value);
}
//$this->response = $client->send($request);
return $client->send($request);
}
/**
* @Given /^User "([^"]*)" moved file "([^"]*)" to "([^"]*)"$/
*/
public function userMovedFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$headers['Destination'] = $fullUrl . $fileDestination;
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
PHPUnit_Framework_Assert::assertEquals(201, $this->response->getStatusCode());
}
/**
* @When /^User "([^"]*)" moves file "([^"]*)" to "([^"]*)"$/
*/
public function userMovesFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$headers['Destination'] = $fullUrl . $fileDestination;
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
}
/**
@ -868,6 +969,26 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$this->sendingToWith("GET", $url, null);
}
/**
* @Then /^last share_id is included in the answer$/
*/
public function checkingLastShareIDIsIncluded(){
$share_id = $this->lastShareData->data[0]->id;
if (!$this->isFieldInResponse('id', $share_id)){
PHPUnit_Framework_Assert::fail("Share id $share_id not found in response");
}
}
/**
* @Then /^last share_id is not included in the answer$/
*/
public function checkingLastShareIDIsNotIncluded(){
$share_id = $this->lastShareData->data[0]->id;
if ($this->isFieldInResponse('id', $share_id)){
PHPUnit_Framework_Assert::fail("Share id $share_id has been found in response");
}
}
/**
* @Then /^Share fields of last share match with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
@ -877,7 +998,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$fd = $body->getRowsHash();
foreach($fd as $field => $value) {
PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse($field, $value));
if (!$this->isFieldInResponse($field, $value)){
PHPUnit_Framework_Assert::fail("$field" . " doesn't have value " . "$value");
}
}
}
}

View File

@ -1,6 +1,7 @@
Feature: sharing
Background:
Given using api version "1"
Given using dav path "remote.php/webdav"
Scenario: Creating a new share with user
Given user "user0" exists
@ -28,7 +29,7 @@ Feature: sharing
Scenario: Creating a new public share
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | welcome.txt |
| shareType | 3 |
Then the OCS status code should be "100"
@ -38,7 +39,7 @@ Feature: sharing
Scenario: Creating a new public share with password
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | welcome.txt |
| shareType | 3 |
| password | publicpw |
@ -49,7 +50,7 @@ Feature: sharing
Scenario: Creating a new public share of a folder
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | FOLDER |
| shareType | 3 |
| password | publicpw |
@ -68,7 +69,7 @@ Feature: sharing
Scenario: Creating a new public share with password and adding an expiration date
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | welcome.txt |
| shareType | 3 |
| password | publicpw |
@ -81,7 +82,7 @@ Feature: sharing
Scenario: Creating a new public share, updating its expiration date and getting its info
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | FOLDER |
| shareType | 3 |
And Updating last share with
@ -111,7 +112,7 @@ Feature: sharing
Scenario: Creating a new public share, updating its password and getting its info
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | FOLDER |
| shareType | 3 |
And Updating last share with
@ -140,7 +141,7 @@ Feature: sharing
Scenario: Creating a new public share, updating its permissions and getting its info
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | FOLDER |
| shareType | 3 |
And Updating last share with
@ -169,7 +170,7 @@ Feature: sharing
Scenario: Creating a new public share, updating publicUpload option and getting its info
Given user "user0" exists
And As an "user0"
When creating a public share with
When creating a share with
| path | FOLDER |
| shareType | 3 |
And Updating last share with
@ -272,6 +273,102 @@ Feature: sharing
| share_with_displayname | user1 |
| displayname_owner | user0 |
Scenario: keep group permissions in sync
Given As an "admin"
Given user "user0" exists
And user "user1" exists
And group "group1" exists
And user "user1" belongs to group "group1"
And file "textfile0.txt" from user "user0" is shared with group "group1"
And User "user1" moved file "/textfile0.txt" to "/FOLDER/textfile0.txt"
And As an "user0"
When Updating last share with
| permissions | 1 |
And Getting info of last share
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And Share fields of last share match with
| id | A_NUMBER |
| item_type | file |
| item_source | A_NUMBER |
| share_type | 1 |
| file_source | A_NUMBER |
| file_target | /textfile0.txt |
| permissions | 1 |
| stime | A_NUMBER |
| storage | A_NUMBER |
| mail_send | 0 |
| uid_owner | user0 |
| storage_id | home::user0 |
| file_parent | A_NUMBER |
| displayname_owner | user0 |
Scenario: Sharee can see the share
Given user "user0" exists
And user "user1" exists
And file "textfile0.txt" from user "user0" is shared with user "user1"
And As an "user1"
When sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And last share_id is included in the answer
Scenario: User is not allowed to reshare file
As an "admin"
Given user "user0" exists
And user "user1" exists
And user "user2" exists
And As an "user0"
And creating a share with
| path | /textfile0.txt |
| shareType | 0 |
| shareWith | user1 |
| permissions | 8 |
And As an "user1"
When creating a share with
| path | /textfile0. (2).txt |
| shareType | 0 |
| shareWith | user2 |
| permissions | 31 |
Then the OCS status code should be "404"
And the HTTP status code should be "200"
Scenario: User is not allowed to reshare file with more permissions
As an "admin"
Given user "user0" exists
And user "user1" exists
And user "user2" exists
And As an "user0"
And creating a share with
| path | /textfile0.txt |
| shareType | 0 |
| shareWith | user1 |
| permissions | 16 |
And As an "user1"
When creating a share with
| path | /textfile0. (2).txt |
| shareType | 0 |
| shareWith | user2 |
| permissions | 31 |
Then the OCS status code should be "404"
And the HTTP status code should be "200"
Scenario: Delete all group shares
Given As an "admin"
And user "user0" exists
And user "user1" exists
And group "group1" exists
And user "user1" belongs to group "group1"
And file "textfile0.txt" from user "user0" is shared with group "group1"
And User "user1" moved file "/textfile0.txt" to "/FOLDER/textfile0.txt"
And As an "user0"
And Deleting last share
And As an "user1"
When sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And last share_id is not included in the answer
Scenario: delete a share
Given user "user0" exists
And user "user1" exists

View File

@ -0,0 +1,23 @@
Feature: sharing
Background:
Given using api version "1"
Scenario: moving a file old way
Given using dav path "remote.php/webdav"
And As an "admin"
And user "user0" exists
When User "user0" moves file "/textfile0.txt" to "/FOLDER/textfile0.txt"
Then the HTTP status code should be "201"