diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-16 21:54:20 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-16 21:54:20 +0100 |
commit | 8b5a1bbe3ead598a81a0fcba4ed03913aadbb923 (patch) | |
tree | 182e84285bddac8d73f44de0aa8c1c56310b10b3 /build/integration | |
parent | b4ea527fb2504a259e59c97b1f5cf77b47dafbe9 (diff) | |
parent | cb56dfec6be42b46bb57c65eb2af8e005d60d8d6 (diff) | |
download | nextcloud-server-8b5a1bbe3ead598a81a0fcba4ed03913aadbb923.tar.gz nextcloud-server-8b5a1bbe3ead598a81a0fcba4ed03913aadbb923.zip |
Merge pull request #23258 from owncloud/sharee-tests
Add integration tests for sharee endpoint
Diffstat (limited to 'build/integration')
-rw-r--r-- | build/integration/config/behat.yml | 10 | ||||
-rw-r--r-- | build/integration/features/bootstrap/AppConfiguration.php | 103 | ||||
-rw-r--r-- | build/integration/features/bootstrap/CapabilitiesContext.php | 79 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Provisioning.php | 9 | ||||
-rw-r--r-- | build/integration/features/bootstrap/ShareesContext.php | 72 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Sharing.php | 53 | ||||
-rw-r--r-- | build/integration/sharees_features/sharees.feature (renamed from build/integration/features/sharees.feature) | 192 |
7 files changed, 299 insertions, 219 deletions
diff --git a/build/integration/config/behat.yml b/build/integration/config/behat.yml index 4b5b5b16ef8..0c0ecef08e9 100644 --- a/build/integration/config/behat.yml +++ b/build/integration/config/behat.yml @@ -42,6 +42,16 @@ default: - admin - admin regular_user_password: 123456 + sharees: + paths: + - %paths.base%/../sharees_features + contexts: + - ShareesContext: + baseUrl: http://localhost:8080/ocs/ + admin: + - admin + - admin + regular_user_password: 123456 diff --git a/build/integration/features/bootstrap/AppConfiguration.php b/build/integration/features/bootstrap/AppConfiguration.php new file mode 100644 index 00000000000..af904a30896 --- /dev/null +++ b/build/integration/features/bootstrap/AppConfiguration.php @@ -0,0 +1,103 @@ +<?php + +use Behat\Behat\Hook\Scope\AfterScenarioScope; +use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use GuzzleHttp\Message\ResponseInterface; + +require __DIR__ . '/../../vendor/autoload.php'; + +trait AppConfiguration { + /** @var string */ + private $currentUser = ''; + + /** @var ResponseInterface */ + private $response = null; + + abstract public function sendingTo($verb, $url); + abstract public function sendingToWith($verb, $url, $body); + abstract public function theOCSStatusCodeShouldBe($statusCode); + abstract public function theHTTPStatusCodeShouldBe($statusCode); + + /** + * @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/ + * @param string $parameter + * @param string $app + * @param string $value + */ + public function serverParameterIsSetTo($parameter, $app, $value) { + $user = $this->currentUser; + $this->currentUser = 'admin'; + + $this->modifyServerConfig($app, $parameter, $value); + + $this->currentUser = $user; + } + + /** + * @param string $app + * @param string $parameter + * @param string $value + */ + protected function modifyServerConfig($app, $parameter, $value) { + $body = new \Behat\Gherkin\Node\TableNode([['value', $value]]); + $this->sendingToWith('post', "/apps/testing/api/v1/app/{$app}/{$parameter}", $body); + $this->theHTTPStatusCodeShouldBe('200'); + $this->theOCSStatusCodeShouldBe('100'); + } + + protected function setStatusTestingApp($enabled) { + $this->sendingTo(($enabled ? 'post' : 'delete'), '/cloud/apps/testing'); + $this->theHTTPStatusCodeShouldBe('200'); + $this->theOCSStatusCodeShouldBe('100'); + + $this->sendingTo('get', '/cloud/apps?filter=enabled'); + $this->theHTTPStatusCodeShouldBe('200'); + if ($enabled) { + PHPUnit_Framework_Assert::assertContains('testing', $this->response->getBody()->getContents()); + } else { + PHPUnit_Framework_Assert::assertNotContains('testing', $this->response->getBody()->getContents()); + } + } + + abstract protected function resetAppConfigs(); + + /** + * @BeforeScenario + * + * Enable the testing app before the first scenario of the feature and + * reset the configs before each scenario + * @param BeforeScenarioScope $event + */ + public function prepareParameters(BeforeScenarioScope $event){ + $user = $this->currentUser; + $this->currentUser = 'admin'; + + $scenarios = $event->getFeature()->getScenarios(); + if ($event->getScenario() === reset($scenarios)) { + $this->setStatusTestingApp(true); + } + + $this->resetAppConfigs(); + + $this->currentUser = $user; + } + + /** + * @AfterScenario + * + * Reset the values after the last scenario of the feature and disable the testing app + * @param AfterScenarioScope $event + */ + public function undoChangingParameters(AfterScenarioScope $event) { + $scenarios = $event->getFeature()->getScenarios(); + if ($event->getScenario() === end($scenarios)) { + $user = $this->currentUser; + $this->currentUser = 'admin'; + + $this->resetAppConfigs(); + + $this->setStatusTestingApp(false); + $this->currentUser = $user; + } + } +} diff --git a/build/integration/features/bootstrap/CapabilitiesContext.php b/build/integration/features/bootstrap/CapabilitiesContext.php index 0eb6353a89a..91a4265504c 100644 --- a/build/integration/features/bootstrap/CapabilitiesContext.php +++ b/build/integration/features/bootstrap/CapabilitiesContext.php @@ -15,18 +15,7 @@ require __DIR__ . '/../../vendor/autoload.php'; class CapabilitiesContext implements Context, SnippetAcceptingContext { use BasicStructure; - - /** - * @Given /^parameter "([^"]*)" of app "([^"]*)" is set to "([^"]*)"$/ - */ - public function serverParameterIsSetTo($parameter, $app, $value){ - $user = $this->currentUser; - $this->currentUser = 'admin'; - - $this->modifyServerConfig($app, $parameter, $value); - - $this->currentUser = $user; - } + use AppConfiguration; /** * @Then /^fields of capabilities match with$/ @@ -63,70 +52,4 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext { $this->modifyServerConfig('core', 'shareapi_default_expire_date', 'no'); $this->modifyServerConfig('core', 'shareapi_enforce_expire_date', 'no'); } - - /** - * @BeforeScenario - * - * Enable the testing app before the first scenario of the feature and - * reset the configs before each scenario - * @param BeforeScenarioScope $event - */ - public function prepareParameters(BeforeScenarioScope $event){ - $user = $this->currentUser; - $this->currentUser = 'admin'; - - $scenarios = $event->getFeature()->getScenarios(); - if ($event->getScenario() === reset($scenarios)) { - $this->setStatusTestingApp(true); - } - - $this->resetAppConfigs(); - - $this->currentUser = $user; - } - - /** - * @AfterScenario - * - * Reset the values after the last scenario of the feature and disable the testing app - * @param AfterScenarioScope $event - */ - public function undoChangingParameters(AfterScenarioScope $event) { - $scenarios = $event->getFeature()->getScenarios(); - if ($event->getScenario() === end($scenarios)) { - $user = $this->currentUser; - $this->currentUser = 'admin'; - - $this->resetAppConfigs(); - - $this->setStatusTestingApp(false); - $this->currentUser = $user; - } - } - - /** - * @param string $app - * @param string $parameter - * @param string $value - */ - protected function modifyServerConfig($app, $parameter, $value) { - $body = new \Behat\Gherkin\Node\TableNode([['value', $value]]); - $this->sendingToWith('post', "/apps/testing/api/v1/app/{$app}/{$parameter}", $body); - $this->theHTTPStatusCodeShouldBe('200'); - $this->theOCSStatusCodeShouldBe('100'); - } - - protected function setStatusTestingApp($enabled) { - $this->sendingTo(($enabled ? 'post' : 'delete'), '/cloud/apps/testing'); - $this->theHTTPStatusCodeShouldBe('200'); - $this->theOCSStatusCodeShouldBe('100'); - - $this->sendingTo('get', '/cloud/apps?filter=enabled'); - $this->theHTTPStatusCodeShouldBe('200'); - if ($enabled) { - PHPUnit_Framework_Assert::assertContains('testing', $this->response->getBody()->getContents()); - } else { - PHPUnit_Framework_Assert::assertNotContains('testing', $this->response->getBody()->getContents()); - } - } } diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index bf84058c05e..feeb850ae7d 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -175,14 +175,15 @@ trait Provisioning { * @param string $group */ public function assureUserBelongsToGroup($user, $group){ + $previous_user = $this->currentUser; + $this->currentUser = "admin"; + if (!$this->userBelongsToGroup($user, $group)){ - $previous_user = $this->currentUser; - $this->currentUser = "admin"; $this->addingUserToGroup($user, $group); - $this->currentUser = $previous_user; } - $this->checkThatUserBelongsToGroup($user, $group); + $this->checkThatUserBelongsToGroup($user, $group); + $this->currentUser = $previous_user; } /** diff --git a/build/integration/features/bootstrap/ShareesContext.php b/build/integration/features/bootstrap/ShareesContext.php new file mode 100644 index 00000000000..de50eeb2beb --- /dev/null +++ b/build/integration/features/bootstrap/ShareesContext.php @@ -0,0 +1,72 @@ +<?php + +use Behat\Behat\Context\Context; +use Behat\Behat\Context\SnippetAcceptingContext; +use GuzzleHttp\Message\ResponseInterface; + +require __DIR__ . '/../../vendor/autoload.php'; + + +/** + * Features context. + */ +class ShareesContext implements Context, SnippetAcceptingContext { + use Provisioning; + use AppConfiguration; + + /** + * @When /^getting sharees for$/ + * @param \Behat\Gherkin\Node\TableNode $body + */ + public function whenGettingShareesFor($body) { + $url = '/apps/files_sharing/api/v1/sharees'; + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $parameters = []; + foreach ($body->getRowsHash() as $key => $value) { + $parameters[] = $key . '=' . $value; + } + if (!empty($parameters)) { + $url .= '?' . implode('&', $parameters); + } + } + + $this->sendingTo('GET', $url); + } + + /** + * @Then /^"([^"]*)" sharees returned (are|is empty)$/ + * @param string $shareeType + * @param string $isEmpty + * @param \Behat\Gherkin\Node\TableNode|null $shareesList + */ + public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) { + if ($isEmpty !== 'is empty') { + $sharees = $shareesList->getRows(); + $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType); + PHPUnit_Framework_Assert::assertEquals($sharees, $respondedArray); + } else { + $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType); + PHPUnit_Framework_Assert::assertEmpty($respondedArray); + } + } + + public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) { + $elements = $response->xml()->data; + $elements = json_decode(json_encode($elements), 1); + if (strpos($shareeType, 'exact ') === 0) { + $elements = $elements['exact']; + $shareeType = substr($shareeType, 6); + } + + $sharees = []; + foreach ($elements[$shareeType] as $element) { + $sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']]; + } + return $sharees; + } + + protected function resetAppConfigs() { + $this->modifyServerConfig('core', 'shareapi_only_share_with_group_members', 'no'); + $this->modifyServerConfig('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'); + } +} diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php index f516b97146d..d423a28f196 100644 --- a/build/integration/features/bootstrap/Sharing.php +++ b/build/integration/features/bootstrap/Sharing.php @@ -7,7 +7,7 @@ require __DIR__ . '/../../vendor/autoload.php'; -trait Sharing{ +trait Sharing { use Provisioning; /** @var int */ @@ -469,56 +469,5 @@ trait Sharing{ throw new \Exception('Expected the same link share to be returned'); } } - - /** - * @When /^getting sharees for$/ - * @param \Behat\Gherkin\Node\TableNode $body - */ - public function whenGettingShareesFor($body) { - $url = '/apps/files_sharing/api/v1/sharees'; - if ($body instanceof \Behat\Gherkin\Node\TableNode) { - $parameters = []; - foreach ($body->getRowsHash() as $key => $value) { - $parameters[] = $key . '=' . $value; - } - if (!empty($parameters)) { - $url .= '?' . implode('&', $parameters); - } - } - - $this->sendingTo('GET', $url); - } - - /** - * @Then /^"([^"]*)" sharees returned (are|is empty)$/ - * @param string $shareeType - * @param string $isEmpty - * @param \Behat\Gherkin\Node\TableNode|null $shareesList - */ - public function thenListOfSharees($shareeType, $isEmpty, $shareesList = null) { - if ($isEmpty !== 'is empty') { - $sharees = $shareesList->getRows(); - $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType); - PHPUnit_Framework_Assert::assertEquals($sharees, $respondedArray); - } else { - $respondedArray = $this->getArrayOfShareesResponded($this->response, $shareeType); - PHPUnit_Framework_Assert::assertEmpty($respondedArray); - } - } - - public function getArrayOfShareesResponded(ResponseInterface $response, $shareeType) { - $elements = $response->xml()->data; - $elements = json_decode(json_encode($elements), 1); - if (strpos($shareeType, 'exact ') === 0) { - $elements = $elements['exact']; - $shareeType = substr($shareeType, 6); - } - - $sharees = []; - foreach ($elements[$shareeType] as $element) { - $sharees[] = [$element['label'], $element['value']['shareType'], $element['value']['shareWith']]; - } - return $sharees; - } } diff --git a/build/integration/features/sharees.feature b/build/integration/sharees_features/sharees.feature index 35a80e72062..5765b937a67 100644 --- a/build/integration/features/sharees.feature +++ b/build/integration/sharees_features/sharees.feature @@ -1,12 +1,13 @@ Feature: sharees Background: Given using api version "1" - - Scenario: Search without exact match - Given user "test" exists + And user "test" exists And user "Sharee1" exists And group "ShareeGroup" exists - And As an "test" + And user "test" belongs to group "ShareeGroup" + + Scenario: Search without exact match + Given As an "test" When getting sharees for | search | Sharee | | itemType | file | @@ -22,10 +23,7 @@ Feature: sharees And "remotes" sharees returned is empty Scenario: Search without exact match not-exact casing - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | sharee | | itemType | file | @@ -40,65 +38,104 @@ Feature: sharees And "exact remotes" sharees returned is empty And "remotes" sharees returned is empty -# TODO need to move the appconfig setting from Capabilities to Basic/Provisioning -# Scenario: Search without exact match no iteration allowed -# Given user "test" exists -# And user "Sharee1" exists -# And group "ShareeGroup" exists -# And As an "test" -# When getting sharees for -# | search | Sharee | -# | itemType | file | -# Then the OCS status code should be "100" -# And the HTTP status code should be "200" -# And "exact users" sharees returned is empty -# And "users" sharees returned is empty -# And "exact groups" sharees returned is empty -# And "groups" sharees returned is empty -# And "exact remotes" sharees returned is empty -# And "remotes" sharees returned is empty -# -# Scenario: Search with exact match no iteration allowed -# Given user "test" exists -# And user "Sharee1" exists -# And group "ShareeGroup" exists -# And As an "test" -# When getting sharees for -# | search | Sharee1 | -# | itemType | file | -# Then the OCS status code should be "100" -# And the HTTP status code should be "200" -# And "exact users" sharees returned are -# | Sharee1 | 0 | Sharee1 | -# And "users" sharees returned is empty -# And "exact groups" sharees returned is empty -# And "groups" sharees returned is empty -# And "exact remotes" sharees returned is empty -# And "remotes" sharees returned is empty -# -# Scenario: Search with exact match group no iteration allowed -# Given user "test" exists -# And user "Sharee1" exists -# And group "ShareeGroup" exists -# And As an "test" -# When getting sharees for -# | search | ShareeGroup | -# | itemType | file | -# Then the OCS status code should be "100" -# And the HTTP status code should be "200" -# And "exact users" sharees returned is empty -# And "users" sharees returned is empty -# And "exact groups" sharees returned are -# | ShareeGroup | 1 | ShareeGroup | -# And "groups" sharees returned is empty -# And "exact remotes" sharees returned is empty -# And "remotes" sharees returned is empty + Scenario: Search only with group members - denied + Given As an "test" + And parameter "shareapi_only_share_with_group_members" of app "core" is set to "yes" + When getting sharees for + | search | sharee | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned is empty + And "users" sharees returned is empty + And "exact groups" sharees returned is empty + And "groups" sharees returned are + | ShareeGroup | 1 | ShareeGroup | + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty + + Scenario: Search only with group members - allowed + Given As an "test" + And parameter "shareapi_only_share_with_group_members" of app "core" is set to "yes" + And user "Sharee1" belongs to group "ShareeGroup" + When getting sharees for + | search | sharee | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned is empty + And "users" sharees returned are + | Sharee1 | 0 | Sharee1 | + And "exact groups" sharees returned is empty + And "groups" sharees returned are + | ShareeGroup | 1 | ShareeGroup | + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty + + Scenario: Search only with group members - no group as non-member + Given As an "Sharee1" + And parameter "shareapi_only_share_with_group_members" of app "core" is set to "yes" + When getting sharees for + | search | sharee | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned is empty + And "users" sharees returned is empty + And "exact groups" sharees returned is empty + And "groups" sharees returned is empty + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty + + Scenario: Search without exact match no iteration allowed + Given As an "test" + And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no" + When getting sharees for + | search | Sharee | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned is empty + And "users" sharees returned is empty + And "exact groups" sharees returned is empty + And "groups" sharees returned is empty + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty + + Scenario: Search with exact match no iteration allowed + Given As an "test" + And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no" + When getting sharees for + | search | Sharee1 | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned are + | Sharee1 | 0 | Sharee1 | + And "users" sharees returned is empty + And "exact groups" sharees returned is empty + And "groups" sharees returned is empty + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty + + Scenario: Search with exact match group no iteration allowed + Given As an "test" + And parameter "shareapi_allow_share_dialog_user_enumeration" of app "core" is set to "no" + When getting sharees for + | search | ShareeGroup | + | itemType | file | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And "exact users" sharees returned is empty + And "users" sharees returned is empty + And "exact groups" sharees returned are + | ShareeGroup | 1 | ShareeGroup | + And "groups" sharees returned is empty + And "exact remotes" sharees returned is empty + And "remotes" sharees returned is empty Scenario: Search with exact match - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | Sharee1 | | itemType | file | @@ -113,10 +150,7 @@ Feature: sharees Then "remotes" sharees returned is empty Scenario: Search with exact match not-exact casing - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | sharee1 | | itemType | file | @@ -131,10 +165,7 @@ Feature: sharees Then "remotes" sharees returned is empty Scenario: Search with exact match not-exact casing group - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | shareegroup | | itemType | file | @@ -149,10 +180,7 @@ Feature: sharees Then "remotes" sharees returned is empty Scenario: Search with "self" - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "Sharee1" + Given As an "Sharee1" When getting sharees for | search | Sharee1 | | itemType | file | @@ -167,10 +195,7 @@ Feature: sharees Then "remotes" sharees returned is empty Scenario: Remote sharee for files - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | test@localhost | | itemType | file | @@ -185,10 +210,7 @@ Feature: sharees Then "remotes" sharees returned is empty Scenario: Remote sharee for calendars not allowed - Given user "test" exists - And user "Sharee1" exists - And group "ShareeGroup" exists - And As an "test" + Given As an "test" When getting sharees for | search | test@localhost | | itemType | calendar | |