2022-12-21 17:22:22 +05:45
<? php declare ( strict_types = 1 );
/**
* ownCloud
*
* @author Joas Schilling <coding@schilljs.com>
* @author Sergio Bertolin <sbertolin@owncloud.com>
* @author Phillip Davis <phil@jankaritech.com>
* @copyright Copyright (c) 2018, ownCloud GmbH
*
* This code 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 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/>
*
*/
use Behat\Gherkin\Node\PyStringNode ;
use Behat\Gherkin\Node\TableNode ;
use Psr\Http\Message\ResponseInterface ;
use PHPUnit\Framework\Assert ;
2023-06-08 16:59:45 +05:45
use PHPUnit\Framework\ExpectationFailedException ;
2022-12-21 17:22:22 +05:45
use TestHelpers\OcsApiHelper ;
use TestHelpers\SharingHelper ;
use TestHelpers\HttpRequestHelper ;
use TestHelpers\TranslationHelper ;
2024-09-17 17:11:20 +05:45
use TestHelpers\WebDavHelper ;
2024-05-22 17:10:47 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2022-12-21 17:22:22 +05:45
/**
* Sharing trait
*/
trait Sharing {
2023-05-02 17:25:56 +05:45
private int $sharingApiVersion = 1 ;
2022-12-21 17:22:22 +05:45
/**
2023-07-26 12:01:09 +05:45
* @var array
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
private array $createdUserGroupShares = [];
2022-12-21 17:22:22 +05:45
2023-05-02 17:25:56 +05:45
private ? float $localLastShareTime = null ;
2022-12-21 17:22:22 +05:45
/**
* Defines the fields that can be provided in a share request.
*/
2023-05-02 17:25:56 +05:45
private array $shareFields = [
2022-12-21 17:22:22 +05:45
'path' , 'name' , 'publicUpload' , 'password' , 'expireDate' ,
'expireDateAsString' , 'permissions' , 'shareWith' , 'shareType'
];
/**
* Defines the fields that are known and can be tested in a share response.
* Note that ownCloud10 also provides file_parent in responses.
* file_parent is not provided by OCIS/reva.
* There are no known clients that use file_parent.
* The acceptance tests do not test for file_parent.
*
* @var array fields that are possible in a share response
*/
2023-05-02 17:25:56 +05:45
private array $shareResponseFields = [
2022-12-21 17:22:22 +05:45
'id' , 'share_type' , 'uid_owner' , 'displayname_owner' , 'stime' , 'parent' ,
'expiration' , 'token' , 'uid_file_owner' , 'displayname_file_owner' , 'path' ,
'item_type' , 'mimetype' , 'storage_id' , 'storage' , 'item_source' ,
'file_source' , 'file_target' , 'name' , 'url' , 'mail_send' ,
'attributes' , 'permissions' , 'share_with' , 'share_with_displayname' , 'share_with_additional_info'
];
/**
2023-08-03 13:51:22 +05:45
* @var array
2022-12-21 17:22:22 +05:45
*/
2023-08-03 13:51:22 +05:45
private array $createdPublicShares = [];
2022-12-21 17:22:22 +05:45
2024-01-02 16:53:47 +05:45
/**
* @var array
*/
private array $shareNgCreatedLinkShares = [];
2024-01-11 11:31:28 +05:45
/**
* @var array
*/
private array $shareNgCreatedUserGroupShares = [];
2022-12-21 17:22:22 +05:45
/**
* @return string
*/
2023-08-03 13:51:22 +05:45
public function getLastCreatedPublicShareToken () : string {
return ( string ) $this -> getLastCreatedPublicShare () -> token ;
2022-12-21 17:22:22 +05:45
}
/**
* @return SimpleXMLElement|null
*/
2023-08-03 13:51:22 +05:45
public function getLastCreatedPublicShare () :? SimpleXMLElement {
return \end ( $this -> createdPublicShares );
2022-12-21 17:22:22 +05:45
}
/**
2023-08-03 13:51:22 +05:45
* @param SimpleXMLElement $shareData
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2023-08-03 13:51:22 +05:45
public function addToCreatedPublicShares ( SimpleXMLElement $shareData ) : void {
$this -> createdPublicShares [] = $shareData ;
2022-12-21 17:22:22 +05:45
}
2024-01-02 16:53:47 +05:45
/**
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgAddToCreatedLinkShares ( ResponseInterface $response ) : void {
$this -> shareNgCreatedLinkShares [] = $response ;
}
/**
* @return ResponseInterface|null
*/
public function shareNgGetLastCreatedLinkShare () :? ResponseInterface {
return \end ( $this -> shareNgCreatedLinkShares );
}
2024-01-11 11:31:28 +05:45
/**
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgAddToCreatedUserGroupShares ( ResponseInterface $response ) : void {
$this -> shareNgCreatedUserGroupShares [] = $response ;
}
/**
* @return ResponseInterface|null
*/
public function shareNgGetLastCreatedUserGroupShare () :? ResponseInterface {
return \end ( $this -> shareNgCreatedUserGroupShares );
}
2022-12-21 17:22:22 +05:45
/**
2023-07-26 12:01:09 +05:45
* @param string $sharer
* @param SimpleXMLElement $shareData
*
* @return void
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function addToCreatedUserGroupShares ( string $sharer , SimpleXMLElement $shareData ) : void {
$this -> createdUserGroupShares [ " $sharer " ] = $shareData ;
2022-12-21 17:22:22 +05:45
}
/**
2023-07-26 12:01:09 +05:45
* @return array
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function getCreatedUserGroupShares () : array {
return $this -> createdUserGroupShares ;
2022-12-21 17:22:22 +05:45
}
/**
2023-07-26 12:01:09 +05:45
* @return SimpleXMLElement
2022-12-21 17:22:22 +05:45
*/
2023-07-26 12:01:09 +05:45
public function getLastCreatedUserGroupShare () : SimpleXMLElement {
return \end ( $this -> createdUserGroupShares );
2022-12-21 17:22:22 +05:45
}
/**
* @return void
*/
2023-08-03 13:51:22 +05:45
public function emptyCreatedPublicShares () : void {
$this -> createdPublicShares = [];
2022-12-21 17:22:22 +05:45
}
/**
* @return void
*/
2023-07-26 12:01:09 +05:45
public function emptyCreatedUserGroupShares () : void {
$this -> createdUserGroupShares = [];
2022-12-21 17:22:22 +05:45
}
/**
2023-05-02 17:25:56 +05:45
* @return float|null
2022-12-21 17:22:22 +05:45
*/
2023-05-02 17:25:56 +05:45
public function getLocalLastShareTime () :? float {
2022-12-21 17:22:22 +05:45
return $this -> localLastShareTime ;
}
/**
* @param string|null $postfix string to append to the end of the path
*
* @return string
*/
public function getSharesEndpointPath ( ? string $postfix = '' ) : string {
2023-05-02 17:25:56 +05:45
return "/apps/files_sharing/api/v $this->sharingApiVersion /shares $postfix " ;
2022-12-21 17:22:22 +05:45
}
2024-01-02 16:53:47 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedLinkShareID () : string {
$lastResponse = $this -> shareNgGetLastCreatedLinkShare ();
if ( ! isset ( $this -> getJsonDecodedResponse ( $lastResponse )[ 'id' ])) {
2024-01-11 11:31:28 +05:45
throw new Error ( 'Response did not contain share id for the created public link' );
2024-01-02 16:53:47 +05:45
}
return $this -> getJsonDecodedResponse ( $lastResponse )[ 'id' ];
}
2024-01-05 13:57:59 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedLinkShareToken () : string {
$lastResponse = $this -> shareNgGetLastCreatedLinkShare ();
if ( ! isset ( $this -> getJsonDecodedResponse ( $lastResponse )[ 'link' ][ 'webUrl' ])) {
throw new Error ( 'Response did not contain share id ' . $this -> getJsonDecodedResponse ( $lastResponse )[ 'link' ][ 'webUrl' ] . ' for the created public link' );
}
$last_created_link_webURL = $this -> getJsonDecodedResponse ( $lastResponse )[ 'link' ][ 'webUrl' ];
return substr ( strrchr ( $last_created_link_webURL , "/" ), 1 );
}
2024-01-11 11:31:28 +05:45
/**
* @return string
*/
public function shareNgGetLastCreatedUserGroupShareID () : string {
$lastResponse = $this -> shareNgGetLastCreatedUserGroupShare ();
if ( ! isset ( $this -> getJsonDecodedResponse ( $lastResponse )[ 'value' ][ 0 ][ 'id' ])) {
throw new Error ( 'Response did not contain share id for the last created share.' );
}
return $this -> getJsonDecodedResponse ( $lastResponse )[ 'value' ][ 0 ][ 'id' ];
}
2022-12-21 17:22:22 +05:45
/**
2024-04-26 15:27:00 +05:45
* Split given permissions string each separated with "," into an array of strings
2022-12-21 17:22:22 +05:45
*
* @param string $str
*
* @return string[]
*/
private function splitPermissionsString ( string $str ) : array {
$str = \trim ( $str );
$permissions = \array_map ( 'trim' , \explode ( ',' , $str ));
/* We use 'all', 'uploadwriteonly' and 'change' in feature files
for readability. Parse into appropriate permissions and return them
without any duplications.*/
if ( \in_array ( 'all' , $permissions , true )) {
$permissions = \array_keys ( SharingHelper :: PERMISSION_TYPES );
}
if ( \in_array ( 'uploadwriteonly' , $permissions , true )) {
// remove 'uploadwriteonly' from $permissions
$permissions = \array_diff ( $permissions , [ 'uploadwriteonly' ]);
$permissions = \array_merge ( $permissions , [ 'create' ]);
}
if ( \in_array ( 'change' , $permissions , true )) {
// remove 'change' from $permissions
$permissions = \array_diff ( $permissions , [ 'change' ]);
$permissions = \array_merge (
$permissions ,
[ 'create' , 'delete' , 'read' , 'update' ]
);
}
return \array_unique ( $permissions );
}
/**
*
* @return int
*
* @throws Exception
*/
public function getServerShareTimeFromLastResponse () : int {
$stime = $this -> getResponseXml ( null , __METHOD__ ) -> xpath ( "//stime" );
2023-05-02 17:25:56 +05:45
if ( $stime ) {
2022-12-21 17:22:22 +05:45
return ( int ) $stime [ 0 ];
}
throw new Exception ( "Last share time (i.e. 'stime') could not be found in the response." );
}
/**
* @return void
*/
private function waitToCreateShare () : void {
if (( $this -> localLastShareTime !== null )
&& (( \microtime ( true ) - $this -> localLastShareTime ) < 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 );
}
}
/**
* @param string $user
* @param TableNode|null $body
2023-04-21 14:59:50 +05:45
* TableNode $body should not have any heading and can have the following rows |
2022-12-21 17:22:22 +05:45
* | path | The folder or file path to be shared |
* | name | A (human-readable) name for the share, |
* | | which can be up to 64 characters in length. |
* | publicUpload | Whether to allow public upload to a public |
* | | shared folder. Write true for allowing. |
* | password | The password to protect the public link share with. |
* | expireDate | An expire date for public link shares. |
* | | This argument takes a date string in any format |
* | | that can be passed to strtotime(), for example: |
* | | 'YYYY-MM-DD' or '+ x days'. It will be converted to |
* | | 'YYYY-MM-DD' format before sending |
* | expireDateAsString | An expire date string for public link shares. |
* | | Whatever string is provided will be sent as the |
* | | expire date. For example, use this to test sending |
* | | invalid date strings. |
* | permissions | The permissions to set on the share. |
* | | 1 = read; 2 = update; 4 = create; |
* | | 8 = delete; 16 = share; 31 = all |
2023-12-06 17:00:47 +05:45
* | | 15 = change; 0 = invite |
2022-12-21 17:22:22 +05:45
* | | 4 = uploadwriteonly |
* | | (default: 31, for public shares: 1) |
* | | Pass either the (total) number, |
* | | or the keyword, |
2023-04-21 14:59:50 +05:45
* | | or a comma separated list of keywords |
2022-12-21 17:22:22 +05:45
* | shareWith | The user or group id with which the file should |
* | | be shared. |
* | shareType | The type of the share. This can be one of: |
* | | 0 = user, 1 = group, 3 = public_link, |
* | | 6 = federated (cloud share). |
* | | Pass either the number or the keyword. |
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
2023-10-03 17:24:47 +05:45
public function createShareWithSettings ( string $user , ? TableNode $body ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeRows (
$body ,
[ 'path' ],
$this -> shareFields
);
$bodyRows = $body -> getRowsHash ();
$bodyRows [ 'name' ] = \array_key_exists ( 'name' , $bodyRows ) ? $bodyRows [ 'name' ] : null ;
$bodyRows [ 'shareWith' ] = \array_key_exists ( 'shareWith' , $bodyRows ) ? $bodyRows [ 'shareWith' ] : null ;
$bodyRows [ 'shareWith' ] = $this -> getActualUsername ( $bodyRows [ 'shareWith' ]);
$bodyRows [ 'publicUpload' ] = \array_key_exists ( 'publicUpload' , $bodyRows ) ? $bodyRows [ 'publicUpload' ] === 'true' : null ;
$bodyRows [ 'password' ] = \array_key_exists ( 'password' , $bodyRows ) ? $this -> getActualPassword ( $bodyRows [ 'password' ]) : null ;
if ( \array_key_exists ( 'permissions' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'permissions' ])) {
$bodyRows [ 'permissions' ] = ( int ) $bodyRows [ 'permissions' ];
} else {
$bodyRows [ 'permissions' ] = $this -> splitPermissionsString ( $bodyRows [ 'permissions' ]);
}
} else {
$bodyRows [ 'permissions' ] = null ;
}
if ( \array_key_exists ( 'shareType' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'shareType' ])) {
$bodyRows [ 'shareType' ] = ( int ) $bodyRows [ 'shareType' ];
}
} else {
$bodyRows [ 'shareType' ] = null ;
}
Assert :: assertFalse (
isset ( $bodyRows [ 'expireDate' ], $bodyRows [ 'expireDateAsString' ]),
'expireDate and expireDateAsString cannot be set at the same time.'
);
$needToParse = \array_key_exists ( 'expireDate' , $bodyRows );
$expireDate = $bodyRows [ 'expireDate' ] ?? $bodyRows [ 'expireDateAsString' ] ?? null ;
$bodyRows [ 'expireDate' ] = $needToParse ? \date ( 'Y-m-d' , \strtotime ( $expireDate )) : $expireDate ;
2023-10-03 17:24:47 +05:45
return $this -> createShare (
2022-12-21 17:22:22 +05:45
$user ,
$bodyRows [ 'path' ],
$bodyRows [ 'shareType' ],
$bodyRows [ 'shareWith' ],
$bodyRows [ 'publicUpload' ],
$bodyRows [ 'password' ],
$bodyRows [ 'permissions' ],
$bodyRows [ 'name' ],
$bodyRows [ 'expireDate' ]
);
}
/**
* @When /^user "([^"]*)" creates a share using the sharing API with settings$/
*
* @param string $user
* @param TableNode|null $body {@link createShareWithSettings}
*
* @return void
* @throws Exception
*/
public function userCreatesAShareWithSettings ( string $user , ? TableNode $body ) : void {
$user = $this -> getActualUsername ( $user );
2023-10-03 17:24:47 +05:45
$response = $this -> createShareWithSettings (
2022-12-21 17:22:22 +05:45
$user ,
$body
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has created a share with settings$/
*
* @param string $user
* @param TableNode|null $body {@link createShareWithSettings}
*
* @return void
* @throws Exception
*/
public function userHasCreatedAShareWithSettings ( string $user , ? TableNode $body ) {
2023-10-03 17:24:47 +05:45
$response = $this -> createShareWithSettings (
2022-12-21 17:22:22 +05:45
$user ,
$body
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function createPublicLinkShare ( string $user , TableNode $body ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$rows = $body -> getRows ();
// A public link share is shareType 3
$rows [] = [ 'shareType' , 'public_link' ];
$newBody = new TableNode ( $rows );
2024-05-22 17:10:47 +05:45
return $this -> createShareWithSettings ( $user , $newBody );
}
/**
* @When /^user "([^"]*)" creates a public link share using the sharing API with settings$/
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
public function userCreatesAPublicLinkShareWithSettings ( string $user , TableNode $body ) : void {
$this -> setResponse ( $this -> createPublicLinkShare ( $user , $body ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has created a public link share with settings$/
*
* @param string $user
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function userHasCreatedAPublicLinkShareWithSettings ( string $user , TableNode $body ) : void {
$response = $this -> createPublicLinkShare ( $user , $body );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
$this -> clearStatusCodeArrays ();
}
/**
* @When /^the user creates a public link share using the sharing API with settings$/
*
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function theUserCreatesAPublicLinkShareWithSettings ( TableNode $body ) : void {
$this -> setResponse ( $this -> createPublicLinkShare ( $this -> currentUser , $body ));
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has created a public link share with settings$/
*
2024-05-22 17:10:47 +05:45
* @param TableNode $body
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function theUserHasCreatedAPublicLinkShareWithSettings ( TableNode $body ) : void {
$response = $this -> createPublicLinkShare ( $this -> currentUser , $body );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $path
* @param boolean $publicUpload
* @param string|null $sharePassword
* @param string|int|string[]|int[]|null $permissions
* @param string|null $linkName
* @param string|null $expireDate
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function createAPublicShare (
string $user ,
string $path ,
bool $publicUpload = false ,
string $sharePassword = null ,
$permissions = null ,
? string $linkName = null ,
? string $expireDate = null
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
return $this -> createShare (
2022-12-21 17:22:22 +05:45
$user ,
$path ,
'public_link' ,
null , // shareWith
$publicUpload ,
$sharePassword ,
$permissions ,
$linkName ,
$expireDate
);
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userCreatesAPublicLinkShareOf ( string $user , string $path ) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userHasCreatedAPublicLinkShareOf ( string $user , string $path ) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/
*
* @param string $user
* @param string $path
* @param string|int|string[]|int[]|null $permissions
*
* @return void
*/
public function userCreatesAPublicLinkShareOfWithPermission (
string $user ,
string $path ,
$permissions
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path , true , null , $permissions );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/
*
* @param string $user
* @param string $path
* @param string|int|string[]|int[]|null $permissions
*
* @return void
*/
public function userHasCreatedAPublicLinkShareOfWithPermission (
string $user ,
string $path ,
$permissions
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAPublicShare ( $user , $path , true , null , $permissions );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function createPublicLinkShareOfResourceWithExpiry (
string $user ,
string $path ,
string $expiryDate
) : void {
$this -> createAPublicShare (
$user ,
$path ,
true ,
null ,
null ,
null ,
$expiryDate
);
}
/**
* @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with expiry "([^"]*)"$/
*
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function userCreatesAPublicLinkShareOfWithExpiry (
string $user ,
string $path ,
string $expiryDate
) : void {
$this -> createPublicLinkShareOfResourceWithExpiry (
$user ,
$path ,
$expiryDate
);
}
/**
* @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with expiry "([^"]*)"$/
*
* @param string $user
* @param string $path
* @param string $expiryDate in a valid date format, e.g. "+30 days"
*
* @return void
*/
public function userHasCreatedAPublicLinkShareOfWithExpiry (
string $user ,
string $path ,
string $expiryDate
) : void {
$this -> createPublicLinkShareOfResourceWithExpiry (
$user ,
$path ,
$expiryDate
);
$this -> theHTTPStatusCodeShouldBeSuccess ();
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should not be able to create a public link share of (?:file|folder) "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
*
* @return void
* @throws Exception
*/
2024-04-26 15:27:00 +05:45
public function shouldNotBeAbleToCreatePublicLinkShare ( string $sharer , string $filepath ) : void {
2022-12-21 17:22:22 +05:45
$this -> createAPublicShare ( $sharer , $filepath );
Assert :: assertEquals (
404 ,
$this -> ocsContext -> getOCSResponseStatusCode ( $this -> response ),
__METHOD__
. " Expected response status code is '404' but got '"
. $this -> ocsContext -> getOCSResponseStatusCode ( $this -> response )
. "'"
);
}
/**
* @param TableNode|null $body
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
2023-12-05 18:43:30 +05:45
public function updateLastShareByCurrentUser ( ? TableNode $body ) : ResponseInterface {
return $this -> updateLastShareWithSettings ( $this -> currentUser , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user updates the last share using the sharing API with$/
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function theUserUpdatesTheLastShareWith ( ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> updateLastShareByCurrentUser ( $body ));
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has updated the last share with$/
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function theUserHasUpdatedTheLastShareWith ( ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareByCurrentUser ( $body );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
2023-07-26 12:01:09 +05:45
/**
* Gets the last user share id using the sharer's name
*
* @param string|null $user
*
* @return string
* @throws Exception
*/
public function getLastCreatedUserGroupShareId ( ? string $user = null ) : string {
if ( $user === null ) {
2024-06-11 11:44:13 +05:45
$shareId = $this -> isUsingSharingNG () ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShare () -> id ;
return ( string ) $shareId ;
2023-07-26 12:01:09 +05:45
}
$createdShares = $this -> getCreatedUserGroupShares ();
if ( isset ( $createdShares [ $user ])) {
return ( string ) $createdShares [ $user ] -> id ;
}
throw new Exception ( __METHOD__ . " user ' $user ' doesn't have a share in the created shares list" );
}
2022-12-21 17:22:22 +05:45
/**
* @param string $user
* @param TableNode|null $body
* @param string|null $shareOwner
* @param bool $updateLastPublicLink
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws Exception
*/
public function updateLastShareWithSettings (
string $user ,
? TableNode $body ,
? string $shareOwner = null ,
? bool $updateLastPublicLink = false
2023-12-05 18:43:30 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
if ( $updateLastPublicLink ) {
2024-05-03 09:50:52 +05:45
$share_id = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedLinkShareID () : ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
} else {
if ( $shareOwner === null ) {
2024-05-09 17:17:14 +05:45
$share_id = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
} else {
2023-07-26 12:01:09 +05:45
$share_id = $this -> getLastCreatedUserGroupShareId ( $shareOwner );
2022-12-21 17:22:22 +05:45
}
}
$this -> verifyTableNodeRows (
$body ,
[],
$this -> shareFields
);
$bodyRows = $body -> getRowsHash ();
2023-03-13 13:11:37 +05:45
2022-12-21 17:22:22 +05:45
if ( \array_key_exists ( 'password' , $bodyRows )) {
$bodyRows [ 'password' ] = $this -> getActualPassword ( $bodyRows [ 'password' ]);
}
if ( \array_key_exists ( 'permissions' , $bodyRows )) {
if ( \is_numeric ( $bodyRows [ 'permissions' ])) {
$bodyRows [ 'permissions' ] = ( int ) $bodyRows [ 'permissions' ];
} else {
$bodyRows [ 'permissions' ] = $this -> splitPermissionsString ( $bodyRows [ 'permissions' ]);
$bodyRows [ 'permissions' ] = SharingHelper :: getPermissionSum ( $bodyRows [ 'permissions' ]);
}
}
2023-12-05 18:43:30 +05:45
return OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"PUT" ,
$this -> getSharesEndpointPath ( "/ $share_id " ),
$this -> getStepLineRef (),
$bodyRows ,
$this -> ocsApiVersion
);
}
/**
* @When /^user "([^"]*)" updates the last share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userUpdatesTheLastShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> updateLastShareWithSettings ( $user , $body ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" updates the last public link share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userUpdatesTheLastPublicLinkShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has updated the last share with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userHasUpdatedTheLastShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has updated the last public link share with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userHasUpdatedTheLastPublicLinkShareWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has updated the last share of "([^"]*)" with$/
*
* @param string $user
* @param string $shareOwner
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userHasUpdatedTheLastShareOfWith ( string $user , string $shareOwner , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$response = $this -> updateLastShareWithSettings ( $user , $body , $shareOwner );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
if ( $this -> ocsApiVersion == 1 ) {
2023-12-05 18:43:30 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100" , "" , $response );
2022-12-21 17:22:22 +05:45
} elseif ( $this -> ocsApiVersion === 2 ) {
2023-12-05 18:43:30 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "200" , "" , $response );
2022-12-21 17:22:22 +05:45
} else {
throw new Exception ( 'Invalid ocs api version used' );
}
}
/**
* @param string $user
* @param string|null $path
* @param string|null $shareType
* @param string|null $shareWith
* @param bool|null $publicUpload
* @param string|null $sharePassword
* @param string|int|string[]|int[]|null $permissions
* @param string|null $linkName
* @param string|null $expireDate
2023-10-26 12:59:34 +05:45
* @param string|null $space_ref
2022-12-21 17:22:22 +05:45
* @param string $sharingApp
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws JsonException
* @throws Exception
*/
public function createShare (
string $user ,
? string $path = null ,
? string $shareType = null ,
? string $shareWith = null ,
? bool $publicUpload = null ,
? string $sharePassword = null ,
$permissions = null ,
? string $linkName = null ,
? string $expireDate = null ,
2023-10-26 12:59:34 +05:45
? string $space_ref = null ,
2022-12-21 17:22:22 +05:45
string $sharingApp = 'files_sharing'
2023-10-03 17:24:47 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$userActual = $this -> getActualUsername ( $user );
if ( \is_string ( $permissions ) && ! \is_numeric ( $permissions )) {
$permissions = $this -> splitPermissionsString ( $permissions );
}
$this -> waitToCreateShare ();
2023-10-03 17:24:47 +05:45
$response = SharingHelper :: createShare (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$userActual ,
$this -> getPasswordForUser ( $user ),
$path ,
$shareType ,
$this -> getStepLineRef (),
$shareWith ,
$publicUpload ,
$sharePassword ,
$permissions ,
$linkName ,
$expireDate ,
2023-10-26 12:59:34 +05:45
$space_ref ,
2022-12-21 17:22:22 +05:45
$this -> ocsApiVersion ,
$this -> sharingApiVersion ,
$sharingApp
);
2023-10-03 17:24:47 +05:45
// save the created share data
2023-10-05 10:52:16 +05:45
if (( $response -> getStatusCode () === 200 )
&& \in_array ( $this -> ocsContext -> getOCSResponseStatusCode ( $response ), [ '100' , '200' ])
) {
2023-10-03 17:24:47 +05:45
$xmlResponse = $this -> getResponseXml ( $response );
if ( isset ( $xmlResponse -> data )) {
$shareData = $xmlResponse -> data ;
2023-08-03 13:51:22 +05:45
if ( $shareType === 'public_link' ) {
$this -> addToCreatedPublicShares ( $shareData );
} else {
2023-10-03 17:24:47 +05:45
$sharer = ( string ) $xmlResponse -> data -> uid_owner ;
2023-08-03 13:51:22 +05:45
$this -> addToCreatedUserGroupshares ( $sharer , $shareData );
2023-07-26 12:01:09 +05:45
}
2022-12-21 17:22:22 +05:45
}
}
$this -> localLastShareTime = \microtime ( true );
2023-10-03 17:24:47 +05:45
return $response ;
2022-12-21 17:22:22 +05:45
}
/**
* @param string $field
* @param string $value
* @param string $contentExpected
* @param bool $expectSuccess if true then the caller expects that the field
* has the expected content
* emit debugging information if the field is not as expected
*
* @return bool
*/
public function doesFieldValueMatchExpectedContent (
string $field ,
string $value ,
string $contentExpected ,
bool $expectSuccess = true
) : bool {
if (( $contentExpected === "ANY_VALUE" )
|| (( $contentExpected === "A_TOKEN" ) && ( \strlen ( $value ) === 15 ))
|| (( $contentExpected === "A_NUMBER" ) && \is_numeric ( $value ))
2024-04-26 15:27:00 +05:45
|| (( $contentExpected === "A_STRING" ) && $value !== "" )
2022-12-21 17:22:22 +05:45
|| (( $contentExpected === "AN_URL" ) && $this -> isAPublicLinkUrl ( $value ))
|| (( $field === 'remote' ) && ( \rtrim ( $value , "/" ) === $contentExpected ))
|| ( $contentExpected === $value )
) {
if ( ! $expectSuccess ) {
echo $field . " is unexpectedly set with value '" . $value . "' \n " ;
}
return true ;
}
return false ;
}
/**
* @param string $field
* @param string|null $contentExpected
* @param bool $expectSuccess if true then the caller expects that the field
* is in the response with the expected content
* so emit debugging information if the field is not correct
* @param SimpleXMLElement|null $data
*
* @return bool
* @throws Exception
*/
public function isFieldInResponse ( string $field , ? string $contentExpected , bool $expectSuccess = true , ? SimpleXMLElement $data = null ) : bool {
if ( $data === null ) {
$data = $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ];
}
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
2023-02-01 09:55:51 +01:00
$dateFieldsArrayToConvert = [ 'original_date' , 'new_date' ];
2022-12-21 17:22:22 +05:45
//do not try to convert empty date
if (( string ) \in_array ( $field , \array_merge ( $dateFieldsArrayToConvert )) && ! empty ( $contentExpected )) {
$timestamp = \strtotime ( $contentExpected , $this -> getServerShareTimeFromLastResponse ());
// strtotime returns false if it failed to parse, just leave it as it is in that condition
if ( $timestamp !== false ) {
$contentExpected
= \date (
'Y-m-d' ,
$timestamp
) . " 00:00:00" ;
}
}
$contentExpected = ( string ) $contentExpected ;
if ( \count ( $data -> element ) > 0 ) {
$fieldIsSet = false ;
$value = "" ;
foreach ( $data as $element ) {
if ( isset ( $element -> $field )) {
$fieldIsSet = true ;
$value = ( string ) $element -> $field ;
2023-02-01 09:55:51 +01:00
// convert expiration to Y-m-d format. bug #5424
if ( $field === "expiration" ) {
$value = ( preg_split ( "/[\sT]+/" , $value ))[ 0 ];
}
2022-12-21 17:22:22 +05:45
if ( $this -> doesFieldValueMatchExpectedContent (
$field ,
$value ,
$contentExpected ,
$expectSuccess
)
) {
return true ;
}
}
}
} else {
$fieldIsSet = isset ( $data -> $field );
if ( $fieldIsSet ) {
$value = ( string ) $data -> $field ;
if ( $this -> doesFieldValueMatchExpectedContent (
$field ,
$value ,
$contentExpected ,
$expectSuccess
)
) {
return true ;
}
}
}
if ( $expectSuccess ) {
if ( $fieldIsSet ) {
echo $field . " has unexpected value '" . $value . "' \n " ;
} else {
echo $field . " is not set in response \n " ;
}
}
return false ;
}
/**
* @Then no files or folders should be included in the response
*
* @return void
*/
public function checkNoFilesFoldersInResponse () : void {
$data = $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ];
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
Assert :: assertCount ( 0 , $data );
}
/**
* @Then exactly :count file/files or folder/folders should be included in the response
*
* @param string $count
*
* @return void
*/
public function checkCountFilesFoldersInResponse ( string $count ) : void {
$count = ( int ) $count ;
$data = $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ];
Assert :: assertIsObject ( $data , __METHOD__ . " data not found in response XML" );
Assert :: assertCount ( $count , $data , __METHOD__ . " the response does not contain $count entries" );
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should be included in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
public function checkSharedFileInResponse ( string $filename ) : void {
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertTrue (
$this -> isFieldInResponse ( 'file_target' , " $filename " ),
"'file_target' value ' $filename ' was not found in response"
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should not be included in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
public function checkSharedFileNotInResponse ( string $filename ) : void {
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertFalse (
$this -> isFieldInResponse ( 'file_target' , " $filename " , false ),
"'file_target' value ' $filename ' was unexpectedly found in response"
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should be included as path in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
public function checkSharedFileAsPathInResponse ( string $filename ) : void {
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertTrue (
$this -> isFieldInResponse ( 'path' , " $filename " ),
"'path' value ' $filename ' was not found in response"
);
}
/**
* @Then /^(?:file|folder|entry) "([^"]*)" should not be included as path in the response$/
*
* @param string $filename
*
* @return void
* @throws Exception
*/
public function checkSharedFileAsPathNotInResponse ( string $filename ) : void {
$filename = "/" . \ltrim ( $filename , '/' );
Assert :: assertFalse (
$this -> isFieldInResponse ( 'path' , " $filename " , false ),
"'path' value ' $filename ' was unexpectedly found in response"
);
}
/**
* @Then /^(user|group) "([^"]*)" should be included in the response$/
*
* @param string $type
* @param string $user
*
* @return void
* @throws Exception
*/
public function checkSharedUserOrGroupInResponse ( string $type , string $user ) : void {
if ( $type === 'user' ) {
$user = $this -> getActualUsername ( $user );
}
Assert :: assertTrue (
$this -> isFieldInResponse ( 'share_with' , " $user " ),
"'share_with' value ' $user ' was not found in response"
);
}
/**
* @Then /^user "([^"]*)" should not be included in the response$/
* @Then /^group "([^"]*)" should not be included in the response$/
*
* @param string $userOrGroup
*
* @return void
* @throws Exception
*/
public function checkSharedUserOrGroupNotInResponse ( string $userOrGroup ) : void {
Assert :: assertFalse (
$this -> isFieldInResponse ( 'share_with' , " $userOrGroup " , false ),
"'share_with' value ' $userOrGroup ' was unexpectedly found in response"
);
}
/**
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-03 17:24:47 +05:45
public function createAUserShare (
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
$permissions = null
) : ResponseInterface {
return $this -> createShare (
$sharer ,
$filepath ,
'0' ,
$this -> getActualUsername ( $sharee ),
null ,
null ,
$permissions
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userSharesFileWithUserUsingTheSharingApi (
2023-10-03 17:24:47 +05:45
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
2022-12-21 17:22:22 +05:45
$permissions = null
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAUserShare (
$sharer ,
2022-12-21 17:22:22 +05:45
$filepath ,
2023-10-03 17:24:47 +05:45
$this -> getActualUsername ( $sharee ),
2022-12-21 17:22:22 +05:45
$permissions
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $sharer
* @param string $sharee
* @param TableNode $table
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userSharesTheFollowingFilesWithUserUsingTheSharingApi (
string $sharer ,
string $sharee ,
TableNode $table ,
$permissions = null
) : void {
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $filepath ) {
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath [ "path" ],
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $sharee ),
2022-12-21 17:22:22 +05:45
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/
*
2023-10-03 17:24:47 +05:45
* @param string $sharer
2022-12-21 17:22:22 +05:45
* @param string $filepath
2023-10-03 17:24:47 +05:45
* @param string $sharee
2022-12-21 17:22:22 +05:45
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userHasSharedFileWithUserUsingTheSharingApi (
2023-10-03 17:24:47 +05:45
string $sharer ,
2022-12-21 17:22:22 +05:45
string $filepath ,
2023-10-03 17:24:47 +05:45
string $sharee ,
2022-12-21 17:22:22 +05:45
$permissions = null
) : void {
2023-10-03 17:24:47 +05:45
$response = $this -> createAUserShare (
$sharer ,
2022-12-21 17:22:22 +05:45
$filepath ,
2023-10-03 17:24:47 +05:45
$this -> getActualUsername ( $sharee ),
$permissions
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with the administrator(?: with permissions (\d+))?$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with the administrator with permissions "([^"]*)"$/
*
* @param string $sharer
* @param string $filepath
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userHasSharedFileWithTheAdministrator (
string $sharer ,
string $filepath ,
$permissions = null
) : void {
$admin = $this -> getAdminUsername ();
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $admin ),
2022-12-21 17:22:22 +05:45
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $filepath
* @param string $user2
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserSharesFileWithUserUsingTheSharingApi (
string $filepath ,
string $user2 ,
$permissions = null
) {
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$this -> getCurrentUser (),
2024-05-22 17:10:47 +05:45
$filepath [ "path" ],
$this -> getActualUsername ( $user2 ),
2022-12-21 17:22:22 +05:45
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/
*
* @param string $filepath
* @param string $user2
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserHasSharedFileWithUserUsingTheSharingApi (
string $filepath ,
string $user2 ,
$permissions = null
) : void {
$user2 = $this -> getActualUsername ( $user2 );
2024-05-22 17:10:47 +05:45
$response = $this -> createAUserShare (
2022-12-21 17:22:22 +05:45
$this -> getCurrentUser (),
$filepath ,
2024-05-22 17:10:47 +05:45
$this -> getActualUsername ( $user2 ),
2022-12-21 17:22:22 +05:45
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserSharesFileWithGroupUsingTheSharingApi (
string $filepath ,
string $group ,
$permissions = null
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$this -> currentUser ,
$filepath ,
$group ,
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))?$/
* @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)"$/
*
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function theUserHasSharedFileWithGroupUsingTheSharingApi (
string $filepath ,
string $group ,
$permissions = null
) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$this -> currentUser ,
$filepath ,
$group ,
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
2023-10-03 17:24:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-03 17:24:47 +05:45
public function createAGroupShare (
2022-12-21 17:22:22 +05:45
string $user ,
string $filepath ,
string $group ,
2023-10-03 17:24:47 +05:45
$permissions = null
) : ResponseInterface {
return $this -> createShare (
$user ,
$filepath ,
'1' ,
$group ,
null ,
null ,
$permissions
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userSharesFileWithGroupUsingTheSharingApi (
string $user ,
string $filepath ,
string $group ,
$permissions = null
) {
2023-10-03 17:24:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath ,
$group ,
$permissions
);
2023-10-03 17:24:47 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @When /^user "([^"]*)" shares the following (?:files|folders|entries) with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userSharesTheFollowingFilesWithGroupUsingTheSharingApi (
string $user ,
string $group ,
TableNode $table ,
$permissions = null
) {
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $filepath ) {
2024-05-22 17:10:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath [ "path" ],
$group ,
$permissions
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
}
/**
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)"$/
* @Given /^user "([^"]*)" has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))?$/
*
* @param string $user
* @param string $filepath
* @param string $group
* @param string|int|string[]|int[] $permissions
*
* @return void
*/
public function userHasSharedFileWithGroupUsingTheSharingApi (
string $user ,
string $filepath ,
string $group ,
$permissions = null
) {
2023-10-03 17:24:47 +05:45
$response = $this -> createAGroupShare (
2022-12-21 17:22:22 +05:45
$user ,
$filepath ,
$group ,
2023-10-03 17:24:47 +05:45
$permissions
2022-12-21 17:22:22 +05:45
);
2023-10-03 17:24:47 +05:45
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" tries to update the last share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userTriesToUpdateTheLastShareUsingTheSharingApiWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" tries to update the last public link share using the sharing API with$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function userTriesToUpdateTheLastPublicLinkShareUsingTheSharingApiWith ( string $user , ? TableNode $body ) : void {
2023-12-05 18:43:30 +05:45
$this -> response = $this -> updateLastShareWithSettings ( $user , $body , null , true );
2022-12-21 17:22:22 +05:45
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)" with permissions "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroupShareType
* @param string $sharee
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userTriesToShareFileUsingTheSharingApi (
string $sharer ,
string $filepath ,
string $userOrGroupShareType ,
string $sharee ,
$permissions = null
) : void {
$sharee = $this -> getActualUsername ( $sharee );
2023-10-03 17:24:47 +05:45
$response = $this -> createShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
$userOrGroupShareType ,
$sharee ,
null ,
null ,
$permissions
);
2023-10-03 17:24:47 +05:45
$statusCode = $this -> ocsContext -> getOCSResponseStatusCode ( $response );
2022-12-21 17:22:22 +05:45
Assert :: assertTrue (
( $statusCode == 404 ) || ( $statusCode == 403 ),
"Sharing should have failed with status code 403 or 404 but got status code $statusCode "
);
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^user "([^"]*)" should be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions (\d+))? using the sharing API$/
* @Then /^user "([^"]*)" should be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)" with permissions "([^"]*)" using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $sharer
* @param string $filepath
* @param string $userOrGroupShareType
* @param string $sharee
* @param string|int|string[]|int[] $permissions
*
* @return void
* @throws Exception
*/
public function userShouldBeAbleToShareUsingTheSharingApi (
string $sharer ,
string $filepath ,
string $userOrGroupShareType ,
string $sharee ,
$permissions = null
) : void {
$sharee = $this -> getActualUsername ( $sharee );
2023-10-03 17:24:47 +05:45
$response = $this -> createShare (
2022-12-21 17:22:22 +05:45
$sharer ,
$filepath ,
$userOrGroupShareType ,
$sharee ,
null ,
null ,
$permissions
);
2023-10-03 17:24:47 +05:45
$statusCode = $this -> ocsContext -> getOCSResponseStatusCode ( $response );
Assert :: assertTrue (
( $statusCode == 100 ) || ( $statusCode == 200 ),
"Sharing should be successful but got ocs status code $statusCode "
);
2022-12-21 17:22:22 +05:45
}
/**
* @When /^the user deletes the last share using the sharing API$/
*
* @return void
*/
public function theUserDeletesLastShareUsingTheSharingAPI () : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApiByCurrentUser ());
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^the user has deleted the last share$/
*
* @return void
*/
public function theUserHasDeletedLastShareUsingTheSharingAPI () : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deleteLastShareUsingSharingApiByCurrentUser ();
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user the user who will do the delete request
* @param string|null $sharer the specific user whose share will be deleted (if specified)
* @param bool $deleteLastPublicLink
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-02 17:00:04 +05:45
public function deleteLastShareUsingSharingApi ( string $user , string $sharer = null , bool $deleteLastPublicLink = false ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
if ( $deleteLastPublicLink ) {
2023-08-03 13:51:22 +05:45
$shareId = ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
} else {
if ( $sharer === null ) {
2024-05-16 15:34:28 +05:45
$shareId = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
} else {
2024-05-16 15:34:28 +05:45
$shareId = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ( $sharer );
2022-12-21 17:22:22 +05:45
}
}
$url = $this -> getSharesEndpointPath ( "/ $shareId " );
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"DELETE" ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
}
/**
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-02 17:00:04 +05:45
public function deleteLastShareUsingSharingApiByCurrentUser () : ResponseInterface {
return $this -> deleteLastShareUsingSharingApi ( $this -> currentUser );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" deletes the last share using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userDeletesLastShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" deletes the last public link share using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last public link share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userDeletesLastPublicLinkShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user , null , true ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" deletes the last share of user "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" tries to delete the last share of user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $sharer
*
* @return void
*/
public function userDeletesLastShareOfUserUsingTheSharingApi ( string $user , string $sharer ) : void {
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $this -> deleteLastShareUsingSharingApi ( $user , $sharer ));
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Given /^user "([^"]*)" has deleted the last share$/
*
* @param string $user
*
* @return void
*/
public function userHasDeletedLastShareUsingTheSharingApi ( string $user ) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deleteLastShareUsingSharingApi ( $user );
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-05-22 17:10:47 +05:45
* @param string $user
* @param string $shareType user|group|link
* @param string|null $language
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function getLastShareInfo ( string $user , string $shareType , ? string $language = null ) : ResponseInterface {
if ( $shareType !== "link" ) {
$shareId = $this -> isUsingSharingNg () ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
} else {
$shareId = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedLinkShareID () : ( string ) $this -> getLastCreatedPublicShare () -> id ;
}
if ( $shareId === null ) {
throw new Exception (
__METHOD__ . " last public link share data was not found"
);
}
$language = TranslationHelper :: getLanguage ( $language );
return $this -> getShareData ( $user , $shareId , $language );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" gets the info of the last share in language "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" gets the info of the last share using the sharing API$/
*
* @param string $user username that requests the information (might not be the user that has initiated the share)
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function userGetsInfoOfLastShareUsingTheSharingApi ( string $user ) : void {
$response = $this -> getLastShareInfo ( $user , "user" );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" gets the info of the last public link share in language "([^"]*)" using the sharing API$/
* @When /^user "([^"]*)" gets the info of the last public link share using the sharing API$/
*
* @param string $user username that requests the information (might not be the user that has initiated the share)
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function userGetsInfoOfLastPublicLinkShareUsingTheSharingApi ( string $user ) : void {
$response = $this -> getLastShareInfo ( $user , "link" );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @Then /^as "([^"]*)" the info about the last share by user "([^"]*)" with user "([^"]*)" should include$/
*
2023-05-02 17:25:56 +05:45
* @param string $requester
2022-12-21 17:22:22 +05:45
* @param string $sharer
* @param string $sharee
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function asLastShareInfoAboutUserSharingWithUserShouldInclude (
2023-05-02 17:25:56 +05:45
string $requester ,
string $sharer ,
string $sharee ,
2022-12-21 17:22:22 +05:45
TableNode $table
) {
2024-05-22 17:10:47 +05:45
$response = $this -> getLastShareInfo ( $requester , "user" );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
$this -> checkTheFieldsOfLastResponseToUser ( $sharer , $sharee , $table );
2022-12-21 17:22:22 +05:45
}
/**
* Get share data of specific share_id
*
* @param string $user
* @param string $share_id
* @param string|null $language
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-02 17:00:04 +05:45
public function getShareData ( string $user , string $share_id , ? string $language = null ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
$headers = [];
if ( $language !== null ) {
$headers [ 'Accept-Language' ] = $language ;
}
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"GET" ,
$url ,
null ,
null ,
$headers
);
}
/**
* @param string $user
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function getSharedWithMeShares ( string $user ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$url = "/apps/files_sharing/api/v1/shares?shared_with_me=true" ;
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
}
/**
* @When user :user gets all the shares shared with him/her using the sharing API
*
* @param string $user
*
* @return void
*/
public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi ( string $user ) : void {
$this -> setResponse ( $this -> getSharedWithMeShares ( $user ));
2022-12-21 17:22:22 +05:45
}
2023-02-01 09:55:51 +01:00
/**
2023-03-11 12:47:31 +05:45
* @Then the information about the last share for user :user should include
2023-02-01 09:55:51 +01:00
*
* @param string $user
* @param TableNode $table
*
* @return void
2024-05-13 16:28:53 +05:45
* @throws Exception
2023-02-01 09:55:51 +01:00
*/
2023-05-02 17:25:56 +05:45
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi ( string $user , TableNode $table ) : void {
2023-02-01 09:55:51 +01:00
$user = $this -> getActualUsername ( $user );
2024-05-13 16:28:53 +05:45
$shareId = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2023-10-02 17:00:04 +05:45
$response = $this -> getShareData ( $user , $shareId );
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $table , $response );
2023-02-01 09:55:51 +01:00
}
2022-12-21 17:22:22 +05:45
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets the (|pending)\s?(user|group|user and group|public link) shares shared with (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $pending
* @param string $shareType
*
* @return void
*/
public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi ( string $user , string $pending , string $shareType ) : void {
$user = $this -> getActualUsername ( $user );
if ( $pending === "pending" ) {
$pendingClause = "&state=" . SharingHelper :: SHARE_STATES [ 'pending' ];
} else {
$pendingClause = "" ;
}
if ( $shareType === 'public link' ) {
$shareType = 'public_link' ;
}
if ( $shareType === 'user and group' ) {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ 'user' ] . "," . SharingHelper :: SHARE_TYPES [ 'group' ];
} else {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ $shareType ];
}
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
$this -> getSharesEndpointPath (
"?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes
2023-05-02 17:25:56 +05:45
)
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets all the shares shared with (?:him|her|them) that are received as (?:file|folder|entry) "([^"]*)" using the provisioning API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userGetsAllSharesSharedWithHimFromFileOrFolderUsingTheProvisioningApi ( string $user , string $path ) : void {
$user = $this -> getActualUsername ( $user );
$url = "/apps/files_sharing/api/"
2023-05-02 17:25:56 +05:45
. "v $this->sharingApiVersion /shares?shared_with_me=true&path= $path " ;
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
'GET' ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
2023-06-28 10:56:08 +05:45
* @param string|null $endpointPath
2022-12-21 17:22:22 +05:45
*
2023-06-28 10:56:08 +05:45
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
2022-12-21 17:22:22 +05:45
*/
2023-06-28 10:56:08 +05:45
public function getAllShares (
string $user ,
? string $endpointPath = null
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-06-28 10:56:08 +05:45
return OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
2023-06-28 10:56:08 +05:45
$this -> getSharesEndpointPath ( $endpointPath ),
2022-12-21 17:22:22 +05:45
$this -> getStepLineRef (),
[],
$this -> ocsApiVersion
);
}
/**
2023-06-28 10:56:08 +05:45
* @When /^user "([^"]*)" gets all shares shared by (?:him|her) using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userGetsAllSharesSharedByHimUsingTheSharingApi ( string $user ) : void {
$this -> setResponse ( $this -> getAllshares ( $user ));
}
/**
* @When /^the administrator gets all shares shared by (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @return void
*/
public function theAdministratorGetsAllSharesSharedByHimUsingTheSharingApi () : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $this -> getAdminUsername ()));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When /^user "([^"]*)" gets the (user|group|user and group|public link) shares shared by (?:him|her) using the sharing API$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $shareType
*
* @return void
*/
public function userGetsFilteredSharesSharedByHimUsingTheSharingApi ( string $user , string $shareType ) : void {
if ( $shareType === 'public link' ) {
$shareType = 'public_link' ;
}
if ( $shareType === 'user and group' ) {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ 'user' ] . "," . SharingHelper :: SHARE_TYPES [ 'group' ];
} else {
$rawShareTypes = SharingHelper :: SHARE_TYPES [ $shareType ];
}
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?share_types=" . $rawShareTypes ));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When user :user gets all the shares of the file :path using the sharing API
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userGetsAllTheSharesFromTheFileUsingTheSharingApi ( string $user , string $path ) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?path= $path " ));
2022-12-21 17:22:22 +05:45
}
/**
2023-05-05 15:05:47 +05:45
* @When user :user gets all the shares with reshares of the file :path using the sharing API
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userGetsAllTheSharesWithResharesFromTheFileUsingTheSharingApi (
string $user ,
string $path
) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?reshares=true&path= $path " ));
2022-12-21 17:22:22 +05:45
}
/**
* @When user :user gets all the shares inside the folder :path using the sharing API
*
* @param string $user
* @param string $path
*
* @return void
*/
public function userGetsAllTheSharesInsideTheFolderUsingTheSharingApi ( string $user , string $path ) : void {
2023-06-28 10:56:08 +05:45
$this -> setResponse ( $this -> getAllShares ( $user , "?path= $path &subfiles=true" ));
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the response when user "([^"]*)" gets the info of the last share should include$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function theResponseWhenUserGetsInfoOfLastShareShouldInclude (
string $user ,
? TableNode $body
) : void {
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeRows ( $body , [], $this -> shareResponseFields );
2024-05-06 16:41:39 +05:45
$share_id = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
$response = $this -> getShareData ( $user , $share_id );
2022-12-21 17:22:22 +05:45
$this -> theHTTPStatusCodeShouldBe (
200 ,
2023-10-02 17:00:04 +05:45
"Error getting info of last share for user $user " ,
$response
2022-12-21 17:22:22 +05:45
);
$this -> ocsContext -> assertOCSResponseIndicatesSuccess (
__METHOD__ .
' Error getting info of last share for user $user\n' .
$this -> ocsContext -> getOCSResponseStatusMessage (
2023-10-02 17:00:04 +05:45
$response
) . '"' ,
$response
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the response when user "([^"]*)" gets the info of the last public link share should include$/
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function theResponseWhenUserGetsInfoOfLastPublicLinkShareShouldInclude (
string $user ,
? TableNode $body
) : void {
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeRows ( $body , [], $this -> shareResponseFields );
2023-08-03 13:51:22 +05:45
$this -> getShareData ( $user , ( string ) $this -> getLastCreatedPublicShare () -> id );
2022-12-21 17:22:22 +05:45
$this -> theHTTPStatusCodeShouldBe (
200 ,
"Error getting info of last public link share for user $user "
);
$this -> ocsContext -> assertOCSResponseIndicatesSuccess (
__METHOD__ .
' Error getting info of last public link share for user $user\n' .
$this -> ocsContext -> getOCSResponseStatusMessage (
$this -> getResponse ()
) . '"'
);
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @Then the information of the last share of user :user should include
*
* @param string $user
* @param TableNode $body
*
* @return void
* @throws Exception
*/
public function informationOfLastShareShouldInclude (
string $user ,
TableNode $body
) : void {
$user = $this -> getActualUsername ( $user );
2023-07-26 12:01:09 +05:45
$shareId = $this -> getLastCreatedUserGroupShareId ( $user );
2022-12-21 17:22:22 +05:45
$this -> getShareData ( $user , $shareId );
$this -> theHTTPStatusCodeShouldBe (
200 ,
"Error getting info of last share for user $user with share id $shareId "
);
$this -> verifyTableNodeRows ( $body , [], $this -> shareResponseFields );
2024-05-22 17:10:47 +05:45
$this -> checkTheFields ( $user , $body );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the information for user "((?:[^']*)|(?:[^"]*))" about the received share of (file|folder) "((?:[^']*)|(?:[^"]*))" shared with a (user|group) should include$/
*
* @param string $user
* @param string $fileOrFolder
* @param string $fileName
* @param string $type
* @param TableNode $body should provide share_type
*
* @return void
* @throws Exception
*/
public function theFieldsOfTheResponseForUserForResourceShouldInclude (
string $user ,
string $fileOrFolder ,
string $fileName ,
string $type ,
TableNode $body
) : void {
$user = $this -> getActualUsername ( $user );
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$fileName = $fileName [ 0 ] === "/" ? $fileName : '/' . $fileName ;
$data = $this -> getAllSharesSharedWithUser ( $user );
Assert :: assertNotEmpty ( $data , 'No shares found for ' . $user );
$bodyRows = $body -> getRowsHash ();
Assert :: assertArrayHasKey ( 'share_type' , $bodyRows , 'share_type is not provided' );
$share_id = null ;
foreach ( $data as $share ) {
if ( $share [ 'file_target' ] === $fileName && $share [ 'item_type' ] === $fileOrFolder ) {
if (( $share [ 'share_type' ] === SharingHelper :: getShareType ( $bodyRows [ 'share_type' ]))
) {
$share_id = $share [ 'id' ];
}
}
}
Assert :: assertNotNull ( $share_id , "Could not find share id for " . $user );
if ( \array_key_exists ( 'expiration' , $bodyRows ) && $bodyRows [ 'expiration' ] !== '' ) {
$bodyRows [ 'expiration' ] = \date ( 'd-m-Y' , \strtotime ( $bodyRows [ 'expiration' ]));
}
$this -> getShareData ( $user , $share_id );
foreach ( $bodyRows as $field => $value ) {
2024-04-26 15:27:00 +05:45
if ( $type === "user" && $field == "share_with" ) {
2022-12-21 17:22:22 +05:45
$value = $this -> getActualUsername ( $value );
}
2024-04-26 15:27:00 +05:45
if ( $field == "uid_owner" ) {
2022-12-21 17:22:22 +05:45
$value = $this -> getActualUsername ( $value );
}
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
$this -> isFieldInResponse ( $field , $value ),
" $field doesn't have value ' $value '"
);
}
}
/**
* @Then /^the last share_id should be included in the response/
*
* @return void
* @throws Exception
*/
public function checkingLastShareIDIsIncluded () : void {
2024-05-15 15:20:58 +05:45
$shareId = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
if ( ! $this -> isFieldInResponse ( 'id' , $shareId )) {
Assert :: fail (
"Share id $shareId not found in response"
);
}
}
/**
* @Then /^the last share id should not be included in the response/
*
* @return void
* @throws Exception
*/
public function checkLastShareIDIsNotIncluded () : void {
2024-05-15 15:20:58 +05:45
$shareId = $this -> isUsingSharingNG () ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
"Share id $shareId has been found in response"
);
}
}
/**
* @Then /^the last public link share id should not be included in the response/
*
* @return void
* @throws Exception
*/
public function checkLastPublicLinkShareIDIsNotIncluded () : void {
2023-08-03 13:51:22 +05:45
$shareId = ( string ) $this -> getLastCreatedPublicShare () -> id ;
2022-12-21 17:22:22 +05:45
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
"Public link share id $shareId has been found in response"
);
}
}
/**
2024-05-22 17:10:47 +05:45
*
* @param ResponseInterface $response
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2024-05-22 17:10:47 +05:45
public function responseShouldNotContainAnyShareIds ( ResponseInterface $response ) : void {
$data = $this -> getResponseXml ( $response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
$fieldIsSet = false ;
$receivedShareCount = 0 ;
if ( \count ( $data -> element ) > 0 ) {
foreach ( $data as $element ) {
if ( isset ( $element -> id )) {
$fieldIsSet = true ;
$receivedShareCount += 1 ;
}
}
} else {
if ( isset ( $data -> id )) {
$fieldIsSet = true ;
$receivedShareCount += 1 ;
}
}
Assert :: assertFalse (
$fieldIsSet ,
"response contains $receivedShareCount share ids but should not contain any share ids"
);
}
/**
* @Then user :user should not see the share id of the last share
*
* @param string $user
*
* @return void
* @throws Exception
*/
public function userShouldNotSeeShareIdOfLastShare ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getSharedWithMeShares ( $user );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$shareId = $this -> isUsingSharingNG () ? $this -> shareNgGetLastCreatedUserGroupShareID () : $this -> getLastCreatedUserGroupShareId ();
if ( $this -> isFieldInResponse ( 'id' , $shareId , false )) {
Assert :: fail (
"Share id $shareId has been found in response"
);
}
2022-12-21 17:22:22 +05:45
}
/**
* @Then user :user should not have any received shares
*
* @param string $user
*
* @return void
*/
public function userShouldNotHaveAnyReceivedShares ( string $user ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> getSharedWithMeShares ( $user );
$this -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> responseShouldNotContainAnyShareIds ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the response should contain ([0-9]+) entries$/
*
* @param int $count
*
* @return void
*/
public function checkingTheResponseEntriesCount ( int $count ) : void {
$actualCount = \count ( $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ]);
Assert :: assertEquals (
$count ,
$actualCount ,
"Expected that the response should contain ' $count ' entries but got ' $actualCount ' entries"
);
}
/**
* @Then the fields of the last response to user :user should include
*
* @param string $user
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
2024-05-22 17:10:47 +05:45
public function checkFields ( string $user , ? TableNode $body ) : void {
$this -> checkTheFields ( $user , $body );
}
/**
* @param string $user
* @param TableNode|null $body
* @param ResponseInterface|null $response
*
* @return void
*/
public function checkTheFields ( string $user , ? TableNode $body , ? ResponseInterface $response = null ) : void {
2023-10-02 17:00:04 +05:45
$response = $response ?? $this -> getResponse ();
$data = $this -> getResponseXml ( $response , __METHOD__ ) -> data [ 0 ];
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
$userRelatedFieldNames = [
"owner" ,
"user" ,
"uid_owner" ,
"uid_file_owner" ,
"share_with" ,
"displayname_file_owner" ,
2023-02-02 15:03:46 +05:45
"displayname_owner" ,
"additional_info_owner" ,
"additional_info_file_owner"
2022-12-21 17:22:22 +05:45
];
foreach ( $bodyRows as $field => $value ) {
if ( \in_array ( $field , $userRelatedFieldNames )) {
$value = $this -> substituteInLineCodes ( $value , $user );
}
$value = $this -> getActualUsername ( $value );
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
2023-10-02 17:00:04 +05:45
$this -> isFieldInResponse ( $field , $value , true , $data ),
" $field doesn't have value ' $value '" ,
2022-12-21 17:22:22 +05:45
);
}
}
/**
2023-06-27 12:50:10 +02:00
* @Then the fields of the last response to user :user and space :space should include
*
* @param string $user
* @param string $space
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function checkFieldsOfSpaceSharingResponse ( string $user , string $space , ? TableNode $body ) : void {
$this -> verifyTableNodeColumnsCount ( $body , 2 );
2023-07-26 12:01:09 +05:45
2023-06-27 12:50:10 +02:00
$bodyRows = $body -> getRowsHash ();
$userRelatedFieldNames = [
"owner" ,
"user" ,
"uid_owner" ,
"uid_file_owner" ,
"share_with" ,
"displayname_file_owner" ,
"displayname_owner" ,
"additional_info_owner" ,
"additional_info_file_owner" ,
"space_id"
];
2023-08-03 13:51:22 +05:45
$response = $this -> getResponseXml ( null , __METHOD__ );
$this -> addToCreatedPublicShares ( $response -> data );
2023-06-27 12:50:10 +02:00
foreach ( $bodyRows as $field => $value ) {
if ( \in_array ( $field , $userRelatedFieldNames )) {
$value = $this -> substituteInLineCodes (
$value ,
$user ,
[],
[
[
"code" => "%space_id%" ,
"function" =>
[ $this -> spacesContext , "getSpaceIdByName" ],
"parameter" => [ $user , $space ]
],
],
null ,
null
);
if ( $field === "uid_file_owner" ) {
$value = ( explode ( "$" , $value ))[ 1 ];
}
if ( $field === "space_id" ) {
2024-04-26 15:27:00 +05:45
$explodedSpaceId = explode ( "$" , $value );
$value = $explodedSpaceId [ 0 ] . "$" . $explodedSpaceId [ 1 ] . "!" . $explodedSpaceId [ 1 ];
2023-06-27 12:50:10 +02:00
}
}
$value = $this -> getActualUsername ( $value );
$value = $this -> replaceValuesFromTable ( $field , $value );
2023-07-26 12:01:09 +05:45
2023-06-27 12:50:10 +02:00
Assert :: assertTrue (
2023-08-03 13:51:22 +05:45
$this -> isFieldInResponse ( $field , $value , true , $this -> getLastCreatedPublicShare ()),
2023-06-27 12:50:10 +02:00
" $field doesn't have value ' $value '"
);
}
}
/**
2022-12-21 17:22:22 +05:45
* @Then /^the fields of the last response (?:to|about) user "([^"]*)" sharing with (?:user|group) "([^"]*)" should include$/
*
* @param string $sharer
* @param string $sharee
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function checkFieldsOfLastResponseToUser ( string $sharer , string $sharee , ? TableNode $body ) : void {
2024-05-22 17:10:47 +05:45
$this -> checkTheFieldsOfLastResponseToUser ( $sharer , $sharee , $body );
}
/**
* @param string $sharer
* @param string $sharee
* @param TableNode|null $body
*
* @return void
*/
public function checkTheFieldsOfLastResponseToUser ( string $sharer , string $sharee , ? TableNode $body ) : void {
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
foreach ( $bodyRows as $field => $value ) {
2024-06-20 11:34:53 +05:45
if ( \in_array ( $field , [ "displayname_owner" , "displayname_file_owner" , "owner" , "uid_owner" , "uid_file_owner" , "additional_info_owner" , "additional_info_file_owner" ])) {
2022-12-21 17:22:22 +05:45
$value = $this -> substituteInLineCodes ( $value , $sharer );
2024-06-20 11:34:53 +05:45
} elseif ( \in_array ( $field , [ "share_with" , "share_with_displayname" , "user" , "share_with_additional_info" ])) {
2022-12-21 17:22:22 +05:45
$value = $this -> substituteInLineCodes ( $value , $sharee );
}
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertTrue (
$this -> isFieldInResponse ( $field , $value ),
" $field doesn't have value ' $value '"
);
}
}
/**
* @Then the last response should be empty
*
* @return void
*/
public function theFieldsOfTheLastResponseShouldBeEmpty () : void {
$data = $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ];
Assert :: assertEquals (
\count ( $data -> element ),
0 ,
"last response contains data but was expected to be empty"
);
}
/**
*
* @return string
*
* @throws Exception
*/
public function getSharingAttributesFromLastResponse () : string {
$responseXml = $this -> getResponseXml ( null , __METHOD__ ) -> data [ 0 ];
$actualAttributesElement = $responseXml -> xpath ( '//attributes' );
2023-05-02 17:25:56 +05:45
if ( $actualAttributesElement ) {
2022-12-21 17:22:22 +05:45
$actualAttributes = ( array ) $actualAttributesElement [ 0 ];
if ( empty ( $actualAttributes )) {
throw new Exception (
"No data inside 'attributes' element in the last response."
);
}
return $actualAttributes [ 0 ];
}
throw new Exception ( "No 'attributes' found inside the response of the last share." );
}
/**
* @Then the additional sharing attributes for the response should include
*
* @param TableNode $attributes
*
* @return void
* @throws Exception
*/
public function checkingAttributesInLastShareResponse ( TableNode $attributes ) : void {
$this -> verifyTableNodeColumns ( $attributes , [ 'scope' , 'key' , 'enabled' ]);
$attributes = $attributes -> getHash ();
// change string "true"/"false" to boolean inside array
\array_walk_recursive (
$attributes ,
function ( & $value , $key ) {
if ( $key !== 'enabled' ) {
return ;
}
if ( $value === 'true' ) {
$value = true ;
}
if ( $value === 'false' ) {
$value = false ;
}
}
);
$actualAttributes = $this -> getSharingAttributesFromLastResponse ();
// parse json to array
$actualAttributesArray = \json_decode ( $actualAttributes , true );
if ( \json_last_error () !== JSON_ERROR_NONE ) {
$errMsg = \strtolower ( \json_last_error_msg ());
throw new Exception (
"JSON decoding failed because of $errMsg in json \n " .
'Expected data to be json with array of objects. ' .
" \n Received: \n $actualAttributes "
);
}
// check if the expected attributes received from table match actualAttributes
foreach ( $attributes as $row ) {
$foundRow = false ;
foreach ( $actualAttributesArray as $item ) {
if (( $item [ 'scope' ] === $row [ 'scope' ])
&& ( $item [ 'key' ] === $row [ 'key' ])
&& ( $item [ 'enabled' ] === $row [ 'enabled' ])
) {
$foundRow = true ;
}
}
Assert :: assertTrue (
$foundRow ,
"Could not find expected attribute with scope '" . $row [ 'scope' ] . "' and key '" . $row [ 'key' ] . "'"
);
}
}
/**
* @Then the downloading of file :fileName for user :user should fail with error message
*
* @param string $fileName
* @param string $user
* @param PyStringNode $errorMessage
*
* @return void
* @throws Exception
*/
public function userDownloadsFailWithMessage ( string $fileName , string $user , PyStringNode $errorMessage ) : void {
$user = $this -> getActualUsername ( $user );
2023-10-11 16:15:31 +05:45
$response = $this -> downloadFileAsUserUsingPassword ( $user , $fileName );
$receivedErrorMessage = $this -> getResponseXml ( $response , __METHOD__ ) -> xpath ( '//s:message' );
2023-05-02 17:25:56 +05:45
Assert :: assertEquals (
$errorMessage ,
( string ) $receivedErrorMessage [ 0 ],
"Expected error message was ' $errorMessage ' but got '"
2024-04-26 15:27:00 +05:45
. $receivedErrorMessage [ 0 ]
2023-05-02 17:25:56 +05:45
. "'"
);
2022-12-21 17:22:22 +05:45
}
/**
* @Then the fields of the last response should not include
*
* @param TableNode|null $body
*
* @return void
* @throws Exception
*/
public function checkFieldsNotInResponse ( ? TableNode $body ) : void {
$this -> verifyTableNodeColumnsCount ( $body , 2 );
$bodyRows = $body -> getRowsHash ();
foreach ( $bodyRows as $field => $value ) {
$value = $this -> replaceValuesFromTable ( $field , $value );
Assert :: assertFalse (
$this -> isFieldInResponse ( $field , $value , false ),
" $field has value $value but should not"
);
}
}
/**
* Returns shares of a file or folder as a SimpleXMLElement
*
* Note: the "single" SimpleXMLElement may contain one or more actual
2023-04-21 14:59:50 +05:45
* shares (to users, groups or public links etc.). If you access an item directly,
2022-12-21 17:22:22 +05:45
* for example, getShares()->id, then the value of "id" for the first element
* will be returned. To access all the elements, you can loop through the
* returned SimpleXMLElement with "foreach" - it will act like a PHP array
* of elements.
*
* @param string $user
* @param string $path
*
* @return SimpleXMLElement
*/
public function getShares ( string $user , string $path ) : SimpleXMLElement {
2023-12-05 18:43:30 +05:45
$response = OcsApiHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
$this -> getSharesEndpointPath ( "?path= $path " ),
$this -> getStepLineRef (),
[],
$this -> ocsApiVersion
);
2023-12-05 18:43:30 +05:45
return $this -> getResponseXml ( $response , __METHOD__ ) -> data -> element ;
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^as user "([^"]*)" the public shares of (?:file|folder) "([^"]*)" should be$/
*
* @param string $user
* @param string $path
* @param TableNode|null $TableNode
*
* @return void
* @throws Exception
*/
public function checkPublicShares ( string $user , string $path , ? TableNode $TableNode ) : void {
$user = $this -> getActualUsername ( $user );
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
2022-12-21 17:22:22 +05:45
$this -> verifyTableNodeColumns ( $TableNode , [ 'path' , 'permissions' , 'name' ]);
if ( $TableNode instanceof TableNode ) {
$elementRows = $TableNode -> getHash ();
foreach ( $elementRows as $expectedElementsArray ) {
$nameFound = false ;
2023-05-24 12:56:43 +05:45
foreach ( $response as $elementResponded ) {
2022-12-21 17:22:22 +05:45
if (( string ) $elementResponded -> name [ 0 ] === $expectedElementsArray [ 'name' ]) {
Assert :: assertEquals (
$expectedElementsArray [ 'path' ],
( string ) $elementResponded -> path [ 0 ],
__METHOD__
2024-04-22 11:20:00 +02:00
. " Expected ' { $expectedElementsArray [ 'path' ] } ' but got '"
2023-05-02 17:25:56 +05:45
. $elementResponded -> path [ 0 ]
2022-12-21 17:22:22 +05:45
. "'"
);
Assert :: assertEquals (
$expectedElementsArray [ 'permissions' ],
( string ) $elementResponded -> permissions [ 0 ],
__METHOD__
2024-04-22 11:20:00 +02:00
. " Expected ' { $expectedElementsArray [ 'permissions' ] } ' but got '"
2023-05-02 17:25:56 +05:45
. $elementResponded -> permissions [ 0 ]
2022-12-21 17:22:22 +05:45
. "'"
);
$nameFound = true ;
break ;
}
}
Assert :: assertTrue (
$nameFound ,
"Shared link name { $expectedElementsArray [ 'name' ] } not found"
);
}
}
}
/**
2024-04-26 15:27:00 +05:45
* @Then /^as user "([^"]*)" the (?:file|folder) "([^"]*)" should not have any shares$/
2022-12-21 17:22:22 +05:45
*
* @param string $user
* @param string $path
*
* @return void
* @throws Exception
*/
2024-04-26 15:27:00 +05:45
public function checkPublicSharesAreEmpty ( string $user , string $path ) : void {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
2022-12-21 17:22:22 +05:45
//It shouldn't have public shares
Assert :: assertEquals (
0 ,
2023-05-24 12:56:43 +05:45
\count ( $response ),
2022-12-21 17:22:22 +05:45
__METHOD__
. " As ' $user ', ' $path ' was expected to have no shares, but got '"
2023-05-24 12:56:43 +05:45
. \count ( $response )
2022-12-21 17:22:22 +05:45
. "' shares present"
);
}
/**
* @param string $user
* @param string $path to share
* @param string $name of share
*
* @return string|null
*/
public function getPublicShareIDByName ( string $user , string $path , string $name ) :? string {
2023-05-24 12:56:43 +05:45
$response = $this -> getShares ( $user , $path );
foreach ( $response as $elementResponded ) {
2022-12-21 17:22:22 +05:45
if (( string ) $elementResponded -> name [ 0 ] === $name ) {
return ( string ) $elementResponded -> id [ 0 ];
}
}
return null ;
}
/**
* @param string $user
* @param string $name
* @param string $path
*
2023-10-02 17:00:04 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function deletePublicLinkShareUsingTheSharingApi (
string $user ,
string $name ,
string $path
2023-10-02 17:00:04 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$share_id = $this -> getPublicShareIDByName ( $user , $path , $name );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
2024-05-09 13:01:41 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"DELETE" ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
}
/**
* @When /^user "([^"]*)" deletes public link share named "([^"]*)" in (?:file|folder) "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $name
* @param string $path
*
* @return void
*/
public function userDeletesPublicLinkShareNamedUsingTheSharingApi (
string $user ,
string $name ,
string $path
) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deletePublicLinkShareUsingTheSharingApi (
2022-12-21 17:22:22 +05:45
$user ,
$name ,
$path
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has deleted public link share named "([^"]*)" in (?:file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $name
* @param string $path
*
* @return void
*/
public function userHasDeletedPublicLinkShareNamedUsingTheSharingApi (
string $user ,
string $name ,
string $path
) : void {
2023-10-02 17:00:04 +05:45
$response = $this -> deletePublicLinkShareUsingTheSharingApi (
2022-12-21 17:22:22 +05:45
$user ,
$name ,
$path
);
2023-10-02 17:00:04 +05:45
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
2024-05-22 17:10:47 +05:45
* @param string|null $state
2022-12-21 17:22:22 +05:45
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function reactToShareOfferedBy ( string $user , string $action , string $share , string $offeredBy , ? string $state = '' ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$offeredBy = $this -> getActualUsername ( $offeredBy );
2023-05-24 12:56:43 +05:45
$response = $this -> getAllSharesSharedWithUser ( $user );
2022-12-21 17:22:22 +05:45
$shareId = null ;
2023-05-24 12:56:43 +05:45
foreach ( $response as $shareElement ) {
2022-12-21 17:22:22 +05:45
// SharingHelper::SHARE_STATES has the mapping between the words for share states
// like "accepted", "pending",... and the integer constants 0, 1,... that are in
// the "state" field of the share data.
if ( $state === '' ) {
// Any share state is OK
$matchesShareState = true ;
} else {
$requiredStateCode = SharingHelper :: SHARE_STATES [ $state ];
if ( $shareElement [ 'state' ] === $requiredStateCode ) {
$matchesShareState = true ;
} else {
$matchesShareState = false ;
}
}
if ( $matchesShareState
&& ( string ) $shareElement [ 'uid_owner' ] === $offeredBy
&& ( string ) $shareElement [ 'path' ] === $share
) {
$shareId = ( string ) $shareElement [ 'id' ];
break ;
}
}
Assert :: assertNotNull (
$shareId ,
__METHOD__ . " could not find share $share , offered by $offeredBy to $user "
);
2023-05-02 17:25:56 +05:45
$url = "/apps/files_sharing/api/v $this->sharingApiVersion " .
2022-12-21 17:22:22 +05:45
"/shares/pending/ $shareId " ;
if ( \substr ( $action , 0 , 7 ) === "decline" ) {
$httpRequestMethod = "DELETE" ;
2023-05-02 17:25:56 +05:45
} else {
// do a POST to accept the share
2022-12-21 17:22:22 +05:45
$httpRequestMethod = "POST" ;
}
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
$httpRequestMethod ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
}
/**
* @When /^user "([^"]*)" (declines|accepts) share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
* @param string|null $state specify 'accepted', 'pending', 'rejected' or 'declined' to only consider shares in that state
*
* @return void
* @throws Exception
*/
public function userReactsToShareOfferedBy ( string $user , string $action , string $share , string $offeredBy , ? string $state = '' ) : void {
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
$share ,
$offeredBy
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
2024-07-22 16:46:04 +05:45
/**
* @When /^user "([^"]*)" (declines|accepts) the already (?:accepted|declined) share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
* @param string|null $state specify 'accepted', 'pending', 'rejected' or 'declined' to only consider shares in that state
*
* @return void
* @throws Exception
*/
public function userAcceptsTheAlreadyAcceptedShareOfferedByUsingTheSharingApi ( string $user , string $action , string $share , string $offeredBy , ? string $state = '' ) : void {
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
"/Shares/" . \trim ( $share , "/" ),
$offeredBy
);
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
}
2022-12-21 17:22:22 +05:45
/**
* @When /^user "([^"]*)" (declines|accepts) the following shares offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $offeredBy
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function userReactsToTheFollowingSharesOfferedBy ( string $user , string $action , string $offeredBy , TableNode $table ) : void {
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
foreach ( $paths as $share ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy (
2022-12-21 17:22:22 +05:45
$user ,
$action ,
$share [ "path" ],
$offeredBy
);
2024-05-22 17:10:47 +05:45
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When /^user "([^"]*)" (declines|accepts) share with ID "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share_id
*
* @return void
* @throws Exception
*/
public function userReactsToShareWithShareIDOfferedBy ( string $user , string $action , string $share_id ) : void {
$user = $this -> getActualUsername ( $user );
$shareId = $this -> substituteInLineCodes ( $share_id , $user );
2023-05-02 17:25:56 +05:45
$url = "/apps/files_sharing/api/v $this->sharingApiVersion " .
2022-12-21 17:22:22 +05:45
"/shares/pending/ $shareId " ;
if ( \substr ( $action , 0 , 7 ) === "decline" ) {
$httpRequestMethod = "DELETE" ;
2023-05-02 17:25:56 +05:45
} else {
// do a POST to accept the share
2022-12-21 17:22:22 +05:45
$httpRequestMethod = "POST" ;
}
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
$httpRequestMethod ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has (declined|accepted) share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
public function userHasReactedToShareOfferedBy ( string $user , string $action , string $share , string $offeredBy ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy (
$user ,
$action ,
$share ,
$offeredBy
);
2022-12-21 17:22:22 +05:45
if ( $action === 'declined' ) {
$actionText = 'decline' ;
2023-05-02 17:25:56 +05:45
} else {
2022-12-21 17:22:22 +05:45
$actionText = 'accept' ;
}
$this -> theHTTPStatusCodeShouldBe (
200 ,
2024-05-22 17:10:47 +05:45
__METHOD__ . " could not $actionText share $share to $user by $offeredBy " ,
$response
2022-12-21 17:22:22 +05:45
);
$this -> emptyLastHTTPStatusCodesArray ();
$this -> emptyLastOCSStatusCodesArray ();
}
/**
* @When /^user "([^"]*)" accepts the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
public function userAcceptsThePendingShareOfferedBy ( string $user , string $share , string $offeredBy ) : void {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
$this -> setResponse ( $response );
$this -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has accepted the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
public function userHasAcceptedThePendingShareOfferedBy ( string $user , string $share , string $offeredBy ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
2022-12-21 17:22:22 +05:45
$this -> theHTTPStatusCodeShouldBe (
200 ,
2024-05-22 17:10:47 +05:45
__METHOD__ . " could not accept the pending share $share to $user by $offeredBy " ,
$response
2022-12-21 17:22:22 +05:45
);
2024-05-22 17:10:47 +05:45
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^user "([^"]*)" should be able to (decline|accept) pending share "([^"]*)" offered by user "([^"]*)"$/
*
* @param string $user
* @param string $action
* @param string $share
* @param string $offeredBy
*
* @return void
* @throws Exception
*/
public function userShouldBeAbleToAcceptShareOfferedBy (
string $user ,
string $action ,
string $share ,
string $offeredBy
) {
if ( $action === 'accept' ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'accepts' , $share , $offeredBy , 'pending' );
$this -> theHTTPStatusCodeShouldBe (
200 ,
__METHOD__ . " could not accept the pending share $share to $user by $offeredBy " ,
$response
);
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
// $this->ocsContext->assertOCSResponseIndicatesSuccess();
2022-12-21 17:22:22 +05:45
} elseif ( $action === 'decline' ) {
2024-05-22 17:10:47 +05:45
$response = $this -> reactToShareOfferedBy ( $user , 'declined' , $share , $offeredBy );
$this -> theHTTPStatusCodeShouldBe (
200 ,
__METHOD__ . " could not decline share $share to $user by $offeredBy " ,
$response
);
$this -> ocsContext -> theOCSStatusCodeShouldBe ( "100,200" , "" , $response );
// $this->emptyLastHTTPStatusCodesArray();
// $this->emptyLastOCSStatusCodesArray();
2022-12-21 17:22:22 +05:45
}
}
/**
*
* @Then /^the sharing API should report to user "([^"]*)" that these shares are in the (pending|accepted|declined) state$/
*
* @param string $user
* @param string $state
* @param TableNode $table table with headings that correspond to the attributes
* of the share e.g. "|path|uid_owner|"
*
* @return void
* @throws Exception
*/
public function assertSharesOfUserAreInState ( string $user , string $state , TableNode $table ) : void {
$this -> verifyTableNodeColumns ( $table , [ "path" ], $this -> shareResponseFields );
$usersShares = $this -> getAllSharesSharedWithUser ( $user , $state );
foreach ( $table as $row ) {
$found = false ;
//the API returns the path without trailing slash, but we want to
//be able to accept leading and/or trailing slashes in the step definition
$row [ 'path' ] = "/" . \trim ( $row [ 'path' ], "/" );
foreach ( $usersShares as $share ) {
try {
Assert :: assertArrayHasKey ( 'path' , $share );
Assert :: assertEquals ( $row [ 'path' ], $share [ 'path' ]);
$found = true ;
break ;
2023-06-08 16:59:45 +05:45
} catch ( ExpectationFailedException $e ) {
2022-12-21 17:22:22 +05:45
}
}
if ( ! $found ) {
Assert :: fail (
"could not find the share with this attributes " .
\print_r ( $row , true )
);
}
}
}
/**
*
* @Then /^the sharing API should report to user "([^"]*)" that no shares are in the (pending|accepted|declined) state$/
*
* @param string $user
* @param string $state
*
* @return void
* @throws Exception
*/
public function assertNoSharesOfUserAreInState ( string $user , string $state ) : void {
$usersShares = $this -> getAllSharesSharedWithUser ( $user , $state );
Assert :: assertEmpty (
$usersShares ,
"user has " . \count ( $usersShares ) . " share(s) in the $state state"
);
}
2023-05-24 12:56:43 +05:45
/**
2023-06-30 12:22:42 +05:45
* @param string $sharer
* @param string $path
* @param string $sharee
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2023-06-30 12:22:42 +05:45
*/
2024-05-22 17:10:47 +05:45
public function unshareResourceSharedTo ( string $sharer , string $path , string $sharee ) : ResponseInterface {
2023-05-24 12:56:43 +05:45
$sharer = $this -> getActualUsername ( $sharer );
$sharee = $this -> getActualUsername ( $sharee );
$response = $this -> getShares ( $sharer , " $path &share_types=0" );
$shareId = null ;
foreach ( $response as $shareElement ) {
if (( string ) $shareElement -> share_with [ 0 ] === $sharee ) {
$shareId = ( string ) $shareElement -> id ;
break ;
}
}
Assert :: assertNotNull (
$shareId ,
__METHOD__ . " could not find share, offered by $sharer to $sharee "
);
2024-05-22 17:10:47 +05:45
return $this -> ocsContext -> sendRequestToOcsEndpoint (
2023-05-24 12:56:43 +05:45
$sharer ,
'DELETE' ,
'/apps/files_sharing/api/v' . $this -> sharingApiVersion . '/shares/' . $shareId
);
2024-05-22 17:10:47 +05:45
}
2024-06-11 11:44:13 +05:45
2024-05-22 17:10:47 +05:45
/**
* @When /^user "([^"]*)" unshares (?:folder|file|entity) "([^"]*)" shared to "([^"]*)"$/
*
* @param string $sharer
* @param string $path
* @param string $sharee
*
* @return void
* @throws JsonException
*/
public function userUnsharesResourceSharedTo ( string $sharer , string $path , string $sharee ) : void {
$response = $this -> unshareResourceSharedTo ( $sharer , $path , $sharee );
2023-10-02 17:00:04 +05:45
$this -> setResponse ( $response );
2023-05-24 12:56:43 +05:45
}
2022-12-21 17:22:22 +05:45
/**
* @Then the sharing API should report that no shares are shared with user :user
*
* @param string $user
*
* @return void
* @throws Exception
*/
public function assertThatNoSharesAreSharedWithUser ( string $user ) : void {
$usersShares = $this -> getAllSharesSharedWithUser ( $user );
Assert :: assertEmpty (
$usersShares ,
"user has " . \count ( $usersShares ) . " share(s)"
);
}
/**
* @When user :user gets share with id :share using the sharing API
*
* @param string $user
* @param string $share_id
*
* @return ResponseInterface|null
*/
public function userGetsTheLastShareWithTheShareIdUsingTheSharingApi ( string $user , string $share_id ) : ? ResponseInterface {
$user = $this -> getActualUsername ( $user );
$share_id = $this -> substituteInLineCodes ( $share_id , $user );
$url = $this -> getSharesEndpointPath ( "/ $share_id " );
$this -> response = OcsApiHelper :: sendRequest (
$this -> getBaseUrl (),
$user ,
$this -> getPasswordForUser ( $user ),
"GET" ,
$url ,
$this -> getStepLineRef (),
[],
$this -> ocsApiVersion
);
return $this -> response ;
}
/**
*
* @param string $user
* @param string|null $state pending|accepted|declined|rejected|all
*
* @return array of shares that are shared with this user
* @throws Exception
*/
private function getAllSharesSharedWithUser ( string $user , ? string $state = "all" ) : array {
switch ( $state ) {
case 'pending' :
case 'accepted' :
case 'declined' :
case 'rejected' :
$stateCode = SharingHelper :: SHARE_STATES [ $state ];
break ;
case 'all' :
$stateCode = "all" ;
break ;
default :
throw new InvalidArgumentException (
__METHOD__ . ' invalid "state" given'
);
}
$url = $this -> getSharesEndpointPath ( "?format=json&shared_with_me=true&state= $stateCode " );
2024-05-09 13:01:41 +05:45
$response = $this -> ocsContext -> sendRequestToOcsEndpoint (
2022-12-21 17:22:22 +05:45
$user ,
"GET" ,
2023-05-02 17:25:56 +05:45
$url
2022-12-21 17:22:22 +05:45
);
2023-10-02 17:00:04 +05:45
if ( $response -> getStatusCode () !== 200 ) {
2022-12-21 17:22:22 +05:45
throw new Exception (
__METHOD__ . " could not retrieve information about shares"
);
}
2023-10-02 17:00:04 +05:45
$result = $response -> getBody () -> getContents ();
2022-12-21 17:22:22 +05:45
$usersShares = \json_decode ( $result , true );
if ( ! \is_array ( $usersShares )) {
throw new Exception (
__METHOD__ . " API result about shares is not valid JSON"
);
}
return $usersShares [ 'ocs' ][ 'data' ];
}
/**
* Send request for preview of a file in a public link
*
* @param string $fileName
* @param string $token
*
2024-05-22 17:10:47 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-05-22 17:10:47 +05:45
public function getPublicPreviewOfFile ( string $fileName , string $token ) : ResponseInterface {
2024-09-17 17:11:20 +05:45
$baseUrl = $this -> getBaseUrl ();
$davPath = WebdavHelper :: getDavPath ( $this -> getDavPathVersion (), $token , "public-files" );
2024-10-21 12:24:50 +05:45
$url = " $baseUrl / $davPath / $fileName ?preview=1" ;
2024-05-22 17:10:47 +05:45
return HttpRequestHelper :: get (
2022-12-21 17:22:22 +05:45
$url ,
$this -> getStepLineRef ()
);
}
/**
* @When the public accesses the preview of file :path from the last shared public link using the sharing API
*
* @param string $path
*
* @return void
*/
public function thePublicAccessesThePreviewOfTheSharedFileUsingTheSharingApi ( string $path ) : void {
2024-05-14 11:54:23 +05:45
$token = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedLinkShareToken () : $this -> getLastCreatedPublicShareToken ();
2024-05-22 17:10:47 +05:45
$response = $this -> getPublicPreviewOfFile ( $path , $token );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
/**
* @When the public accesses the preview of the following files from the last shared public link using the sharing API
*
* @param TableNode $table
*
* @throws Exception
* @return void
*/
public function thePublicAccessesThePreviewOfTheFollowingSharedFileUsingTheSharingApi (
TableNode $table
) : void {
$this -> verifyTableNodeColumns ( $table , [ "path" ]);
$paths = $table -> getHash ();
$this -> emptyLastHTTPStatusCodesArray ();
$this -> emptyLastOCSStatusCodesArray ();
foreach ( $paths as $path ) {
2024-05-14 11:54:23 +05:45
$token = ( $this -> isUsingSharingNG ()) ? $this -> shareNgGetLastCreatedLinkShareToken () : $this -> getLastCreatedPublicShareToken ();
2024-05-22 17:10:47 +05:45
$response = $this -> getPublicPreviewOfFile ( $path [ "path" ], $token );
$this -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> pushToLastStatusCodesArrays ();
}
}
/**
* @param string $user
* @param string $shareServer
* @param string|null $password
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function saveLastSharedPublicLinkShare (
string $user ,
string $shareServer ,
? string $password = ""
2023-12-05 18:43:30 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$user = $this -> getActualUsername ( $user );
$userPassword = $this -> getPasswordForUser ( $user );
2023-08-03 13:51:22 +05:45
$shareData = $this -> getLastCreatedPublicShare ();
$owner = ( string ) $shareData -> uid_owner ;
$name = $this -> encodePath (( string ) $shareData -> file_target );
2022-12-21 17:22:22 +05:45
$name = \trim ( $name , "/" );
2023-08-03 13:51:22 +05:45
$ownerDisplayName = ( string ) $shareData -> displayname_owner ;
$token = ( string ) $shareData -> token ;
2022-12-21 17:22:22 +05:45
if ( \strtolower ( $shareServer ) == "remote" ) {
$remote = $this -> getRemoteBaseUrl ();
} else {
$remote = $this -> getLocalBaseUrl ();
}
$body [ 'remote' ] = $remote ;
$body [ 'token' ] = $token ;
$body [ 'owner' ] = $owner ;
$body [ 'ownerDisplayName' ] = $ownerDisplayName ;
$body [ 'name' ] = $name ;
$body [ 'password' ] = $password ;
Assert :: assertNotNull (
$token ,
__METHOD__ . " could not find any public share"
);
$url = $this -> getBaseUrl () . "/index.php/apps/files_sharing/external" ;
$response = HttpRequestHelper :: post (
$url ,
$this -> getStepLineRef (),
$user ,
$userPassword ,
null ,
$body
);
2023-12-05 18:43:30 +05:45
return $response ;
2022-12-21 17:22:22 +05:45
}
/**
* @Given /^user "([^"]*)" has added the public share created from server "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $shareServer
*
* @return void
*/
public function userHasAddedPublicShareCreatedByUser ( string $user , string $shareServer ) : void {
$this -> saveLastSharedPublicLinkShare ( $user , $shareServer );
$resBody = json_decode ( $this -> response -> getBody () -> getContents ());
$status = '' ;
$message = '' ;
if ( $resBody ) {
$status = $resBody -> status ;
$message = $resBody -> data -> message ;
}
Assert :: assertEquals (
200 ,
$this -> response -> getStatusCode (),
__METHOD__
. " Expected status code is '200' but got '"
. $this -> response -> getStatusCode ()
. "'"
);
Assert :: assertNotEquals (
'error' ,
$status ,
__METHOD__
. " \n Failed to save public share. \n ' $message '"
);
}
/**
* @param string $user
* @param string $path
* @param string $type
* @param int $permissions
*
* @return array
*/
public function preparePublicQuickLinkPayload ( string $user , string $path , string $type , int $permissions = 1 ) : array {
return [
"permissions" => $permissions ,
"expireDate" => "" ,
"shareType" => 3 ,
"itemType" => $type ,
"itemSource" => $this -> getFileIdForPath ( $user , $path ),
"name" => "Public quick link" ,
"attributes" => [
[
"scope" => "files_sharing" ,
"key" => "isQuickLink" ,
"value" => true
]
],
"path" => $path
];
}
/**
* @Given /^user "([^"]*)" has created a read only public link for (file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $type
* @param string $path
*
* @return void
* @throws Exception
*/
public function theUserHasCreatedAReadOnlyPublicLinkForFileFolder ( string $user , string $type , string $path ) : void {
$user = $this -> getActualUsername ( $user );
$userPassword = $this -> getPasswordForUser ( $user );
$requestPayload = $this -> preparePublicQuickLinkPayload ( $user , $path , $type );
$url = $this -> getBaseUrl () . "/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json" ;
$response = HttpRequestHelper :: post (
$url ,
$this -> getStepLineRef (),
$user ,
$userPassword ,
null ,
$requestPayload
);
2023-12-05 18:43:30 +05:45
$this -> theHTTPStatusCodeShouldBeBetween ( 200 , 299 , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @When /^user "([^"]*)" adds the public share created from server "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $shareServer
*
* @return void
*/
public function userAddsPublicShareCreatedByUser ( string $user , string $shareServer ) : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> saveLastSharedPublicLinkShare ( $user , $shareServer ));
2022-12-21 17:22:22 +05:45
}
/**
* Expires last created public link share using the testing API
*
* @return void
2023-12-05 18:43:30 +05:45
* @throws ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-12-05 18:43:30 +05:45
public function expireLastCreatedPublicLinkShare () : ResponseInterface {
2023-08-03 13:51:22 +05:45
$shareId = ( string ) $this -> getLastCreatedPublicShare () -> id ;
2023-12-05 18:43:30 +05:45
return $this -> expireShare ( $shareId );
2022-12-21 17:22:22 +05:45
}
/**
* Expires a share using the testing API
*
* @param string|null $shareId optional share id, if null then expire the last share that was created.
*
2023-12-05 18:43:30 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
* @throws GuzzleException
*/
2023-12-05 18:43:30 +05:45
public function expireShare ( string $shareId = null ) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$adminUser = $this -> getAdminUsername ();
if ( $shareId === null ) {
2023-07-26 12:01:09 +05:45
$shareId = $this -> getLastCreatedUserGroupShareId ();
2022-12-21 17:22:22 +05:45
}
$response = OcsApiHelper :: sendRequest (
$this -> getBaseUrl (),
$adminUser ,
$this -> getAdminPassword (),
'POST' ,
2023-05-02 17:25:56 +05:45
"/apps/testing/api/v1/expire-share/ $shareId " ,
2022-12-21 17:22:22 +05:45
$this -> getStepLineRef (),
[],
$this -> getOcsApiVersion ()
);
2023-12-05 18:43:30 +05:45
return $response ;
2022-12-21 17:22:22 +05:45
}
/**
* @Given the administrator has expired the last created share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorHasExpiredTheLastCreatedShare () : void {
$this -> expireShare ();
$httpStatus = $this -> getResponse () -> getStatusCode ();
Assert :: assertSame (
200 ,
$httpStatus ,
"Request to expire last share failed. HTTP status was ' $httpStatus '"
);
$ocsStatusMessage = $this -> ocsContext -> getOCSResponseStatusMessage ( $this -> getResponse ());
if ( $this -> getOcsApiVersion () === 1 ) {
$expectedOcsStatusCode = "100" ;
} else {
$expectedOcsStatusCode = "200" ;
}
$this -> ocsContext -> theOCSStatusCodeShouldBe (
$expectedOcsStatusCode ,
"Request to expire last share failed: ' $ocsStatusMessage '"
);
}
/**
* @Given the administrator has expired the last created public link share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorHasExpiredTheLastCreatedPublicLinkShare () : void {
$this -> expireLastCreatedPublicLinkShare ();
$httpStatus = $this -> getResponse () -> getStatusCode ();
Assert :: assertSame (
200 ,
$this -> getResponse () -> getStatusCode (),
"Request to expire last public link share failed. HTTP status was ' $httpStatus '"
);
$ocsStatusMessage = $this -> ocsContext -> getOCSResponseStatusMessage ( $this -> getResponse ());
if ( $this -> getOcsApiVersion () === 1 ) {
$expectedOcsStatusCode = "100" ;
} else {
$expectedOcsStatusCode = "200" ;
}
$this -> ocsContext -> theOCSStatusCodeShouldBe (
$expectedOcsStatusCode ,
"Request to expire last public link share failed: ' $ocsStatusMessage '"
);
}
/**
* @When the administrator expires the last created share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorExpiresTheLastCreatedShare () : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> expireShare ());
2022-12-21 17:22:22 +05:45
}
/**
* @When the administrator expires the last created public link share using the testing API
*
* @return void
* @throws GuzzleException
*/
public function theAdministratorExpiresTheLastCreatedPublicLinkShare () : void {
2023-12-05 18:43:30 +05:45
$this -> setResponse ( $this -> expireLastCreatedPublicLinkShare ());
2022-12-21 17:22:22 +05:45
}
/**
* replace values from table
*
* @param string $field
* @param string $value
*
* @return string
*/
public function replaceValuesFromTable ( string $field , string $value ) : string {
if ( \substr ( $field , 0 , 10 ) === "share_with" ) {
$value = \str_replace (
"REMOTE" ,
$this -> getRemoteBaseUrl (),
$value
);
$value = \str_replace (
"LOCAL" ,
$this -> getLocalBaseUrl (),
$value
);
}
if ( \substr ( $field , 0 , 6 ) === "remote" ) {
$value = \str_replace (
"REMOTE" ,
$this -> getRemoteBaseUrl (),
$value
);
$value = \str_replace (
"LOCAL" ,
$this -> getLocalBaseUrl (),
$value
);
}
if ( $field === "permissions" ) {
if ( \is_string ( $value ) && ! \is_numeric ( $value )) {
$value = $this -> splitPermissionsString ( $value );
}
$value = ( string ) SharingHelper :: getPermissionSum ( $value );
}
if ( $field === "share_type" ) {
$value = ( string ) SharingHelper :: getShareType ( $value );
}
return $value ;
}
/**
* @return array of common sharing capability settings for testing
*/
protected function getCommonSharingConfigs () : array {
return [
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'auto_accept_share' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_auto_accept_share' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'api_enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_enabled' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_links' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@upload' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_public_upload' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'group_sharing' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_group_sharing' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'share_with_group_members_only' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_only_share_with_group_members' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'share_with_membership_groups_only' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_only_share_with_membership_groups' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'exclude_groups_from_sharing' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_exclude_groups' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'exclude_groups_from_sharing_list' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_exclude_groups_list' ,
'testingState' => ''
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' =>
'user_enumeration@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' =>
'shareapi_allow_share_dialog_user_enumeration' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' =>
'user_enumeration@@@group_members_only' ,
'testingApp' => 'core' ,
'testingParameter' =>
'shareapi_share_dialog_user_enumeration_group_members' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'resharing' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_resharing' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@read_only' ,
'testingApp' => 'core' ,
'testingParameter' =>
'shareapi_enforce_links_password_read_only' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@read_write' ,
'testingApp' => 'core' ,
'testingParameter' =>
'shareapi_enforce_links_password_read_write' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@upload_only' ,
'testingApp' => 'core' ,
'testingParameter' =>
'shareapi_enforce_links_password_write_only' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@send_mail' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_public_notification' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@social_share' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_social_share' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@expire_date@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_default_expire_date' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'public@@@expire_date@@@enforced' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_enforce_expire_date' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'user@@@send_mail' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_allow_mail_notification' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'user@@@expire_date@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_default_expire_date_user_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'user@@@expire_date@@@enforced' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_enforce_expire_date_user_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'group@@@expire_date@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_default_expire_date_group_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'group@@@expire_date@@@enforced' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_enforce_expire_date_group_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'remote@@@expire_date@@@enabled' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_default_expire_date_remote_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'remote@@@expire_date@@@enforced' ,
'testingApp' => 'core' ,
'testingParameter' => 'shareapi_enforce_expire_date_remote_share' ,
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'federation@@@outgoing' ,
'testingApp' => 'files_sharing' ,
'testingParameter' => 'outgoing_server2server_share_enabled' ,
'testingState' => true
],
[
'capabilitiesApp' => 'files_sharing' ,
'capabilitiesParameter' => 'federation@@@incoming' ,
'testingApp' => 'files_sharing' ,
'testingParameter' => 'incoming_server2server_share_enabled' ,
'testingState' => true
]
];
}
}