aboutsummaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'build/integration/features/bootstrap')
-rw-r--r--build/integration/features/bootstrap/CalDavContext.php172
-rw-r--r--build/integration/features/bootstrap/CardDavContext.php193
-rw-r--r--build/integration/features/bootstrap/Provisioning.php8
-rw-r--r--build/integration/features/bootstrap/Sharing.php16
-rw-r--r--build/integration/features/bootstrap/WebDav.php47
5 files changed, 425 insertions, 11 deletions
diff --git a/build/integration/features/bootstrap/CalDavContext.php b/build/integration/features/bootstrap/CalDavContext.php
new file mode 100644
index 00000000000..88711f3aa73
--- /dev/null
+++ b/build/integration/features/bootstrap/CalDavContext.php
@@ -0,0 +1,172 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+require __DIR__ . '/../../vendor/autoload.php';
+
+use GuzzleHttp\Client;
+use GuzzleHttp\Message\ResponseInterface;
+
+class CalDavContext implements \Behat\Behat\Context\Context {
+ /** @var string */
+ private $baseUrl;
+ /** @var Client */
+ private $client;
+ /** @var ResponseInterface */
+ private $response;
+ /** @var string */
+ private $responseXml = '';
+
+ /**
+ * @param string $baseUrl
+ */
+ public function __construct($baseUrl) {
+ $this->baseUrl = $baseUrl;
+
+ // in case of ci deployment we take the server url from the environment
+ $testServerUrl = getenv('TEST_SERVER_URL');
+ if ($testServerUrl !== false) {
+ $this->baseUrl = substr($testServerUrl, 0, -5);
+ }
+ }
+
+ /** @BeforeScenario */
+ public function tearUpScenario() {
+ $this->client = new Client();
+ $this->responseXml = '';
+ }
+
+ /** @AfterScenario */
+ public function afterScenario() {
+ $davUrl = $this->baseUrl. '/remote.php/dav/calendars/admin/MyCalendar';
+ try {
+ $this->client->delete(
+ $davUrl,
+ [
+ 'auth' => [
+ 'admin',
+ 'admin',
+ ],
+ ]
+ );
+ } catch (\GuzzleHttp\Exception\ClientException $e) {}
+ }
+
+ /**
+ * @When :user requests calendar :calendar
+ */
+ public function requestsCalendar($user, $calendar) {
+ $davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$calendar;
+
+ $password = ($user === 'admin') ? 'admin' : '123456';
+ try {
+ $this->response = $this->client->get(
+ $davUrl,
+ [
+ 'auth' => [
+ $user,
+ $password,
+ ]
+ ]
+ );
+ } catch (\GuzzleHttp\Exception\ClientException $e) {
+ $this->response = $e->getResponse();
+ }
+ }
+
+ /**
+ * @Then The CalDAV HTTP status code should be :code
+ */
+ public function theCaldavHttpStatusCodeShouldBe($code) {
+ if((int)$code !== $this->response->getStatusCode()) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ (int)$code,
+ $this->response->getStatusCode()
+ )
+ );
+ }
+
+ $body = $this->response->getBody()->getContents();
+ if($body && substr($body, 0, 1) === '<') {
+ $reader = new Sabre\Xml\Reader();
+ $reader->xml($body);
+ $this->responseXml = $reader->parse();
+ }
+ }
+
+ /**
+ * @Then The exception is :message
+ */
+ public function theExceptionIs($message) {
+ $result = $this->responseXml['value'][0]['value'];
+
+ if($message !== $result) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ $message,
+ $result
+ )
+ );
+ }
+ }
+
+ /**
+ * @Then The error message is :message
+ */
+ public function theErrorMessageIs($message) {
+ $result = $this->responseXml['value'][1]['value'];
+
+ if($message !== $result) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ $message,
+ $result
+ )
+ );
+ }
+ }
+
+ /**
+ * @Given :user creates a calendar named :name
+ */
+ public function createsACalendarNamed($user, $name) {
+ $davUrl = $this->baseUrl . '/remote.php/dav/calendars/'.$user.'/'.$name;
+ $password = ($user === 'admin') ? 'admin' : '123456';
+
+ $request = $this->client->createRequest(
+ 'MKCALENDAR',
+ $davUrl,
+ [
+ 'body' => '<c:mkcalendar xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:" xmlns:a="http://apple.com/ns/ical/" xmlns:o="http://owncloud.org/ns"><d:set><d:prop><d:displayname>test</d:displayname><o:calendar-enabled>1</o:calendar-enabled><a:calendar-color>#21213D</a:calendar-color><c:supported-calendar-component-set><c:comp name="VEVENT"/></c:supported-calendar-component-set></d:prop></d:set></c:mkcalendar>',
+ 'auth' => [
+ $user,
+ $password,
+ ],
+ ]
+ );
+
+ $this->response = $this->client->send($request);
+ }
+
+}
diff --git a/build/integration/features/bootstrap/CardDavContext.php b/build/integration/features/bootstrap/CardDavContext.php
new file mode 100644
index 00000000000..251d76d0833
--- /dev/null
+++ b/build/integration/features/bootstrap/CardDavContext.php
@@ -0,0 +1,193 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+require __DIR__ . '/../../vendor/autoload.php';
+
+use GuzzleHttp\Client;
+use GuzzleHttp\Message\ResponseInterface;
+
+class CardDavContext implements \Behat\Behat\Context\Context {
+ /** @var string */
+ private $baseUrl;
+ /** @var Client */
+ private $client;
+ /** @var ResponseInterface */
+ private $response;
+ /** @var string */
+ private $responseXml = '';
+
+ /**
+ * @param string $baseUrl
+ */
+ public function __construct($baseUrl) {
+ $this->baseUrl = $baseUrl;
+
+ // in case of ci deployment we take the server url from the environment
+ $testServerUrl = getenv('TEST_SERVER_URL');
+ if ($testServerUrl !== false) {
+ $this->baseUrl = substr($testServerUrl, 0, -5);
+ }
+ }
+
+ /** @BeforeScenario */
+ public function tearUpScenario() {
+ $this->client = new Client();
+ $this->responseXml = '';
+ }
+
+
+ /** @AfterScenario */
+ public function afterScenario() {
+ $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/admin/MyAddressbook';
+ try {
+ $this->client->delete(
+ $davUrl,
+ [
+ 'auth' => [
+ 'admin',
+ 'admin',
+ ],
+ ]
+ );
+ } catch (\GuzzleHttp\Exception\ClientException $e) {}
+ }
+
+
+ /**
+ * @When :user requests addressbook :addressBook with statuscode :statusCode
+ */
+ public function requestsAddressbookWithStatuscode($user, $addressBook, $statusCode) {
+ $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$addressBook;
+
+ $password = ($user === 'admin') ? 'admin' : '123456';
+ try {
+ $this->response = $this->client->get(
+ $davUrl,
+ [
+ 'auth' => [
+ $user,
+ $password,
+ ],
+ ]
+ );
+ } catch (\GuzzleHttp\Exception\ClientException $e) {
+ $this->response = $e->getResponse();
+ }
+
+ if((int)$statusCode !== $this->response->getStatusCode()) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ (int)$statusCode,
+ $this->response->getStatusCode()
+ )
+ );
+ }
+
+ $body = $this->response->getBody()->getContents();
+ if(substr($body, 0, 1) === '<') {
+ $reader = new Sabre\Xml\Reader();
+ $reader->xml($body);
+ $this->responseXml = $reader->parse();
+ }
+ }
+
+ /**
+ * @Given :user creates an addressbook named :addressBook with statuscode :statusCode
+ */
+ public function createsAnAddressbookNamedWithStatuscode($user, $addressBook, $statusCode) {
+ $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/'.$user.'/'.$addressBook;
+ $password = ($user === 'admin') ? 'admin' : '123456';
+
+ $request = $this->client->createRequest(
+ 'MKCOL',
+ $davUrl,
+ [
+ 'body' => '<d:mkcol xmlns:c="urn:ietf:params:xml:ns:caldav"
+ xmlns:card="urn:ietf:params:xml:ns:carddav"
+ xmlns:cs="http://calendarserver.org/ns/"
+ xmlns:d="DAV:">
+ <d:set>
+ <d:prop>
+ <d:resourcetype>
+ <d:collection />,<card:addressbook />
+ </d:resourcetype>,<d:displayname>'.$addressBook.'</d:displayname>
+ </d:prop>
+ </d:set>
+ </d:mkcol>',
+ 'auth' => [
+ $user,
+ $password,
+ ],
+ 'headers' => [
+ 'Content-Type' => 'application/xml;charset=UTF-8',
+ ],
+ ]
+ );
+
+ $this->response = $this->client->send($request);
+
+ if($this->response->getStatusCode() !== (int)$statusCode) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ (int)$statusCode,
+ $this->response->getStatusCode()
+ )
+ );
+ }
+ }
+
+ /**
+ * @When The CardDAV exception is :message
+ */
+ public function theCarddavExceptionIs($message) {
+ $result = $this->responseXml['value'][0]['value'];
+
+ if($message !== $result) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ $message,
+ $result
+ )
+ );
+ }
+ }
+
+ /**
+ * @When The CardDAV error message is :arg1
+ */
+ public function theCarddavErrorMessageIs($message) {
+ $result = $this->responseXml['value'][1]['value'];
+
+ if($message !== $result) {
+ throw new \Exception(
+ sprintf(
+ 'Expected %s got %s',
+ $message,
+ $result
+ )
+ );
+ }
+ }
+
+}
diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php
index 65a6611b06c..6d710b2016f 100644
--- a/build/integration/features/bootstrap/Provisioning.php
+++ b/build/integration/features/bootstrap/Provisioning.php
@@ -531,6 +531,14 @@ trait Provisioning {
}
/**
+ * @Given user :user has unlimited quota
+ */
+ public function userHasUnlimitedQuota($user)
+ {
+ $this->userHasAQuotaOf($user, 'none');
+ }
+
+ /**
* @BeforeScenario
* @AfterScenario
*/
diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php
index 2073c840095..da2e9ca1094 100644
--- a/build/integration/features/bootstrap/Sharing.php
+++ b/build/integration/features/bootstrap/Sharing.php
@@ -21,17 +21,17 @@ trait Sharing{
private $savedShareId = null;
/**
- * @When /^creating a share with$/
+ * @Given /^as "([^"]*)" creating a share with$/
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
- public function creatingShare($body) {
+ public function asCreatingAShareWith($user, $body) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares";
$client = new Client();
$options = [];
- if ($this->currentUser === 'admin') {
+ if ($user === 'admin') {
$options['auth'] = $this->adminUser;
} else {
- $options['auth'] = [$this->currentUser, $this->regularUser];
+ $options['auth'] = [$user, $this->regularUser];
}
if ($body instanceof \Behat\Gherkin\Node\TableNode) {
@@ -53,6 +53,14 @@ trait Sharing{
}
/**
+ * @When /^creating a share with$/
+ * @param \Behat\Gherkin\Node\TableNode|null $formData
+ */
+ public function creatingShare($body) {
+ return $this->asCreatingAShareWith($this->currentUser, $body);
+ }
+
+ /**
* @Then /^Public shared file "([^"]*)" can be downloaded$/
*/
public function checkPublicSharedFile($filename) {
diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php
index be87a09731b..fa6761d9f71 100644
--- a/build/integration/features/bootstrap/WebDav.php
+++ b/build/integration/features/bootstrap/WebDav.php
@@ -20,7 +20,7 @@ trait WebDav {
*/
public function usingDavPath($davPath) {
$this->davPath = $davPath;
- }
+ }
public function makeDavRequest($user, $method, $path, $headers, $body = null){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
@@ -34,7 +34,7 @@ trait WebDav {
$request = $client->createRequest($method, $fullUrl, $options);
if (!is_null($headers)){
foreach ($headers as $key => $value) {
- $request->addHeader($key, $value);
+ $request->addHeader($key, $value);
}
}
@@ -84,7 +84,7 @@ trait WebDav {
$client = new GClient();
$options = [];
$options['auth'] = [$token, ""];
-
+
$request = $client->createRequest("GET", $fullUrl, $options);
$request->addHeader('Range', $range);
@@ -149,8 +149,37 @@ trait WebDav {
}
}
+ /**
+ * @Then /^as "([^"]*)" gets properties of folder "([^"]*)" with$/
+ * @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
+ */
+ public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) {
+ $properties = null;
+ if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) {
+ foreach ($propertiesTable->getRows() as $row) {
+ $properties[] = $row[0];
+ }
+ }
+ $this->response = $this->listFolder($user, $path, 0, $properties);
+ }
+
+ /**
+ * @Then the single response should contain a property :key with value :value
+ */
+ public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) {
+ $keys = $this->response;
+ if (!isset($keys[$key])) {
+ throw new \Exception("Cannot find property \"$key\" with \"$expectedalue\"");
+ }
+
+ $value = $keys[$key];
+ if ($value !== $expectedValue) {
+ throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$expectedValue\"");
+ }
+ }
+
/*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/
- public function listFolder($user, $path, $folderDepth){
+ public function listFolder($user, $path, $folderDepth, $properties = null){
$fullUrl = substr($this->baseUrl, 0, -4);
$settings = array(
@@ -166,9 +195,13 @@ trait WebDav {
$client = new SClient($settings);
- $response = $client->propfind($this->davPath . "/", array(
- '{DAV:}getetag'
- ), $folderDepth);
+ if (!$properties) {
+ $properties = [
+ '{DAV:}getetag'
+ ];
+ }
+
+ $response = $client->propfind($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth);
return $response;
}