aboutsummaryrefslogtreecommitdiffstats
path: root/build/integration/features/bootstrap/Sharing.php
diff options
context:
space:
mode:
Diffstat (limited to 'build/integration/features/bootstrap/Sharing.php')
-rw-r--r--build/integration/features/bootstrap/Sharing.php163
1 files changed, 80 insertions, 83 deletions
diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php
index deff350475b..0cc490ff110 100644
--- a/build/integration/features/bootstrap/Sharing.php
+++ b/build/integration/features/bootstrap/Sharing.php
@@ -1,35 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Sergio Bertolin <sbertolin@solidgear.es>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sergio Bertolin <sbertolin@solidgear.es>
- * @author Sergio Bertolín <sbertolin@solidgear.es>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Client;
@@ -81,13 +55,19 @@ trait Sharing {
$fd = $body->getRowsHash();
if (array_key_exists('expireDate', $fd)) {
$dateModification = $fd['expireDate'];
- $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
+ if ($dateModification === 'null') {
+ $fd['expireDate'] = null;
+ } elseif (!empty($dateModification)) {
+ $fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
+ } else {
+ $fd['expireDate'] = '';
+ }
}
$options['form_params'] = $fd;
}
try {
- $this->response = $client->request("POST", $fullUrl, $options);
+ $this->response = $client->request('POST', $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
}
@@ -123,7 +103,7 @@ trait Sharing {
public function acceptingLastShare() {
$share_id = $this->lastShareData->data[0]->id;
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
- $this->sendingToWith("POST", $url, null);
+ $this->sendingToWith('POST', $url, null);
$this->theHTTPStatusCodeShouldBe('200');
}
@@ -143,7 +123,7 @@ trait Sharing {
$share_id = $this->lastShareData->data[0]->id;
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/pending/$share_id";
- $this->sendingToWith("POST", $url, null);
+ $this->sendingToWith('POST', $url, null);
$this->currentUser = $previousUser;
@@ -159,7 +139,7 @@ trait Sharing {
} else {
$url = $this->lastShareData->data->url;
}
- $fullUrl = $url . "/download";
+ $fullUrl = $url . '/download';
$this->checkDownload($fullUrl, null, 'text/plain');
}
@@ -173,7 +153,7 @@ trait Sharing {
$token = $this->lastShareData->data->token;
}
- $fullUrl = substr($this->baseUrl, 0, -4) . "index.php/s/" . $token . "/download";
+ $fullUrl = substr($this->baseUrl, 0, -4) . 'index.php/s/' . $token . '/download';
$this->checkDownload($fullUrl, null, 'text/plain');
}
@@ -187,8 +167,8 @@ trait Sharing {
$token = $this->lastShareData->data->token;
}
- $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
- $this->checkDownload($fullUrl, [$token, $password], 'text/plain');
+ $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/dav/files/$token/";
+ $this->checkDownload($fullUrl, ['', $password], 'text/plain');
}
private function checkDownload($url, $auth = null, $mimeType = null) {
@@ -219,7 +199,7 @@ trait Sharing {
* @When /^Adding expiration date to last share$/
*/
public function addingExpirationDate() {
- $share_id = (string) $this->lastShareData->data[0]->id;
+ $share_id = (string)$this->lastShareData->data[0]->id;
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
$client = new Client();
$options = [];
@@ -228,9 +208,9 @@ trait Sharing {
} else {
$options['auth'] = [$this->currentUser, $this->regularUser];
}
- $date = date('Y-m-d', strtotime("+3 days"));
+ $date = date('Y-m-d', strtotime('+3 days'));
$options['form_params'] = ['expireDate' => $date];
- $this->response = $this->response = $client->request("PUT", $fullUrl, $options);
+ $this->response = $this->response = $client->request('PUT', $fullUrl, $options);
Assert::assertEquals(200, $this->response->getStatusCode());
}
@@ -239,7 +219,7 @@ trait Sharing {
* @param TableNode|null $body
*/
public function updatingLastShare($body) {
- $share_id = (string) $this->lastShareData->data[0]->id;
+ $share_id = (string)$this->lastShareData->data[0]->id;
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
$client = new Client();
$options = [
@@ -263,19 +243,20 @@ trait Sharing {
}
try {
- $this->response = $client->request("PUT", $fullUrl, $options);
+ $this->response = $client->request('PUT', $fullUrl, $options);
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
}
}
public function createShare($user,
- $path = null,
- $shareType = null,
- $shareWith = null,
- $publicUpload = null,
- $password = null,
- $permissions = null) {
+ $path = null,
+ $shareType = null,
+ $shareWith = null,
+ $publicUpload = null,
+ $password = null,
+ $permissions = null,
+ $viewOnly = false) {
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares";
$client = new Client();
$options = [
@@ -309,10 +290,14 @@ trait Sharing {
$body['permissions'] = $permissions;
}
+ if ($viewOnly === true) {
+ $body['attributes'] = json_encode([['scope' => 'permissions', 'key' => 'download', 'value' => false]]);
+ }
+
$options['form_params'] = $body;
try {
- $this->response = $client->request("POST", $fullUrl, $options);
+ $this->response = $client->request('POST', $fullUrl, $options);
$this->lastShareData = simplexml_load_string($this->response->getBody());
} catch (\GuzzleHttp\Exception\ClientException $ex) {
$this->response = $ex->getResponse();
@@ -323,16 +308,18 @@ trait Sharing {
public function isFieldInResponse($field, $contentExpected) {
$data = simplexml_load_string($this->response->getBody())->data[0];
if ((string)$field == 'expiration') {
- $contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
+ if (!empty($contentExpected)) {
+ $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
+ }
}
if (count($data->element) > 0) {
foreach ($data as $element) {
- if ($contentExpected == "A_TOKEN") {
+ if ($contentExpected == 'A_TOKEN') {
return (strlen((string)$element->$field) == 15);
- } elseif ($contentExpected == "A_NUMBER") {
+ } elseif ($contentExpected == 'A_NUMBER') {
return is_numeric((string)$element->$field);
- } elseif ($contentExpected == "AN_URL") {
- return $this->isExpectedUrl((string)$element->$field, "index.php/s/");
+ } elseif ($contentExpected == 'AN_URL') {
+ return $this->isExpectedUrl((string)$element->$field, 'index.php/s/');
} elseif ((string)$element->$field == $contentExpected) {
return true;
} else {
@@ -342,14 +329,16 @@ trait Sharing {
return false;
} else {
- if ($contentExpected == "A_TOKEN") {
+ if ($contentExpected == 'A_TOKEN') {
return (strlen((string)$data->$field) == 15);
- } elseif ($contentExpected == "A_NUMBER") {
+ } elseif ($contentExpected == 'A_NUMBER') {
return is_numeric((string)$data->$field);
- } elseif ($contentExpected == "AN_URL") {
- return $this->isExpectedUrl((string)$data->$field, "index.php/s/");
- } elseif ($data->$field == $contentExpected) {
+ } elseif ($contentExpected == 'AN_URL') {
+ return $this->isExpectedUrl((string)$data->$field, 'index.php/s/');
+ } elseif ($contentExpected == $data->$field) {
return true;
+ } else {
+ print($data->$field);
}
return false;
}
@@ -402,13 +391,17 @@ trait Sharing {
}
/**
- * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?$/
+ * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
*
* @param string $filepath
* @param string $user1
* @param string $user2
*/
- public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null) {
+ public function assureFileIsShared($entry, $filepath, $user1, $user2, $withPerms = null, $permissions = null, $viewOnly = null) {
+ // when view-only is set, permissions is empty string instead of null...
+ if ($permissions === '') {
+ $permissions = null;
+ }
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
$client = new Client();
$options = [];
@@ -424,20 +417,24 @@ trait Sharing {
if ($this->isUserOrGroupInSharedData($user2, $permissions)) {
return;
} else {
- $this->createShare($user1, $filepath, 0, $user2, null, null, $permissions);
+ $this->createShare($user1, $filepath, 0, $user2, null, null, $permissions, $viewOnly !== null);
}
$this->response = $client->get($fullUrl, $options);
Assert::assertEquals(true, $this->isUserOrGroupInSharedData($user2, $permissions));
}
/**
- * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?$/
+ * @Given /^(file|folder|entry) "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"( with permissions ([\d]*))?( view-only)?$/
*
* @param string $filepath
* @param string $user
* @param string $group
*/
- public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null) {
+ public function assureFileIsSharedWithGroup($entry, $filepath, $user, $group, $withPerms = null, $permissions = null, $viewOnly = null) {
+ // when view-only is set, permissions is empty string instead of null...
+ if ($permissions === '') {
+ $permissions = null;
+ }
$fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath";
$client = new Client();
$options = [];
@@ -453,7 +450,7 @@ trait Sharing {
if ($this->isUserOrGroupInSharedData($group, $permissions)) {
return;
} else {
- $this->createShare($user, $filepath, 1, $group, null, null, $permissions);
+ $this->createShare($user, $filepath, 1, $group, null, null, $permissions, $viewOnly !== null);
}
$this->response = $client->get($fullUrl, $options);
Assert::assertEquals(true, $this->isUserOrGroupInSharedData($group, $permissions));
@@ -465,7 +462,7 @@ trait Sharing {
public function deletingLastShare() {
$share_id = $this->lastShareData->data[0]->id;
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
- $this->sendingToWith("DELETE", $url, null);
+ $this->sendingToWith('DELETE', $url, null);
}
/**
@@ -474,7 +471,7 @@ trait Sharing {
public function gettingInfoOfLastShare() {
$share_id = $this->lastShareData->data[0]->id;
$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id";
- $this->sendingToWith("GET", $url, null);
+ $this->sendingToWith('GET', $url, null);
}
/**
@@ -506,13 +503,13 @@ trait Sharing {
$fd = $body->getRowsHash();
foreach ($fd as $field => $value) {
- if (substr($field, 0, 10) === "share_with") {
- $value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -5), $value);
- $value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -5), $value);
+ if (substr($field, 0, 10) === 'share_with') {
+ $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -5), $value);
+ $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -5), $value);
}
- if (substr($field, 0, 6) === "remote") {
- $value = str_replace("REMOTE", substr($this->remoteBaseUrl, 0, -4), $value);
- $value = str_replace("LOCAL", substr($this->localBaseUrl, 0, -4), $value);
+ if (substr($field, 0, 6) === 'remote') {
+ $value = str_replace('REMOTE', substr($this->remoteBaseUrl, 0, -4), $value);
+ $value = str_replace('LOCAL', substr($this->localBaseUrl, 0, -4), $value);
}
if (!$this->isFieldInResponse($field, $value)) {
Assert::fail("$field" . " doesn't have value " . "$value");
@@ -567,18 +564,18 @@ trait Sharing {
];
$expectedFields = array_merge($defaultExpectedFields, $body->getRowsHash());
- if (!array_key_exists('uid_file_owner', $expectedFields) &&
- array_key_exists('uid_owner', $expectedFields)) {
+ if (!array_key_exists('uid_file_owner', $expectedFields)
+ && array_key_exists('uid_owner', $expectedFields)) {
$expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
}
- if (!array_key_exists('displayname_file_owner', $expectedFields) &&
- array_key_exists('displayname_owner', $expectedFields)) {
+ if (!array_key_exists('displayname_file_owner', $expectedFields)
+ && array_key_exists('displayname_owner', $expectedFields)) {
$expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
}
- if (array_key_exists('share_type', $expectedFields) &&
- $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */ &&
- array_key_exists('share_with', $expectedFields)) {
+ if (array_key_exists('share_type', $expectedFields)
+ && $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */
+ && array_key_exists('share_with', $expectedFields)) {
if ($expectedFields['share_with'] === 'private_conversation') {
$expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
} else {
@@ -608,12 +605,12 @@ trait Sharing {
return;
}
- if (!array_key_exists($field, $returnedShare)) {
+ if (!property_exists($returnedShare, $field)) {
Assert::fail("$field was not found in response");
}
if ($field === 'expiration' && !empty($contentExpected)) {
- $contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
+ $contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
}
if ($contentExpected === 'A_NUMBER') {