2015-03-17 11:51:07 -04:00
< ? php
2025-06-30 09:04:05 -04:00
2015-03-17 11:51:07 -04:00
/**
2024-06-06 13:48:28 -04:00
* SPDX - FileCopyrightText : 2016 - 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX - FileCopyrightText : 2016 ownCloud , Inc .
* SPDX - License - Identifier : AGPL - 3.0 - only
2015-03-17 11:51:07 -04:00
*/
namespace OCA\Files_Sharing\Tests\External ;
2017-01-27 06:52:17 -05:00
use OC\Federation\CloudIdManager ;
2023-06-28 09:48:55 -04:00
use OC\Files\Mount\MountPoint ;
2022-03-02 13:38:21 -05:00
use OC\Files\SetupManagerFactory ;
2015-03-24 12:26:38 -04:00
use OC\Files\Storage\StorageFactory ;
2023-06-28 09:48:55 -04:00
use OC\Files\Storage\Temporary ;
2025-10-29 11:50:50 -04:00
use OCA\Files_Sharing\External\ExternalShare ;
use OCA\Files_Sharing\External\ExternalShareMapper ;
2015-04-27 11:14:52 -04:00
use OCA\Files_Sharing\External\Manager ;
2015-10-05 10:43:10 -04:00
use OCA\Files_Sharing\External\MountProvider ;
2015-03-17 11:51:07 -04:00
use OCA\Files_Sharing\Tests\TestCase ;
2020-11-16 11:56:44 -05:00
use OCP\Contacts\IManager ;
2020-07-13 09:43:42 -04:00
use OCP\EventDispatcher\IEventDispatcher ;
2018-06-12 10:20:53 -04:00
use OCP\Federation\ICloudFederationFactory ;
use OCP\Federation\ICloudFederationProviderManager ;
2025-09-27 18:38:34 -04:00
use OCP\Files\Folder ;
use OCP\Files\IRootFolder ;
2026-01-26 16:09:40 -05:00
use OCP\Files\ISetupManager ;
2022-02-23 12:29:08 -05:00
use OCP\Files\NotFoundException ;
2025-03-27 18:23:56 -04:00
use OCP\Http\Client\IClient ;
2016-08-23 04:16:33 -04:00
use OCP\Http\Client\IClientService ;
2019-11-22 07:23:56 -05:00
use OCP\Http\Client\IResponse ;
2022-08-30 12:15:02 -04:00
use OCP\ICacheFactory ;
2025-10-01 04:40:50 -04:00
use OCP\ICertificateManager ;
2025-02-03 09:34:01 -05:00
use OCP\IDBConnection ;
2021-07-02 03:58:54 -04:00
use OCP\IGroup ;
2018-07-04 04:39:13 -04:00
use OCP\IGroupManager ;
2021-07-09 02:00:03 -04:00
use OCP\IURLGenerator ;
2021-08-12 07:31:29 -04:00
use OCP\IUser ;
2018-07-04 04:39:13 -04:00
use OCP\IUserManager ;
2021-08-12 07:31:29 -04:00
use OCP\IUserSession ;
2024-10-10 06:40:31 -04:00
use OCP\OCS\IDiscoveryService ;
2025-02-03 09:34:01 -05:00
use OCP\Server ;
2020-06-24 10:49:16 -04:00
use OCP\Share\IShare ;
2025-05-31 13:00:01 -04:00
use PHPUnit\Framework\MockObject\MockObject ;
2021-07-20 14:36:26 -04:00
use Psr\Log\LoggerInterface ;
2015-10-05 10:18:14 -04:00
use Test\Traits\UserTrait ;
2015-03-17 11:51:07 -04:00
2015-11-02 19:52:41 -05:00
/**
* Class ManagerTest
*
*
* @ package OCA\Files_Sharing\Tests\External
*/
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
2015-03-17 11:51:07 -04:00
class ManagerTest extends TestCase {
2015-10-05 10:18:14 -04:00
use UserTrait ;
2015-03-17 11:51:07 -04:00
2025-05-31 13:00:01 -04:00
protected IUser $user ;
2025-09-27 18:38:34 -04:00
protected IGroup & MockObject $group1 ;
protected IGroup & MockObject $group2 ;
2025-05-31 13:00:01 -04:00
protected MountProvider $testMountProvider ;
protected IEventDispatcher & MockObject $eventDispatcher ;
protected LoggerInterface & MockObject $logger ;
protected \OC\Files\Mount\Manager $mountManager ;
protected IManager & MockObject $contactsManager ;
protected Manager & MockObject $manager ;
protected IClientService & MockObject $clientService ;
protected ICloudFederationProviderManager & MockObject $cloudFederationProviderManager ;
protected ICloudFederationFactory & MockObject $cloudFederationFactory ;
protected IGroupManager & MockObject $groupManager ;
protected IUserManager & MockObject $userManager ;
2026-01-26 16:09:40 -05:00
protected ISetupManager & MockObject $setupManager ;
2025-10-01 04:40:50 -04:00
protected ICertificateManager & MockObject $certificateManager ;
2025-10-29 11:50:50 -04:00
private ExternalShareMapper $externalShareMapper ;
2015-10-05 10:18:14 -04:00
2019-11-21 10:40:38 -05:00
protected function setUp () : void {
2015-03-17 11:51:07 -04:00
parent :: setUp ();
2025-09-27 18:38:34 -04:00
$this -> user = $this -> createUser ( $this -> getUniqueID ( 'user' ), '' );
2022-03-02 13:38:21 -05:00
$this -> mountManager = new \OC\Files\Mount\Manager ( $this -> createMock ( SetupManagerFactory :: class ));
2017-10-24 09:26:53 -04:00
$this -> clientService = $this -> getMockBuilder ( IClientService :: class )
2016-08-23 04:16:33 -04:00
-> disableOriginalConstructor () -> getMock ();
2018-06-12 10:20:53 -04:00
$this -> cloudFederationProviderManager = $this -> createMock ( ICloudFederationProviderManager :: class );
$this -> cloudFederationFactory = $this -> createMock ( ICloudFederationFactory :: class );
2018-07-04 04:39:13 -04:00
$this -> groupManager = $this -> createMock ( IGroupManager :: class );
$this -> userManager = $this -> createMock ( IUserManager :: class );
2020-07-13 09:43:42 -04:00
$this -> eventDispatcher = $this -> createMock ( IEventDispatcher :: class );
2026-01-26 16:09:40 -05:00
$this -> setupManager = $this -> createMock ( ISetupManager :: class );
2025-09-27 18:38:34 -04:00
$this -> rootFolder = $this -> createMock ( IRootFolder :: class );
$this -> rootFolder -> method ( 'getUserFolder' )
-> willReturnCallback ( function ( string $userId ) : Folder {
$folder = $this -> createMock ( Folder :: class );
$folder -> method ( 'get' )
-> willReturn ( $folder );
$folder -> method ( 'getNonExistingName' )
-> willReturnCallback ( fn ( string $name ) : string => $name );
return $folder ;
});
2018-06-12 10:20:53 -04:00
2025-10-29 11:50:50 -04:00
$this -> externalShareMapper = new ExternalShareMapper ( Server :: get ( IDBConnection :: class ), $this -> groupManager );
2020-11-16 11:56:44 -05:00
$this -> contactsManager = $this -> createMock ( IManager :: class );
// needed for MountProvider() initialization
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2025-10-01 04:40:50 -04:00
$this -> certificateManager = $this -> createMock ( ICertificateManager :: class );
2021-07-27 08:32:51 -04:00
$this -> logger = $this -> createMock ( LoggerInterface :: class );
$this -> logger -> expects ( $this -> never ()) -> method ( 'emergency' );
2021-07-05 10:07:02 -04:00
2025-09-27 18:38:34 -04:00
$this -> manager = $this -> createManagerForUser ( $this -> user );
2017-03-10 09:37:21 -05:00
2025-02-03 09:34:01 -05:00
$this -> testMountProvider = new MountProvider ( Server :: get ( IDBConnection :: class ), function () {
2015-10-05 10:43:10 -04:00
return $this -> manager ;
2022-08-30 12:15:02 -04:00
}, new CloudIdManager (
2025-07-21 09:51:58 -04:00
$this -> createMock ( ICacheFactory :: class ),
$this -> createMock ( IEventDispatcher :: class ),
2022-08-30 12:15:02 -04:00
$this -> contactsManager ,
$this -> createMock ( IURLGenerator :: class ),
$this -> userManager ,
));
2021-07-02 03:58:54 -04:00
2025-09-27 18:38:34 -04:00
$this -> group1 = $this -> createMock ( IGroup :: class );
$this -> group1 -> expects ( $this -> any ()) -> method ( 'getGID' ) -> willReturn ( 'group1' );
$this -> group1 -> expects ( $this -> any ()) -> method ( 'inGroup' ) -> with ( $this -> user ) -> willReturn ( true );
2021-07-02 03:58:54 -04:00
2025-09-27 18:38:34 -04:00
$this -> group2 = $this -> createMock ( IGroup :: class );
$this -> group2 -> expects ( $this -> any ()) -> method ( 'getGID' ) -> willReturn ( 'group2' );
$this -> group2 -> expects ( $this -> any ()) -> method ( 'inGroup' ) -> with ( $this -> user ) -> willReturn ( true );
2021-07-13 11:51:52 -04:00
2021-07-02 03:58:54 -04:00
$this -> userManager -> expects ( $this -> any ()) -> method ( 'get' ) -> willReturn ( $this -> user );
2025-09-27 18:38:34 -04:00
$this -> groupManager -> expects ( $this -> any ()) -> method (( 'getUserGroups' )) -> willReturn ([ $this -> group1 , $this -> group2 ]);
2021-07-13 11:51:52 -04:00
$this -> groupManager -> expects ( $this -> any ()) -> method (( 'get' ))
2025-06-30 10:56:59 -04:00
-> willReturnMap ([
2025-09-27 18:38:34 -04:00
[ 'group1' , $this -> group1 ],
[ 'group2' , $this -> group2 ],
2025-06-30 10:56:59 -04:00
]);
2021-07-02 03:58:54 -04:00
}
protected function tearDown () : void {
// clear the share external table to avoid side effects
2025-09-12 11:17:17 -04:00
Server :: get ( IDBConnection :: class ) -> getQueryBuilder () -> delete ( 'share_external' ) -> executeStatement ();
2021-07-02 03:58:54 -04:00
parent :: tearDown ();
2015-03-17 11:51:07 -04:00
}
2025-09-27 18:38:34 -04:00
private function createManagerForUser ( IUser $user ) : Manager & MockObject {
2021-08-12 07:31:29 -04:00
$userSession = $this -> createMock ( IUserSession :: class );
$userSession -> method ( 'getUser' )
-> willReturn ( $user );
2021-07-27 08:32:51 -04:00
return $this -> getMockBuilder ( Manager :: class )
-> setConstructorArgs (
[
2025-02-03 09:34:01 -05:00
Server :: get ( IDBConnection :: class ),
2021-07-27 08:32:51 -04:00
$this -> mountManager ,
new StorageFactory (),
$this -> clientService ,
2025-02-03 09:34:01 -05:00
Server :: get ( \OCP\Notification\IManager :: class ),
Server :: get ( IDiscoveryService :: class ),
2021-07-27 08:32:51 -04:00
$this -> cloudFederationProviderManager ,
$this -> cloudFederationFactory ,
$this -> groupManager ,
2021-08-12 07:31:29 -04:00
$userSession ,
2021-07-27 08:32:51 -04:00
$this -> eventDispatcher ,
$this -> logger ,
2025-09-27 18:38:34 -04:00
$this -> rootFolder ,
$this -> setupManager ,
2025-10-01 04:40:50 -04:00
$this -> certificateManager ,
2025-10-29 11:50:50 -04:00
$this -> externalShareMapper ,
2021-07-27 08:32:51 -04:00
]
2025-05-31 13:00:01 -04:00
) -> onlyMethods ([ 'tryOCMEndPoint' ]) -> getMock ();
2021-07-27 08:32:51 -04:00
}
2025-09-27 18:38:34 -04:00
private function setupMounts () : void {
2023-06-28 09:48:55 -04:00
$this -> clearMounts ();
2016-09-20 09:27:40 -04:00
$mounts = $this -> testMountProvider -> getMountsForUser ( $this -> user , new StorageFactory ());
2015-10-05 10:18:14 -04:00
foreach ( $mounts as $mount ) {
$this -> mountManager -> addMount ( $mount );
}
}
2025-09-27 18:38:34 -04:00
private function clearMounts () : void {
2023-06-28 09:48:55 -04:00
$this -> mountManager -> clear ();
$this -> mountManager -> addMount ( new MountPoint ( Temporary :: class , '' , []));
}
2021-07-02 03:58:54 -04:00
public function testAddUserShare () : void {
2025-10-29 11:50:50 -04:00
$userShare = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$userShare -> generateId ();
2025-10-29 11:50:50 -04:00
$userShare -> setRemote ( 'http://localhost' );
$userShare -> setShareToken ( 'token1' );
$userShare -> setPassword ( '' );
$userShare -> setName ( '/SharedFolder' );
$userShare -> setOwner ( 'foobar' );
$userShare -> setShareType ( IShare :: TYPE_USER );
$userShare -> setAccepted ( IShare :: STATUS_PENDING );
$userShare -> setRemoteId ( '2342' );
$this -> doTestAddShare ( $userShare , $this -> user );
2021-07-02 03:58:54 -04:00
}
public function testAddGroupShare () : void {
2025-10-29 11:50:50 -04:00
$groupShare = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$groupShare -> generateId ();
2025-10-29 11:50:50 -04:00
$groupShare -> setRemote ( 'http://localhost' );
$groupShare -> setOwner ( 'foobar' );
$groupShare -> setShareType ( IShare :: TYPE_GROUP );
$groupShare -> setAccepted ( IShare :: STATUS_PENDING );
$groupShare -> setRemoteId ( '2342' );
$groupShare -> setShareToken ( 'token1' );
$groupShare -> setPassword ( '' );
$groupShare -> setName ( '/SharedFolder' );
$this -> doTestAddShare ( $groupShare , $this -> group1 , isGroup : true );
2021-07-02 03:58:54 -04:00
}
2025-10-29 11:50:50 -04:00
public function doTestAddShare ( ExternalShare $shareData1 , IUser | IGroup $userOrGroup , bool $isGroup = false ) : void {
2021-07-02 03:58:54 -04:00
if ( $isGroup ) {
2025-09-27 18:38:34 -04:00
$this -> manager -> expects ( $this -> never ()) -> method ( 'tryOCMEndPoint' ) -> willReturn ( false );
2021-07-02 03:58:54 -04:00
} else {
2025-05-31 13:00:01 -04:00
$this -> manager -> expects ( self :: atLeast ( 2 ))
-> method ( 'tryOCMEndPoint' )
-> willReturnMap ([
[ 'http://localhost' , 'token1' , '2342' , 'accept' , false ],
[ 'http://localhost' , 'token3' , '2342' , 'decline' , false ],
]);
2021-07-02 03:58:54 -04:00
}
2018-06-12 10:20:53 -04:00
2015-03-17 11:51:07 -04:00
// Add a share for "user"
2025-10-29 11:50:50 -04:00
$this -> assertSame ( null , call_user_func_array ([ $this -> manager , 'addShare' ], [ $shareData1 , $userOrGroup ]));
2015-03-17 11:51:07 -04:00
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 1 , $openShares );
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData1 , $openShares [ 0 ], 1 , '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' , $userOrGroup );
$shareData2 = $shareData1 -> clone ();
$shareData2 -> setShareToken ( 'token2' );
2026-01-05 15:37:23 -05:00
$shareData2 -> generateId ();
2025-10-29 11:50:50 -04:00
$shareData3 = $shareData1 -> clone ();
$shareData3 -> setShareToken ( 'token3' );
2026-01-05 15:37:23 -05:00
$shareData3 -> generateId ();
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2015-03-24 12:26:38 -04:00
$this -> assertNotMount ( 'SharedFolder' );
2025-10-29 11:50:50 -04:00
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
2015-03-24 12:26:38 -04:00
2015-03-17 11:51:07 -04:00
// Add a second share for "user" with the same name
2025-10-29 11:50:50 -04:00
$this -> assertSame ( null , call_user_func_array ([ $this -> manager , 'addShare' ], [ $shareData2 , $userOrGroup ]));
2015-03-17 11:51:07 -04:00
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 2 , $openShares );
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData1 , $openShares [ 0 ], 1 , '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' , $userOrGroup );
2015-03-17 11:51:07 -04:00
// New share falls back to "-1" appendix, because the name is already taken
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData2 , $openShares [ 1 ], 2 , '{{TemporaryMountPointName#' . $shareData2 -> getName () . '}}-1' , $userOrGroup );
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2015-03-24 12:26:38 -04:00
$this -> assertNotMount ( 'SharedFolder' );
2025-10-29 11:50:50 -04:00
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-24 12:26:38 -04:00
2025-03-27 18:23:56 -04:00
$newClientCalls = [];
$this -> clientService
-> method ( 'newClient' )
-> willReturnCallback ( function () use ( & $newClientCalls ) : IClient {
if ( ! empty ( $newClientCalls )) {
return array_shift ( $newClientCalls );
}
return $this -> createMock ( IClient :: class );
});
2021-07-02 03:58:54 -04:00
if ( ! $isGroup ) {
2025-03-27 18:23:56 -04:00
$client = $this -> createMock ( IClient :: class );
$newClientCalls [] = $client ;
2021-07-02 03:58:54 -04:00
$response = $this -> createMock ( IResponse :: class );
$response -> method ( 'getBody' )
-> willReturn ( json_encode ([
'ocs' => [
'meta' => [
'statuscode' => 200 ,
]
2019-11-22 07:23:56 -05:00
]
2021-07-02 03:58:54 -04:00
]));
$client -> expects ( $this -> once ())
-> method ( 'post' )
2025-10-29 11:50:50 -04:00
-> with ( $this -> stringStartsWith ( 'http://localhost/ocs/v2.php/cloud/shares/' . $openShares [ 0 ] -> getRemoteId ()), $this -> anything ())
2021-07-02 03:58:54 -04:00
-> willReturn ( $response );
}
2015-04-28 08:56:13 -04:00
2015-03-17 11:51:07 -04:00
// Accept the first share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $openShares [ 0 ]));
2015-03-17 11:51:07 -04:00
// Check remaining shares - Accepted
2025-10-29 11:50:50 -04:00
$acceptedShares = $this -> externalShareMapper -> getShares ( $this -> user , IShare :: STATUS_ACCEPTED );
2015-03-17 11:51:07 -04:00
$this -> assertCount ( 1 , $acceptedShares );
2025-10-29 11:50:50 -04:00
$shareData1 -> setAccepted ( true );
$this -> assertExternalShareEntry ( $shareData1 , $acceptedShares [ 0 ], 1 , $shareData1 -> getName (), $this -> user );
2015-03-17 11:51:07 -04:00
// Check remaining shares - Open
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 1 , $openShares );
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData2 , $openShares [ 0 ], 2 , '{{TemporaryMountPointName#' . $shareData2 -> getName () . '}}-1' , $userOrGroup );
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertMount ( $shareData1 -> getName ());
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-24 12:26:38 -04:00
2015-03-17 11:51:07 -04:00
// Add another share for "user" with the same name
2025-10-29 11:50:50 -04:00
$this -> assertSame ( null , call_user_func_array ([ $this -> manager , 'addShare' ], [ $shareData3 , $userOrGroup ]));
2015-03-17 11:51:07 -04:00
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 2 , $openShares );
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData2 , $openShares [ 0 ], 2 , '{{TemporaryMountPointName#' . $shareData2 -> getName () . '}}-1' , $userOrGroup );
2021-07-02 03:58:54 -04:00
if ( ! $isGroup ) {
// New share falls back to the original name (no "-\d", because the name is not taken)
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData3 , $openShares [ 1 ], 3 , '{{TemporaryMountPointName#' . $shareData3 -> getName () . '}}' , $userOrGroup );
2021-07-02 03:58:54 -04:00
} else {
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData3 , $openShares [ 1 ], 3 , '{{TemporaryMountPointName#' . $shareData3 -> getName () . '}}-2' , $userOrGroup );
2021-07-02 03:58:54 -04:00
}
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertMount ( $shareData1 -> getName ());
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-24 12:26:38 -04:00
2021-07-02 03:58:54 -04:00
if ( ! $isGroup ) {
2025-03-27 18:23:56 -04:00
$client = $this -> createMock ( IClient :: class );
$newClientCalls [] = $client ;
2021-07-02 03:58:54 -04:00
$response = $this -> createMock ( IResponse :: class );
$response -> method ( 'getBody' )
-> willReturn ( json_encode ([
'ocs' => [
'meta' => [
'statuscode' => 200 ,
]
2019-11-22 07:23:56 -05:00
]
2021-07-02 03:58:54 -04:00
]));
$client -> expects ( $this -> once ())
-> method ( 'post' )
2025-10-29 11:50:50 -04:00
-> with ( $this -> stringStartsWith ( 'http://localhost/ocs/v2.php/cloud/shares/' . $openShares [ 1 ] -> getRemoteId () . '/decline' ), $this -> anything ())
2021-07-02 03:58:54 -04:00
-> willReturn ( $response );
}
2015-04-28 08:56:13 -04:00
2015-03-17 11:51:07 -04:00
// Decline the third share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $openShares [ 1 ]));
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertMount ( $shareData1 -> getName ());
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-24 12:26:38 -04:00
2015-03-17 11:51:07 -04:00
// Check remaining shares - Accepted
2025-10-29 11:50:50 -04:00
$acceptedShares = $this -> externalShareMapper -> getShares ( $this -> user , IShare :: STATUS_ACCEPTED );
2015-03-17 11:51:07 -04:00
$this -> assertCount ( 1 , $acceptedShares );
2025-10-29 11:50:50 -04:00
$shareData1 -> setAccepted ( true );
$this -> assertExternalShareEntry ( $shareData1 , $acceptedShares [ 0 ], 1 , $shareData1 -> getName (), $this -> user );
2015-03-17 11:51:07 -04:00
// Check remaining shares - Open
$openShares = $this -> manager -> getOpenShares ();
2021-07-02 03:58:54 -04:00
if ( $isGroup ) {
// declining a group share adds it back to pending instead of deleting it
$this -> assertCount ( 2 , $openShares );
// this is a group share that is still open
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData2 , $openShares [ 0 ], 2 , '{{TemporaryMountPointName#' . $shareData2 -> getName () . '}}-1' , $userOrGroup );
2021-07-02 03:58:54 -04:00
// this is the user share sub-entry matching the group share which got declined
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData3 , $openShares [ 1 ], 2 , '{{TemporaryMountPointName#' . $shareData3 -> getName () . '}}-2' , $this -> user );
2021-07-02 03:58:54 -04:00
} else {
$this -> assertCount ( 1 , $openShares );
2025-10-29 11:50:50 -04:00
$this -> assertExternalShareEntry ( $shareData2 , $openShares [ 0 ], 2 , '{{TemporaryMountPointName#' . $shareData2 -> getName () . '}}-1' , $this -> user );
2021-07-02 03:58:54 -04:00
}
2015-03-17 11:51:07 -04:00
2015-10-05 10:18:14 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertMount ( $shareData1 -> getName ());
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-24 12:26:38 -04:00
2021-07-02 03:58:54 -04:00
if ( $isGroup ) {
// no http requests here
2025-10-29 11:50:50 -04:00
$this -> manager -> removeGroupShares ( $this -> group1 );
2021-07-02 03:58:54 -04:00
} else {
2025-03-27 18:23:56 -04:00
$client1 = $this -> createMock ( IClient :: class );
$client2 = $this -> createMock ( IClient :: class );
$newClientCalls [] = $client1 ;
$newClientCalls [] = $client2 ;
2021-07-02 03:58:54 -04:00
$response = $this -> createMock ( IResponse :: class );
$response -> method ( 'getBody' )
-> willReturn ( json_encode ([
'ocs' => [
'meta' => [
'statuscode' => 200 ,
]
2019-11-22 07:23:56 -05:00
]
2021-07-02 03:58:54 -04:00
]));
$client1 -> expects ( $this -> once ())
-> method ( 'post' )
2025-10-29 11:50:50 -04:00
-> with ( $this -> stringStartsWith ( 'http://localhost/ocs/v2.php/cloud/shares/' . $openShares [ 0 ] -> getRemoteId () . '/decline' ), $this -> anything ())
2021-07-02 03:58:54 -04:00
-> willReturn ( $response );
$client2 -> expects ( $this -> once ())
-> method ( 'post' )
2025-10-29 11:50:50 -04:00
-> with ( $this -> stringStartsWith ( 'http://localhost/ocs/v2.php/cloud/shares/' . $acceptedShares [ 0 ] -> getRemoteId () . '/decline' ), $this -> anything ())
2021-07-02 03:58:54 -04:00
-> willReturn ( $response );
2025-09-27 18:38:34 -04:00
$this -> manager -> removeUserShares ( $this -> user );
2021-07-02 03:58:54 -04:00
}
2025-10-29 11:50:50 -04:00
$this -> assertEmpty ( $this -> externalShareMapper -> getShares ( $this -> user , null ), 'Asserting all shares for the user have been deleted' );
2015-03-24 12:26:38 -04:00
2023-06-28 09:48:55 -04:00
$this -> clearMounts ();
2015-06-03 06:03:02 -04:00
self :: invokePrivate ( $this -> manager , 'setupMounts' );
2025-10-29 11:50:50 -04:00
$this -> assertNotMount ( $shareData1 -> getName ());
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}' );
$this -> assertNotMount ( '{{TemporaryMountPointName#' . $shareData1 -> getName () . '}}-1' );
2015-03-17 11:51:07 -04:00
}
2025-10-29 11:50:50 -04:00
private function verifyAcceptedGroupShare ( ExternalShare $share ) : void {
2021-07-05 10:07:02 -04:00
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 0 , $openShares );
2025-10-29 11:50:50 -04:00
$acceptedShares = $this -> externalShareMapper -> getShares ( $this -> user , IShare :: STATUS_ACCEPTED );
2021-07-05 10:07:02 -04:00
$this -> assertCount ( 1 , $acceptedShares );
2025-10-29 11:50:50 -04:00
$share -> setAccepted ( IShare :: STATUS_ACCEPTED );
$this -> assertExternalShareEntry ( $share , $acceptedShares [ 0 ], 0 , $share -> getName (), $this -> user );
2021-07-05 10:07:02 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertMount ( $share -> getName ());
2021-07-05 10:07:02 -04:00
}
2025-10-29 11:50:50 -04:00
private function verifyDeclinedGroupShare ( ExternalShare $share , ? string $tempMount = null ) : void {
2021-07-05 10:07:02 -04:00
if ( $tempMount === null ) {
$tempMount = '{{TemporaryMountPointName#/SharedFolder}}' ;
}
$openShares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 1 , $openShares );
2025-10-29 11:50:50 -04:00
$acceptedShares = $this -> externalShareMapper -> getShares ( $this -> user , IShare :: STATUS_ACCEPTED );
2021-07-05 10:07:02 -04:00
$this -> assertCount ( 0 , $acceptedShares );
2025-10-29 11:50:50 -04:00
$share -> setAccepted ( IShare :: STATUS_PENDING );
$this -> assertExternalShareEntry ( $share , $openShares [ 0 ], 0 , $tempMount , $this -> user );
2021-07-05 10:07:02 -04:00
$this -> setupMounts ();
2025-10-29 11:50:50 -04:00
$this -> assertNotMount ( $share -> getName ());
2021-07-05 10:07:02 -04:00
$this -> assertNotMount ( $tempMount );
}
2025-10-29 11:50:50 -04:00
private function createTestUserShare ( string $userId = 'user1' ) : ExternalShare {
2025-09-27 18:38:34 -04:00
$user = $this -> createMock ( IUser :: class );
$user -> expects ( $this -> any ()) -> method ( 'getUID' ) -> willReturn ( $userId );
2025-10-29 11:50:50 -04:00
$share = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$share -> generateId ();
2025-10-29 11:50:50 -04:00
$share -> setRemote ( 'http://localhost' );
$share -> setShareToken ( 'token1' );
$share -> setPassword ( '' );
$share -> setName ( '/SharedFolder' );
$share -> setOwner ( 'foobar' );
$share -> setShareType ( IShare :: TYPE_USER );
$share -> setAccepted ( IShare :: STATUS_PENDING );
$share -> setRemoteId ( '2346' );
$this -> assertSame ( null , call_user_func_array ([ $this -> manager , 'addShare' ], [ $share , $user ]));
return $share ;
2021-07-27 08:32:51 -04:00
}
2025-10-29 11:50:50 -04:00
/**
* @ return array { 0 : ExternalShare , 1 : ExternalShare }
*/
2025-09-27 18:38:34 -04:00
private function createTestGroupShare ( string $groupId = 'group1' ) : array {
2025-10-29 11:50:50 -04:00
$share = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$share -> generateId ();
2025-10-29 11:50:50 -04:00
$share -> setRemote ( 'http://localhost' );
$share -> setShareToken ( 'token1' );
$share -> setPassword ( '' );
$share -> setName ( '/SharedFolder' );
$share -> setOwner ( 'foobar' );
$share -> setShareType ( IShare :: TYPE_GROUP );
$share -> setAccepted ( IShare :: STATUS_PENDING );
$share -> setRemoteId ( '2342' );
$this -> assertSame ( null , call_user_func_array ([ $this -> manager , 'addShare' ], [ $share , $groupId === 'group1' ? $this -> group1 : $this -> group2 ]));
$allShares = $this -> externalShareMapper -> getShares ( $this -> user , null );
$groupShare = null ;
2021-07-27 08:32:51 -04:00
foreach ( $allShares as $share ) {
2025-10-29 11:50:50 -04:00
if ( $share -> getUser () === $groupId ) {
2021-07-27 08:32:51 -04:00
// this will hold the main group entry
$groupShare = $share ;
break ;
}
}
2021-07-05 10:07:02 -04:00
2025-10-29 11:50:50 -04:00
$this -> assertEquals ( $share -> getId (), $groupShare -> getId ());
return [ $share , $groupShare ];
2021-07-05 10:07:02 -04:00
}
public function testAcceptOriginalGroupShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
}
public function testAcceptGroupShareAgainThroughGroupShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// decline again, this keeps the sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
// this will return sub-entries
$openShares = $this -> manager -> getOpenShares ();
2021-07-27 08:32:51 -04:00
$this -> assertCount ( 1 , $openShares );
2021-07-05 10:07:02 -04:00
2021-07-27 08:32:51 -04:00
// accept through group share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData , '/SharedFolder' );
// accept a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData , '/SharedFolder' );
}
public function testAcceptGroupShareAgainThroughSubShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// decline again, this keeps the sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
// this will return sub-entries
$openShares = $this -> manager -> getOpenShares ();
2021-07-27 08:32:51 -04:00
$this -> assertCount ( 1 , $openShares );
2021-07-05 10:07:02 -04:00
// accept through sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $openShares [ 0 ]));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// accept a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $openShares [ 0 ]));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
}
public function testDeclineOriginalGroupShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData );
// a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData );
}
public function testDeclineGroupShareAgainThroughGroupShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// decline again, this keeps the sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
// a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
}
public function testDeclineGroupShareAgainThroughSubshare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// this will return sub-entries
2025-10-29 11:50:50 -04:00
$allShares = $this -> externalShareMapper -> getShares ( $this -> user , null );
2021-07-05 10:07:02 -04:00
$this -> assertCount ( 1 , $allShares );
// decline again through sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $allShares [ 0 ]));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
// a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $allShares [ 0 ]));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
}
public function testDeclineGroupShareAgainThroughMountPoint () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-05 10:07:02 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// decline through mount point name
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> removeShare ( $this -> user -> getUID () . '/files/' . $shareData -> getName ()));
2021-07-05 10:07:02 -04:00
$this -> verifyDeclinedGroupShare ( $shareData , '/SharedFolder' );
// second time must fail as the mount point is gone
2025-10-29 11:50:50 -04:00
$this -> assertFalse ( $this -> manager -> removeShare ( $this -> user -> getUID () . '/files/' . $shareData -> getName ()));
2021-07-05 10:07:02 -04:00
}
2021-07-20 10:42:19 -04:00
public function testDeclineThenAcceptGroupShareAgainThroughGroupShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
// decline, this creates a declined sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-20 10:42:19 -04:00
$this -> verifyDeclinedGroupShare ( $shareData );
// accept through sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-20 10:42:19 -04:00
$this -> verifyAcceptedGroupShare ( $shareData , '/SharedFolder' );
// accept a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-20 10:42:19 -04:00
$this -> verifyAcceptedGroupShare ( $shareData , '/SharedFolder' );
}
public function testDeclineThenAcceptGroupShareAgainThroughSubShare () : void {
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
// decline, this creates a declined sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> declineShare ( $groupShare ));
2021-07-20 10:42:19 -04:00
$this -> verifyDeclinedGroupShare ( $shareData );
// this will return sub-entries
$openShares = $this -> manager -> getOpenShares ();
// accept through sub-share
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $openShares [ 0 ]));
2021-07-20 10:42:19 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
// accept a second time
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $openShares [ 0 ]));
2021-07-20 10:42:19 -04:00
$this -> verifyAcceptedGroupShare ( $shareData );
}
2021-07-27 08:32:51 -04:00
public function testDeleteUserShares () : void {
// user 1 shares
2025-10-29 11:50:50 -04:00
$userShare = $this -> createTestUserShare ( $this -> user -> getUID ());
2021-07-27 08:32:51 -04:00
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
$shares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 2 , $shares );
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
$user2 = $this -> createMock ( IUser :: class );
$user2 -> method ( 'getUID' ) -> willReturn ( 'user2' );
2021-07-27 08:32:51 -04:00
// user 2 shares
2025-10-29 11:50:50 -04:00
$manager2 = $this -> createManagerForUser ( $user2 );
$share = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$share -> generateId ();
2025-10-29 11:50:50 -04:00
$share -> setRemote ( 'http://localhost' );
$share -> setShareToken ( 'token1' );
$share -> setPassword ( '' );
$share -> setName ( '/SharedFolder' );
$share -> setOwner ( 'foobar' );
$share -> setShareType ( IShare :: TYPE_USER );
$share -> setAccepted ( IShare :: STATUS_PENDING );
$share -> setRemoteId ( '2342' );
2021-07-27 08:32:51 -04:00
2024-12-26 08:12:33 -05:00
$this -> assertCount ( 1 , $manager2 -> getOpenShares ());
2025-10-29 11:50:50 -04:00
$this -> assertSame ( null , call_user_func_array ([ $manager2 , 'addShare' ], [ $share , $user2 ]));
2024-12-26 08:12:33 -05:00
$this -> assertCount ( 2 , $manager2 -> getOpenShares ());
2021-07-27 08:32:51 -04:00
2025-10-29 11:50:50 -04:00
$userShare = $this -> externalShareMapper -> getById ( $userShare -> getId ()); // Simpler to compare
$this -> manager -> expects ( $this -> once ()) -> method ( 'tryOCMEndPoint' ) -> with ( $userShare , 'decline' ) -> willReturn ([]);
2025-09-27 18:38:34 -04:00
$this -> manager -> removeUserShares ( $this -> user );
2021-07-27 08:32:51 -04:00
$user1Shares = $this -> manager -> getOpenShares ();
// user share is gone, group is still there
$this -> assertCount ( 1 , $user1Shares );
2025-10-29 11:50:50 -04:00
$this -> assertEquals ( $user1Shares [ 0 ] -> getShareType (), IShare :: TYPE_GROUP );
2021-07-27 08:32:51 -04:00
// user 2 shares untouched
$user2Shares = $manager2 -> getOpenShares ();
$this -> assertCount ( 2 , $user2Shares );
2025-10-29 11:50:50 -04:00
$this -> assertEquals ( $user2Shares [ 0 ] -> getShareType (), IShare :: TYPE_GROUP );
$this -> assertEquals ( $user2Shares [ 0 ] -> getUser (), 'group1' );
$this -> assertEquals ( $user2Shares [ 1 ] -> getShareType (), IShare :: TYPE_USER );
$this -> assertEquals ( $user2Shares [ 1 ] -> getUser (), 'user2' );
2021-07-27 08:32:51 -04:00
}
public function testDeleteGroupShares () : void {
2025-09-27 18:38:34 -04:00
$shareData = $this -> createTestUserShare ( $this -> user -> getUID ());
2021-07-27 08:32:51 -04:00
[ $shareData , $groupShare ] = $this -> createTestGroupShare ();
$shares = $this -> manager -> getOpenShares ();
$this -> assertCount ( 2 , $shares );
2025-10-29 11:50:50 -04:00
$this -> assertTrue ( $this -> manager -> acceptShare ( $groupShare ));
2021-07-27 08:32:51 -04:00
2025-09-27 18:38:34 -04:00
$user = $this -> createMock ( IUser :: class );
$user -> method ( 'getUID' ) -> willReturn ( 'user2' );
2021-07-27 08:32:51 -04:00
// user 2 shares
2025-09-27 18:38:34 -04:00
$manager2 = $this -> createManagerForUser ( $user );
2025-10-29 11:50:50 -04:00
$share = new ExternalShare ();
2026-01-05 15:37:23 -05:00
$share -> generateId ();
2025-10-29 11:50:50 -04:00
$share -> setRemote ( 'http://localhost' );
$share -> setShareToken ( 'token1' );
$share -> setPassword ( '' );
$share -> setName ( '/SharedFolder' );
$share -> setOwner ( 'foobar' );
$share -> setShareType ( IShare :: TYPE_USER );
$share -> setAccepted ( IShare :: STATUS_PENDING );
$share -> setRemoteId ( '2343' );
2021-07-27 08:32:51 -04:00
2024-12-26 08:12:33 -05:00
$this -> assertCount ( 1 , $manager2 -> getOpenShares ());
2025-10-29 11:50:50 -04:00
$this -> assertSame ( null , call_user_func_array ([ $manager2 , 'addShare' ], [ $share , $user ]));
2024-12-26 08:12:33 -05:00
$this -> assertCount ( 2 , $manager2 -> getOpenShares ());
2021-07-27 08:32:51 -04:00
$this -> manager -> expects ( $this -> never ()) -> method ( 'tryOCMEndPoint' );
2025-10-29 11:50:50 -04:00
$this -> manager -> removeGroupShares ( $this -> group1 );
2021-07-27 08:32:51 -04:00
$user1Shares = $this -> manager -> getOpenShares ();
// user share is gone, group is still there
$this -> assertCount ( 1 , $user1Shares );
2025-10-29 11:50:50 -04:00
$this -> assertEquals ( $user1Shares [ 0 ] -> getShareType (), IShare :: TYPE_USER );
2021-07-27 08:32:51 -04:00
// user 2 shares untouched
$user2Shares = $manager2 -> getOpenShares ();
$this -> assertCount ( 1 , $user2Shares );
2025-10-29 11:50:50 -04:00
$this -> assertEquals ( $user2Shares [ 0 ] -> getShareType (), IShare :: TYPE_USER );
$this -> assertEquals ( $user2Shares [ 0 ] -> getUser (), 'user2' );
2021-07-27 08:32:51 -04:00
}
2025-10-29 11:50:50 -04:00
protected function assertExternalShareEntry ( ExternalShare $expected , ExternalShare $actual , int $share , string $mountPoint , IUser | IGroup $targetEntity ) : void {
$this -> assertEquals ( $expected -> getRemote (), $actual -> getRemote (), 'Asserting remote of a share #' . $share );
$this -> assertEquals ( $expected -> getShareToken (), $actual -> getShareToken (), 'Asserting token of a share #' . $share );
$this -> assertEquals ( $expected -> getName (), $actual -> getName (), 'Asserting name of a share #' . $share );
$this -> assertEquals ( $expected -> getOwner (), $actual -> getOwner (), 'Asserting owner of a share #' . $share );
$this -> assertEquals ( $expected -> getAccepted (), $actual -> getAccepted (), 'Asserting accept of a share #' . $share );
$this -> assertEquals ( $targetEntity instanceof IGroup ? $targetEntity -> getGID () : $targetEntity -> getUID (), $actual -> getUser (), 'Asserting user of a share #' . $share );
$this -> assertEquals ( $mountPoint , $actual -> getMountpoint (), 'Asserting mountpoint of a share #' . $share );
2015-03-24 12:26:38 -04:00
}
2025-09-27 18:38:34 -04:00
private function assertMount ( string $mountPoint ) : void {
2015-03-24 12:26:38 -04:00
$mountPoint = rtrim ( $mountPoint , '/' );
$mount = $this -> mountManager -> find ( $this -> getFullPath ( $mountPoint ));
$this -> assertInstanceOf ( '\OCA\Files_Sharing\External\Mount' , $mount );
$this -> assertInstanceOf ( '\OCP\Files\Mount\IMountPoint' , $mount );
$this -> assertEquals ( $this -> getFullPath ( $mountPoint ), rtrim ( $mount -> getMountPoint (), '/' ));
$storage = $mount -> getStorage ();
$this -> assertInstanceOf ( '\OCA\Files_Sharing\External\Storage' , $storage );
}
2025-09-27 18:38:34 -04:00
private function assertNotMount ( string $mountPoint ) : void {
2015-03-24 12:26:38 -04:00
$mountPoint = rtrim ( $mountPoint , '/' );
2022-02-23 12:29:08 -05:00
try {
$mount = $this -> mountManager -> find ( $this -> getFullPath ( $mountPoint ));
2015-03-24 12:26:38 -04:00
$this -> assertInstanceOf ( '\OCP\Files\Mount\IMountPoint' , $mount );
$this -> assertNotEquals ( $this -> getFullPath ( $mountPoint ), rtrim ( $mount -> getMountPoint (), '/' ));
2022-02-23 12:29:08 -05:00
} catch ( NotFoundException $e ) {
2015-03-24 12:26:38 -04:00
}
}
2015-03-17 11:51:07 -04:00
2025-09-27 18:38:34 -04:00
private function getFullPath ( string $path ) : string {
return '/' . $this -> user -> getUID () . '/files' . $path ;
2015-03-17 11:51:07 -04:00
}
}