Merge pull request #23258 from owncloud/sharee-tests

Add integration tests for sharee endpoint
This commit is contained in:
Thomas Müller 2016-03-16 21:54:20 +01:00
commit 8b5a1bbe3e
7 changed files with 302 additions and 222 deletions

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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());
}
}
}

View File

@ -175,14 +175,15 @@ trait Provisioning {
* @param string $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);
$previous_user = $this->currentUser;
$this->currentUser = "admin";
if (!$this->userBelongsToGroup($user, $group)){
$this->addingUserToGroup($user, $group);
}
$this->checkThatUserBelongsToGroup($user, $group);
$this->currentUser = $previous_user;
}
/**

View File

@ -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');
}
}

View File

@ -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;
}
}

View File

@ -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 |