Skip to content

Commit

Permalink
Merge pull request #31715 from owncloud/API-test-sharing-restrictShar…
Browse files Browse the repository at this point in the history
…ingOutsideTheGroup

API test for restrictSharingOutsideTheGroup
  • Loading branch information
phil-davis authored Jun 12, 2018
2 parents da0d5c6 + 7715908 commit 7909d43
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
63 changes: 49 additions & 14 deletions tests/acceptance/features/apiSharing-v1/disableSharing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ So that ownCloud users cannot share file or folder
And using old DAV path

Scenario: user tries to share a file with another user when the sharing api has been disabled
Given as user "admin"
And user "user0" has been created
Given user "user0" has been created
And user "user1" has been created
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Expand All @@ -19,8 +18,7 @@ So that ownCloud users cannot share file or folder
And the HTTP status code should be "200"

Scenario: user tries to share a folder with another user when the sharing api has been disabled
Given as user "admin"
And user "user0" has been created
Given user "user0" has been created
And user "user1" has been created
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Expand All @@ -29,41 +27,78 @@ So that ownCloud users cannot share file or folder
And the HTTP status code should be "200"

Scenario: user tries to share a file with group when the sharing api has been disabled
Given as user "admin"
And user "user0" has been created
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And user "user1" has been added to group "sharinggroup"
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Then user "user0" should not be able to share file "welcome.txt" with group "sharinggroup" using the API
And the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: user tries to share a folder with group when the sharing api has been disabled
Given as user "admin"
And user "user0" has been created
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And user "user1" has been added to group "sharinggroup"
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Then user "user0" should not be able to share folder "/FOLDER" with group "sharinggroup" using the API
And the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: user tries to create public share of a file when the sharing api has been disabled
Given user "user0" has been created
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Then user "user0" should not be able to create public share of file "welcome.txt" using the API
Then the OCS status code should be "404"
And the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: user tries to create public share of a folder when the sharing api has been disabled
Given user "user0" has been created
And as user "admin"
When parameter "shareapi_enabled" of app "core" has been set to "no"
Then user "user0" should not be able to create public share of folder "/FOLDER" using the API
Then the OCS status code should be "404"
And the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: user tries to share a file with user who is not in his group when sharing outside the group has been restricted
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And user "user0" has been added to group "sharinggroup"
When parameter "shareapi_only_share_with_group_members" of app "core" has been set to "yes"
Then user "user0" should not be able to share file "welcome.txt" with user "user1" using the API
And the OCS status code should be "403"
And the HTTP status code should be "200"

Scenario: user shares a file with user who is in his group when sharing outside the group has been restricted
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And user "user0" has been added to group "sharinggroup"
And user "user1" has been added to group "sharinggroup"
When parameter "shareapi_only_share_with_group_members" of app "core" has been set to "yes"
Then user "user0" should be able to share file "welcome.txt" with user "user1" using the API
And the OCS status code should be "100"
And the HTTP status code should be "200"

Scenario: user shares a file with the group he is not member of when sharing outside the group has been restricted
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And group "anothersharinggroup" has been created
And user "user0" has been added to group "sharinggroup"
And user "user1" has been added to group "anothersharinggroup"
When parameter "shareapi_only_share_with_group_members" of app "core" has been set to "yes"
Then user "user0" should be able to share file "welcome.txt" with group "anothersharinggroup" using the API
And the OCS status code should be "100"
And the HTTP status code should be "200"

Scenario: user shares a file with the group he is member of when sharing outside the group has been restricted
Given user "user0" has been created
And user "user1" has been created
And group "sharinggroup" has been created
And user "user0" has been added to group "sharinggroup"
When parameter "shareapi_only_share_with_group_members" of app "core" has been set to "yes"
Then user "user0" should be able to share file "welcome.txt" with group "sharinggroup" using the API
And the OCS status code should be "100"
And the HTTP status code should be "200"
41 changes: 37 additions & 4 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,16 +864,49 @@ public function userSharesFileWithGroupUsingTheAPI(
}

/**
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (?:user|group) "([^"]*)"(?: with permissions ([\d]*))? using the API$/
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions ([\d]*))? using the API$/
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroup
* @param string $sharee
* @param int $permissions
*
* @return void
*/
public function userTriesToShareFileUsingTheApi($sharer, $filepath, $userOrGroup, $sharee, $permissions = null) {
$shareType = ($userOrGroup === "user" ? 0 : 1);
$time = \time();
if ($this->lastShareTime !== null && $time - $this->lastShareTime < 1) {
// prevent creating two shares with the same "stime" which is
// based on seconds, this affects share merging order and could
// affect expected test result order
\sleep(1);
}
$this->lastShareTime = $time;
$this->createShare(
$sharer, $filepath, $shareType, $sharee, null, null, $permissions
);
$statusCode = $this->getOCSResponseStatusCode($this->response);
PHPUnit_Framework_Assert::assertTrue(
($statusCode == 404) || ($statusCode == 403),
"Sharing should have failed but passed with status code " . $statusCode
);
}

/**
* @Then /^user "([^"]*)" should be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions ([\d]*))? using the API$/
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroup
* @param string $sharee
* @param int $permissions
*
* @return void
*/
public function userTriesToShareFileWithUserUsingTheApi($sharer, $filepath, $sharee, $permissions = null) {
public function userShouldBeAbleToShareUsingTheApi($sharer, $filepath, $userOrGroup, $sharee, $permissions = null) {
$shareType = ($userOrGroup === "user" ? 0 : 1);
$time = \time();
if ($this->lastShareTime !== null && $time - $this->lastShareTime < 1) {
// prevent creating two shares with the same "stime" which is
Expand All @@ -883,10 +916,10 @@ public function userTriesToShareFileWithUserUsingTheApi($sharer, $filepath, $sha
}
$this->lastShareTime = $time;
$this->createShare(
$sharer, $filepath, 0, $sharee, null, null, $permissions
$sharer, $filepath, $shareType, $sharee, null, null, $permissions
);
PHPUnit_Framework_Assert::assertEquals(
404,
100,
$this->getOCSResponseStatusCode($this->response)
);
}
Expand Down

0 comments on commit 7909d43

Please sign in to comment.