2016-02-04 10:08:35 -05:00
< ? php
2024-05-28 10:42:42 -04:00
2025-05-29 05:50:46 -04:00
declare ( strict_types = 1 );
2016-03-01 11:52:32 -05:00
/**
2024-05-28 10:42:42 -04:00
* SPDX - FileCopyrightText : 2016 - 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX - FileCopyrightText : 2016 ownCloud , Inc .
* SPDX - License - Identifier : AGPL - 3.0 - only
2016-03-01 11:52:32 -05:00
*/
2016-02-04 10:08:35 -05:00
namespace OCA\FederatedFileSharing\Tests ;
2017-01-27 06:52:17 -05:00
use OC\Federation\CloudIdManager ;
2016-02-04 10:08:35 -05:00
use OCA\FederatedFileSharing\AddressHandler ;
use OCA\FederatedFileSharing\FederatedShareProvider ;
use OCA\FederatedFileSharing\Notifications ;
use OCA\FederatedFileSharing\TokenHandler ;
2024-10-10 06:40:31 -04:00
use OCP\Constants ;
2020-11-16 11:56:44 -05:00
use OCP\Contacts\IManager as IContactsManager ;
2022-08-30 12:15:02 -04:00
use OCP\EventDispatcher\IEventDispatcher ;
2018-07-04 04:39:13 -04:00
use OCP\Federation\ICloudFederationProviderManager ;
2017-01-27 06:52:17 -05:00
use OCP\Federation\ICloudIdManager ;
2017-10-24 09:26:53 -04:00
use OCP\Files\File ;
2016-02-04 10:08:35 -05:00
use OCP\Files\IRootFolder ;
2022-08-30 12:15:02 -04:00
use OCP\ICacheFactory ;
2016-04-18 12:17:08 -04:00
use OCP\IConfig ;
2016-02-04 10:08:35 -05:00
use OCP\IDBConnection ;
use OCP\IL10N ;
2021-07-09 02:00:03 -04:00
use OCP\IURLGenerator ;
2016-05-11 14:48:27 -04:00
use OCP\IUserManager ;
2025-02-03 09:34:01 -05:00
use OCP\Server ;
2016-02-04 10:08:35 -05:00
use OCP\Share\IManager ;
2020-06-24 10:49:16 -04:00
use OCP\Share\IShare ;
2020-11-16 11:56:44 -05:00
use PHPUnit\Framework\MockObject\MockObject ;
2023-07-05 05:42:41 -04:00
use Psr\Log\LoggerInterface ;
2016-02-04 10:08:35 -05:00
/**
* Class FederatedShareProviderTest
*
* @ package OCA\FederatedFileSharing\Tests
*/
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
2016-05-04 09:26:30 -04:00
class FederatedShareProviderTest extends \Test\TestCase {
2025-05-29 05:50:46 -04:00
protected IDBConnection $connection ;
protected AddressHandler & MockObject $addressHandler ;
protected Notifications & MockObject $notifications ;
protected TokenHandler & MockObject $tokenHandler ;
protected IL10N $l ;
protected LoggerInterface $logger ;
protected IRootFolder & MockObject $rootFolder ;
protected IConfig & MockObject $config ;
protected IUserManager & MockObject $userManager ;
protected \OCP\GlobalScale\IConfig & MockObject $gsConfig ;
protected IManager $shareManager ;
protected FederatedShareProvider $provider ;
protected IContactsManager & MockObject $contactsManager ;
private ICloudIdManager $cloudIdManager ;
private ICloudFederationProviderManager & MockObject $cloudFederationProviderManager ;
2016-02-04 10:08:35 -05:00
2019-11-27 09:27:18 -05:00
protected function setUp () : void {
2016-02-04 10:08:35 -05:00
parent :: setUp ();
2025-02-03 09:34:01 -05:00
$this -> connection = Server :: get ( IDBConnection :: class );
2025-05-29 05:50:46 -04:00
$this -> notifications = $this -> createMock ( Notifications :: class );
$this -> tokenHandler = $this -> createMock ( TokenHandler :: class );
$this -> l = $this -> createMock ( IL10N :: class );
2016-02-04 10:08:35 -05:00
$this -> l -> method ( 't' )
2020-04-09 07:53:40 -04:00
-> willReturnCallback ( function ( $text , $parameters = []) {
2016-02-04 10:08:35 -05:00
return vsprintf ( $text , $parameters );
2020-03-25 17:21:27 -04:00
});
2025-05-29 05:50:46 -04:00
$this -> logger = $this -> createMock ( LoggerInterface :: class );
$this -> rootFolder = $this -> createMock ( IRootFolder :: class );
$this -> config = $this -> createMock ( IConfig :: class );
$this -> userManager = $this -> createMock ( IUserManager :: class );
2016-05-11 14:48:27 -04:00
//$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
2025-05-29 05:50:46 -04:00
$this -> addressHandler = $this -> createMock ( AddressHandler :: class );
2020-11-16 11:56:44 -05:00
$this -> contactsManager = $this -> createMock ( IContactsManager :: class );
2022-08-30 12:15:02 -04:00
$this -> cloudIdManager = 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 ,
);
2017-05-24 03:07:58 -04:00
$this -> gsConfig = $this -> createMock ( \OCP\GlobalScale\IConfig :: class );
2016-02-04 10:08:35 -05:00
2016-05-04 09:26:30 -04:00
$this -> userManager -> expects ( $this -> any ()) -> method ( 'userExists' ) -> willReturn ( true );
2018-07-04 04:39:13 -04:00
$this -> cloudFederationProviderManager = $this -> createMock ( ICloudFederationProviderManager :: class );
2016-02-04 10:08:35 -05:00
$this -> provider = new FederatedShareProvider (
$this -> connection ,
$this -> addressHandler ,
$this -> notifications ,
$this -> tokenHandler ,
$this -> l ,
2016-04-18 12:17:08 -04:00
$this -> rootFolder ,
2016-05-11 14:48:27 -04:00
$this -> config ,
2017-01-27 06:52:17 -05:00
$this -> userManager ,
2017-05-24 03:07:58 -04:00
$this -> cloudIdManager ,
2018-07-04 04:39:13 -04:00
$this -> gsConfig ,
2023-07-05 05:42:41 -04:00
$this -> cloudFederationProviderManager ,
$this -> logger ,
2016-02-04 10:08:35 -05:00
);
2025-05-29 05:50:46 -04:00
$this -> shareManager = Server :: get ( IManager :: class );
2016-02-04 10:08:35 -05:00
}
2019-11-27 09:27:18 -05:00
protected function tearDown () : void {
2025-05-29 05:50:46 -04:00
$this -> connection -> getQueryBuilder () -> delete ( 'share' ) -> executeStatement ();
2016-02-04 10:08:35 -05:00
2019-11-21 10:40:38 -05:00
parent :: tearDown ();
2016-02-04 10:08:35 -05:00
}
2025-05-29 05:50:46 -04:00
public static function dataTestCreate () : array {
2021-03-24 12:50:56 -04:00
return [
[ null , null ],
[ new \DateTime ( '2020-03-01T01:02:03' ), '2020-03-01 01:02:03' ],
];
}
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestCreate')]
2025-05-29 05:50:46 -04:00
public function testCreate ( ? \DateTime $expirationDate , ? string $expectedDataDate ) : void {
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
/** @var File&MockObject $node */
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2021-03-24 12:50:56 -04:00
-> setExpirationDate ( $expirationDate )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'generateRemoteURL' )
-> willReturn ( 'http://localhost/' );
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturn ([ 'user' , 'server.com' ]);
2016-02-04 10:08:35 -05:00
$this -> notifications -> expects ( $this -> once ())
-> method ( 'sendRemoteShare' )
-> with (
$this -> equalTo ( 'token' ),
$this -> equalTo ( 'user@server.com' ),
$this -> equalTo ( 'myFile' ),
$this -> anything (),
2016-05-04 09:26:30 -04:00
'shareOwner' ,
2024-03-25 08:20:16 -04:00
'shareOwner@http://localhost' ,
2016-05-04 09:26:30 -04:00
'sharedBy' ,
2024-03-25 08:20:16 -04:00
'sharedBy@http://localhost'
2020-11-16 11:56:44 -05:00
)
-> willReturn ( true );
2016-02-04 10:08:35 -05:00
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> provider -> create ( $share );
$qb = $this -> connection -> getQueryBuilder ();
$stmt = $qb -> select ( '*' )
-> from ( 'share' )
-> where ( $qb -> expr () -> eq ( 'id' , $qb -> createNamedParameter ( $share -> getId ())))
2025-05-29 05:50:46 -04:00
-> executeQuery ();
2016-02-04 10:08:35 -05:00
2025-11-17 06:20:11 -05:00
$data = $stmt -> fetchAssociative ();
2016-02-04 10:08:35 -05:00
$stmt -> closeCursor ();
$expected = [
2020-06-24 10:49:16 -04:00
'share_type' => IShare :: TYPE_REMOTE ,
2016-02-04 10:08:35 -05:00
'share_with' => 'user@server.com' ,
'uid_owner' => 'shareOwner' ,
'uid_initiator' => 'sharedBy' ,
'item_type' => 'file' ,
'item_source' => 42 ,
'file_source' => 42 ,
'permissions' => 19 ,
'accepted' => 0 ,
'token' => 'token' ,
2021-03-24 12:50:56 -04:00
'expiration' => $expectedDataDate ,
2016-02-04 10:08:35 -05:00
];
2020-07-23 07:39:13 -04:00
foreach ( array_keys ( $expected ) as $key ) {
$this -> assertEquals ( $expected [ $key ], $data [ $key ], " Assert that value for key ' $key ' is the same " );
}
2016-02-04 10:08:35 -05:00
$this -> assertEquals ( $data [ 'id' ], $share -> getId ());
2020-06-24 10:49:16 -04:00
$this -> assertEquals ( IShare :: TYPE_REMOTE , $share -> getShareType ());
2016-02-04 10:08:35 -05:00
$this -> assertEquals ( 'user@server.com' , $share -> getSharedWith ());
$this -> assertEquals ( 'sharedBy' , $share -> getSharedBy ());
$this -> assertEquals ( 'shareOwner' , $share -> getShareOwner ());
$this -> assertEquals ( 'file' , $share -> getNodeType ());
$this -> assertEquals ( 42 , $share -> getNodeId ());
$this -> assertEquals ( 19 , $share -> getPermissions ());
$this -> assertEquals ( 'token' , $share -> getToken ());
2021-03-24 12:50:56 -04:00
$this -> assertEquals ( $expirationDate , $share -> getExpirationDate ());
2016-02-04 10:08:35 -05:00
}
public function testCreateCouldNotFindServer () : void {
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'generateRemoteURL' )
-> willReturn ( 'http://localhost/' );
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturn ([ 'user' , 'server.com' ]);
2016-02-04 10:08:35 -05:00
$this -> notifications -> expects ( $this -> once ())
-> method ( 'sendRemoteShare' )
-> with (
$this -> equalTo ( 'token' ),
$this -> equalTo ( 'user@server.com' ),
$this -> equalTo ( 'myFile' ),
$this -> anything (),
2016-05-04 09:26:30 -04:00
'shareOwner' ,
2024-03-25 08:20:16 -04:00
'shareOwner@http://localhost' ,
2016-05-04 09:26:30 -04:00
'sharedBy' ,
2024-03-25 08:20:16 -04:00
'sharedBy@http://localhost'
2016-02-04 10:08:35 -05:00
) -> willReturn ( false );
$this -> rootFolder -> method ( 'getById' )
-> with ( '42' )
-> willReturn ([ $node ]);
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
try {
$share = $this -> provider -> create ( $share );
$this -> fail ();
} catch ( \Exception $e ) {
2016-11-02 13:05:14 -04:00
$this -> assertEquals ( 'Sharing myFile failed, could not find user@server.com, maybe the server is currently unreachable or uses a self-signed certificate.' , $e -> getMessage ());
2016-02-04 10:08:35 -05:00
}
$qb = $this -> connection -> getQueryBuilder ();
$stmt = $qb -> select ( '*' )
2016-06-24 09:59:32 -04:00
-> from ( 'share' )
-> where ( $qb -> expr () -> eq ( 'id' , $qb -> createNamedParameter ( $share -> getId ())))
2025-05-29 05:50:46 -04:00
-> executeQuery ();
2016-06-24 09:59:32 -04:00
2025-11-17 06:20:11 -05:00
$data = $stmt -> fetchAssociative ();
2016-06-24 09:59:32 -04:00
$stmt -> closeCursor ();
$this -> assertFalse ( $data );
}
public function testCreateException () : void {
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-06-24 09:59:32 -04:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-06-24 09:59:32 -04:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'generateRemoteURL' )
-> willReturn ( 'http://localhost/' );
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturn ([ 'user' , 'server.com' ]);
$this -> notifications -> expects ( $this -> once ())
-> method ( 'sendRemoteShare' )
-> with (
$this -> equalTo ( 'token' ),
$this -> equalTo ( 'user@server.com' ),
$this -> equalTo ( 'myFile' ),
$this -> anything (),
'shareOwner' ,
2024-03-25 08:20:16 -04:00
'shareOwner@http://localhost' ,
2016-06-24 09:59:32 -04:00
'sharedBy' ,
2024-03-25 08:20:16 -04:00
'sharedBy@http://localhost'
2016-06-24 09:59:32 -04:00
) -> willThrowException ( new \Exception ( 'dummy' ));
$this -> rootFolder -> method ( 'getById' )
-> with ( '42' )
-> willReturn ([ $node ]);
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-06-24 09:59:32 -04:00
try {
$share = $this -> provider -> create ( $share );
$this -> fail ();
} catch ( \Exception $e ) {
2016-11-02 13:05:14 -04:00
$this -> assertEquals ( 'Sharing myFile failed, could not find user@server.com, maybe the server is currently unreachable or uses a self-signed certificate.' , $e -> getMessage ());
2016-06-24 09:59:32 -04:00
}
$qb = $this -> connection -> getQueryBuilder ();
$stmt = $qb -> select ( '*' )
2016-02-04 10:08:35 -05:00
-> from ( 'share' )
-> where ( $qb -> expr () -> eq ( 'id' , $qb -> createNamedParameter ( $share -> getId ())))
2025-05-29 05:50:46 -04:00
-> executeQuery ();
2016-02-04 10:08:35 -05:00
2025-11-17 06:20:11 -05:00
$data = $stmt -> fetchAssociative ();
2016-02-04 10:08:35 -05:00
$stmt -> closeCursor ();
$this -> assertFalse ( $data );
}
public function testCreateShareWithSelf () : void {
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'compareAddresses' )
-> willReturn ( true );
$shareWith = 'sharedBy@localhost' ;
2016-02-04 10:08:35 -05:00
$share -> setSharedWith ( $shareWith )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
-> setNode ( $node );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
try {
$share = $this -> provider -> create ( $share );
$this -> fail ();
} catch ( \Exception $e ) {
2022-09-21 11:44:32 -04:00
$this -> assertEquals ( 'Not allowed to create a federated share to the same account' , $e -> getMessage ());
2016-02-04 10:08:35 -05:00
}
$qb = $this -> connection -> getQueryBuilder ();
$stmt = $qb -> select ( '*' )
-> from ( 'share' )
-> where ( $qb -> expr () -> eq ( 'id' , $qb -> createNamedParameter ( $share -> getId ())))
2025-05-29 05:50:46 -04:00
-> executeQuery ();
2016-02-04 10:08:35 -05:00
2025-11-17 06:20:11 -05:00
$data = $stmt -> fetchAssociative ();
2016-02-04 10:08:35 -05:00
$stmt -> closeCursor ();
$this -> assertFalse ( $data );
}
public function testCreateAlreadyShared () : void {
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturn ([ 'user' , 'server.com' ]);
2016-02-04 10:08:35 -05:00
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'generateRemoteURL' )
-> willReturn ( 'http://localhost/' );
2016-02-04 10:08:35 -05:00
$this -> notifications -> expects ( $this -> once ())
-> method ( 'sendRemoteShare' )
-> with (
$this -> equalTo ( 'token' ),
$this -> equalTo ( 'user@server.com' ),
$this -> equalTo ( 'myFile' ),
$this -> anything (),
2016-05-04 09:26:30 -04:00
'shareOwner' ,
2024-03-25 08:20:16 -04:00
'shareOwner@http://localhost' ,
2016-05-04 09:26:30 -04:00
'sharedBy' ,
2024-03-25 08:20:16 -04:00
'sharedBy@http://localhost'
2016-02-04 10:08:35 -05:00
) -> willReturn ( true );
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share );
try {
$this -> provider -> create ( $share );
} catch ( \Exception $e ) {
2024-02-13 04:26:36 -05:00
$this -> assertEquals ( 'Sharing myFile failed, because this item is already shared with the account user@server.com' , $e -> getMessage ());
2016-02-04 10:08:35 -05:00
}
}
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestUpdate')]
2025-05-29 05:50:46 -04:00
public function testUpdate ( string $owner , string $sharedBy , ? \DateTime $expirationDate ) : void {
$this -> provider = $this -> getMockBuilder ( FederatedShareProvider :: class )
2016-05-04 09:26:30 -04:00
-> setConstructorArgs (
[
$this -> connection ,
$this -> addressHandler ,
$this -> notifications ,
$this -> tokenHandler ,
$this -> l ,
$this -> rootFolder ,
$this -> config ,
2017-01-27 06:52:17 -05:00
$this -> userManager ,
2017-05-24 03:07:58 -04:00
$this -> cloudIdManager ,
2018-07-04 04:39:13 -04:00
$this -> gsConfig ,
2023-07-05 05:42:41 -04:00
$this -> cloudFederationProviderManager ,
$this -> logger ,
2016-05-04 09:26:30 -04:00
]
2025-05-29 05:50:46 -04:00
)
-> onlyMethods ([ 'sendPermissionUpdate' ])
-> getMock ();
2016-05-04 09:26:30 -04:00
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturn ([ 'user' , 'server.com' ]);
2016-02-04 10:08:35 -05:00
$share -> setSharedWith ( 'user@server.com' )
2016-05-04 09:26:30 -04:00
-> setSharedBy ( $sharedBy )
-> setShareOwner ( $owner )
2016-02-04 10:08:35 -05:00
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2021-03-24 12:50:56 -04:00
-> setExpirationDate ( new \DateTime ( '2019-02-01T01:02:03' ))
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'generateRemoteURL' )
-> willReturn ( 'http://localhost/' );
2016-02-04 10:08:35 -05:00
$this -> notifications -> expects ( $this -> once ())
-> method ( 'sendRemoteShare' )
-> with (
$this -> equalTo ( 'token' ),
$this -> equalTo ( 'user@server.com' ),
$this -> equalTo ( 'myFile' ),
$this -> anything (),
2016-05-04 09:26:30 -04:00
$owner ,
2024-03-25 08:20:16 -04:00
$owner . '@http://localhost' ,
2016-05-04 09:26:30 -04:00
$sharedBy ,
2024-03-25 08:20:16 -04:00
$sharedBy . '@http://localhost'
2016-02-04 10:08:35 -05:00
) -> willReturn ( true );
2025-12-01 08:09:28 -05:00
$this -> provider -> expects ( $this -> never ()) -> method ( 'sendPermissionUpdate' );
2016-05-04 09:26:30 -04:00
2016-02-04 10:08:35 -05:00
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> provider -> create ( $share );
$share -> setPermissions ( 1 );
2021-03-24 12:50:56 -04:00
$share -> setExpirationDate ( $expirationDate );
2016-02-04 10:08:35 -05:00
$this -> provider -> update ( $share );
$share = $this -> provider -> getShareById ( $share -> getId ());
$this -> assertEquals ( 1 , $share -> getPermissions ());
2021-03-24 12:50:56 -04:00
$this -> assertEquals ( $expirationDate , $share -> getExpirationDate ());
2016-02-04 10:08:35 -05:00
}
2025-05-29 05:50:46 -04:00
public static function dataTestUpdate () : array {
2016-05-04 09:26:30 -04:00
return [
2021-03-24 12:50:56 -04:00
[ 'sharedBy' , 'shareOwner' , new \DateTime ( '2020-03-01T01:02:03' )],
[ 'shareOwner' , 'shareOwner' , null ],
2016-05-04 09:26:30 -04:00
];
}
2016-02-04 10:08:35 -05:00
public function testGetSharedBy () : void {
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
2022-05-24 06:56:01 -04:00
$this -> addressHandler -> expects ( $this -> never ()) -> method ( 'splitUserRemote' );
2016-05-11 14:48:27 -04:00
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> notifications
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share );
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'user2@server.com' )
-> setSharedBy ( 'sharedBy2' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share2 );
2020-06-24 10:49:16 -04:00
$shares = $this -> provider -> getSharesBy ( 'sharedBy' , IShare :: TYPE_REMOTE , null , false , - 1 , 0 );
2016-02-04 10:08:35 -05:00
$this -> assertCount ( 1 , $shares );
$this -> assertEquals ( 'user@server.com' , $shares [ 0 ] -> getSharedWith ());
$this -> assertEquals ( 'sharedBy' , $shares [ 0 ] -> getSharedBy ());
}
public function testGetSharedByWithNode () : void {
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> notifications
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share );
2017-10-24 09:26:53 -04:00
$node2 = $this -> getMockBuilder ( File :: class ) -> getMock ();
2016-02-04 10:08:35 -05:00
$node2 -> method ( 'getId' ) -> willReturn ( 43 );
$node2 -> method ( 'getName' ) -> willReturn ( 'myOtherFile' );
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node2 )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share2 );
2020-06-24 10:49:16 -04:00
$shares = $this -> provider -> getSharesBy ( 'sharedBy' , IShare :: TYPE_REMOTE , $node2 , false , - 1 , 0 );
2016-02-04 10:08:35 -05:00
$this -> assertCount ( 1 , $shares );
$this -> assertEquals ( 43 , $shares [ 0 ] -> getNodeId ());
}
public function testGetSharedByWithReshares () : void {
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> notifications
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'shareOwner' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share );
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'user2@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share2 );
2020-06-24 10:49:16 -04:00
$shares = $this -> provider -> getSharesBy ( 'shareOwner' , IShare :: TYPE_REMOTE , null , true , - 1 , 0 );
2016-02-04 10:08:35 -05:00
$this -> assertCount ( 2 , $shares );
}
public function testGetSharedByWithLimit () : void {
2025-05-29 05:50:46 -04:00
$node = $this -> createMock ( File :: class );
2016-02-04 10:08:35 -05:00
$node -> method ( 'getId' ) -> willReturn ( 42 );
$node -> method ( 'getName' ) -> willReturn ( 'myFile' );
2016-05-11 14:48:27 -04:00
$this -> addressHandler -> expects ( $this -> any ()) -> method ( 'splitUserRemote' )
-> willReturnCallback ( function ( $uid ) {
if ( $uid === 'user@server.com' ) {
return [ 'user' , 'server.com' ];
}
return [ 'user2' , 'server.com' ];
});
2016-02-04 10:08:35 -05:00
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> notifications
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
$this -> rootFolder -> expects ( $this -> never ()) -> method ( $this -> anything ());
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-02-04 10:08:35 -05:00
$share = $this -> shareManager -> newShare ();
$share -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share );
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'user2@server.com' )
-> setSharedBy ( 'sharedBy' )
-> setShareOwner ( 'shareOwner' )
-> setPermissions ( 19 )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $node )
-> setTarget ( '' );
2016-02-04 10:08:35 -05:00
$this -> provider -> create ( $share2 );
2020-06-24 10:49:16 -04:00
$shares = $this -> provider -> getSharesBy ( 'shareOwner' , IShare :: TYPE_REMOTE , null , true , 1 , 1 );
2016-02-04 10:08:35 -05:00
$this -> assertCount ( 1 , $shares );
$this -> assertEquals ( 'user2@server.com' , $shares [ 0 ] -> getSharedWith ());
}
2016-04-04 06:28:19 -04:00
2025-05-29 05:50:46 -04:00
public static function dataDeleteUser () : array {
2016-04-04 06:28:19 -04:00
return [
[ 'a' , 'b' , 'c' , 'a' , true ],
[ 'a' , 'b' , 'c' , 'b' , false ],
// The recipient is non local.
[ 'a' , 'b' , 'c' , 'c' , false ],
[ 'a' , 'b' , 'c' , 'd' , false ],
];
}
/**
*
* @ param string $owner The owner of the share ( uid )
* @ param string $initiator The initiator of the share ( uid )
* @ param string $recipient The recipient of the share ( uid / gid / pass )
* @ param string $deletedUser The user that is deleted
* @ param bool $rowDeleted Is the row deleted in this setup
*/
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataDeleteUser')]
2025-05-29 05:50:46 -04:00
public function testDeleteUser ( string $owner , string $initiator , string $recipient , string $deletedUser , bool $rowDeleted ) : void {
2016-04-04 06:28:19 -04:00
$qb = $this -> connection -> getQueryBuilder ();
$qb -> insert ( 'share' )
2020-06-24 10:49:16 -04:00
-> setValue ( 'share_type' , $qb -> createNamedParameter ( IShare :: TYPE_REMOTE ))
2016-04-04 06:28:19 -04:00
-> setValue ( 'uid_owner' , $qb -> createNamedParameter ( $owner ))
-> setValue ( 'uid_initiator' , $qb -> createNamedParameter ( $initiator ))
-> setValue ( 'share_with' , $qb -> createNamedParameter ( $recipient ))
-> setValue ( 'item_type' , $qb -> createNamedParameter ( 'file' ))
-> setValue ( 'item_source' , $qb -> createNamedParameter ( 42 ))
-> setValue ( 'file_source' , $qb -> createNamedParameter ( 42 ))
2025-05-29 05:50:46 -04:00
-> executeStatement ();
2016-04-04 06:28:19 -04:00
$id = $qb -> getLastInsertId ();
2020-06-24 10:49:16 -04:00
$this -> provider -> userDeleted ( $deletedUser , IShare :: TYPE_REMOTE );
2016-04-04 06:28:19 -04:00
$qb = $this -> connection -> getQueryBuilder ();
$qb -> select ( '*' )
-> from ( 'share' )
-> where (
$qb -> expr () -> eq ( 'id' , $qb -> createNamedParameter ( $id ))
);
2025-05-29 05:50:46 -04:00
$cursor = $qb -> executeQuery ();
2025-11-17 06:20:11 -05:00
$data = $cursor -> fetchAllAssociative ();
2016-04-04 06:28:19 -04:00
$cursor -> closeCursor ();
$this -> assertCount ( $rowDeleted ? 0 : 1 , $data );
}
2016-04-18 12:17:08 -04:00
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestIsOutgoingServer2serverShareEnabled')]
2025-05-29 05:50:46 -04:00
public function testIsOutgoingServer2serverShareEnabled ( bool $internalOnly , string $isEnabled , bool $expected ) : void {
2017-05-24 03:07:58 -04:00
$this -> gsConfig -> expects ( $this -> once ()) -> method ( 'onlyInternalFederation' )
-> willReturn ( $internalOnly );
$this -> config -> expects ( $this -> any ()) -> method ( 'getAppValue' )
2016-04-18 12:17:08 -04:00
-> with ( 'files_sharing' , 'outgoing_server2server_share_enabled' , 'yes' )
-> willReturn ( $isEnabled );
$this -> assertSame ( $expected ,
$this -> provider -> isOutgoingServer2serverShareEnabled ()
);
}
2025-05-29 05:50:46 -04:00
public static function dataTestIsOutgoingServer2serverShareEnabled () : array {
2017-05-24 03:07:58 -04:00
return [
[ false , 'yes' , true ],
[ false , 'no' , false ],
[ true , 'yes' , false ],
[ true , 'no' , false ],
];
}
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestIsIncomingServer2serverShareEnabled')]
2025-05-29 05:50:46 -04:00
public function testIsIncomingServer2serverShareEnabled ( bool $onlyInternal , string $isEnabled , bool $expected ) : void {
2017-05-24 03:07:58 -04:00
$this -> gsConfig -> expects ( $this -> once ()) -> method ( 'onlyInternalFederation' )
-> willReturn ( $onlyInternal );
$this -> config -> expects ( $this -> any ()) -> method ( 'getAppValue' )
2016-04-18 12:17:08 -04:00
-> with ( 'files_sharing' , 'incoming_server2server_share_enabled' , 'yes' )
-> willReturn ( $isEnabled );
$this -> assertSame ( $expected ,
$this -> provider -> isIncomingServer2serverShareEnabled ()
);
}
2025-05-29 05:50:46 -04:00
public static function dataTestIsIncomingServer2serverShareEnabled () : array {
2017-05-24 03:07:58 -04:00
return [
[ false , 'yes' , true ],
[ false , 'no' , false ],
[ true , 'yes' , false ],
[ true , 'no' , false ],
];
}
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestIsLookupServerQueriesEnabled')]
2025-05-29 05:50:46 -04:00
public function testIsLookupServerQueriesEnabled ( bool $gsEnabled , string $isEnabled , bool $expected ) : void {
2017-05-24 03:07:58 -04:00
$this -> gsConfig -> expects ( $this -> once ()) -> method ( 'isGlobalScaleEnabled' )
-> willReturn ( $gsEnabled );
$this -> config -> expects ( $this -> any ()) -> method ( 'getAppValue' )
2025-03-10 10:31:45 -04:00
-> with ( 'files_sharing' , 'lookupServerEnabled' , 'no' )
2017-04-07 05:42:33 -04:00
-> willReturn ( $isEnabled );
$this -> assertSame ( $expected ,
$this -> provider -> isLookupServerQueriesEnabled ()
);
}
2017-05-24 03:07:58 -04:00
2025-05-29 05:50:46 -04:00
public static function dataTestIsLookupServerQueriesEnabled () : array {
2017-05-24 03:07:58 -04:00
return [
[ true , 'yes' , true ],
[ true , 'no' , true ],
2025-03-10 11:24:26 -04:00
// TODO: reenable if we use the lookup server for non-global scale
// [false, 'yes', true],
// [false, 'no', false],
[ false , 'no' , false ],
[ false , 'yes' , false ],
2017-05-24 03:07:58 -04:00
];
}
2026-01-07 08:21:48 -05:00
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestIsLookupServerUploadEnabled')]
2025-05-29 05:50:46 -04:00
public function testIsLookupServerUploadEnabled ( bool $gsEnabled , string $isEnabled , bool $expected ) : void {
2017-05-24 03:07:58 -04:00
$this -> gsConfig -> expects ( $this -> once ()) -> method ( 'isGlobalScaleEnabled' )
-> willReturn ( $gsEnabled );
$this -> config -> expects ( $this -> any ()) -> method ( 'getAppValue' )
2025-03-08 14:54:15 -05:00
-> with ( 'files_sharing' , 'lookupServerUploadEnabled' , 'no' )
2017-04-07 05:42:33 -04:00
-> willReturn ( $isEnabled );
$this -> assertSame ( $expected ,
$this -> provider -> isLookupServerUploadEnabled ()
);
}
2025-05-29 05:50:46 -04:00
public static function dataTestIsLookupServerUploadEnabled () : array {
2016-04-18 12:17:08 -04:00
return [
2017-05-24 03:07:58 -04:00
[ true , 'yes' , false ],
[ true , 'no' , false ],
2025-03-10 11:24:26 -04:00
// TODO: reenable if we use the lookup server again
// [false, 'yes', true],
// [false, 'no', false],
[ false , 'yes' , false ],
[ false , 'no' , false ],
2016-04-18 12:17:08 -04:00
];
}
2016-11-01 08:22:52 -04:00
public function testGetSharesInFolder () : void {
2025-02-03 09:34:01 -05:00
$userManager = Server :: get ( IUserManager :: class );
$rootFolder = Server :: get ( IRootFolder :: class );
2016-11-01 08:22:52 -04:00
2025-05-29 05:50:46 -04:00
$u1 = $userManager -> createUser ( 'testFed' , md5 (( string ) time ()));
$u2 = $userManager -> createUser ( 'testFed2' , md5 (( string ) time ()));
2016-11-01 08:22:52 -04:00
$folder1 = $rootFolder -> getUserFolder ( $u1 -> getUID ()) -> newFolder ( 'foo' );
$file1 = $folder1 -> newFile ( 'bar1' );
$file2 = $folder1 -> newFile ( 'bar2' );
$this -> tokenHandler -> method ( 'generateToken' ) -> willReturn ( 'token' );
$this -> notifications
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2016-11-01 08:22:52 -04:00
$share1 = $this -> shareManager -> newShare ();
$share1 -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( $u1 -> getUID ())
-> setShareOwner ( $u1 -> getUID ())
2024-10-10 06:40:31 -04:00
-> setPermissions ( Constants :: PERMISSION_READ )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $file1 )
-> setTarget ( '' );
2016-11-01 08:22:52 -04:00
$this -> provider -> create ( $share1 );
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( $u2 -> getUID ())
-> setShareOwner ( $u1 -> getUID ())
2024-10-10 06:40:31 -04:00
-> setPermissions ( Constants :: PERMISSION_READ )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $file2 )
-> setTarget ( '' );
2016-11-01 08:22:52 -04:00
$this -> provider -> create ( $share2 );
$result = $this -> provider -> getSharesInFolder ( $u1 -> getUID (), $folder1 , false );
$this -> assertCount ( 1 , $result );
$this -> assertCount ( 1 , $result [ $file1 -> getId ()]);
$result = $this -> provider -> getSharesInFolder ( $u1 -> getUID (), $folder1 , true );
$this -> assertCount ( 2 , $result );
$this -> assertCount ( 1 , $result [ $file1 -> getId ()]);
$this -> assertCount ( 1 , $result [ $file2 -> getId ()]);
$u1 -> delete ();
$u2 -> delete ();
}
2017-01-04 02:59:43 -05:00
public function testGetAccessList () : void {
2025-02-03 09:34:01 -05:00
$userManager = Server :: get ( IUserManager :: class );
$rootFolder = Server :: get ( IRootFolder :: class );
2017-01-04 02:59:43 -05:00
2025-05-29 05:50:46 -04:00
$u1 = $userManager -> createUser ( 'testFed' , md5 (( string ) time ()));
2017-01-04 02:59:43 -05:00
$folder1 = $rootFolder -> getUserFolder ( $u1 -> getUID ()) -> newFolder ( 'foo' );
$file1 = $folder1 -> newFile ( 'bar1' );
2017-04-10 09:40:30 -04:00
$this -> tokenHandler -> expects ( $this -> exactly ( 2 ))
-> method ( 'generateToken' )
-> willReturnOnConsecutiveCalls ( 'token1' , 'token2' );
$this -> notifications -> expects ( $this -> atLeastOnce ())
2017-01-04 02:59:43 -05:00
-> method ( 'sendRemoteShare' )
-> willReturn ( true );
2020-11-16 11:56:44 -05:00
$this -> contactsManager -> expects ( $this -> any ())
-> method ( 'search' )
-> willReturn ([]);
2017-04-11 06:40:36 -04:00
$result = $this -> provider -> getAccessList ([ $file1 ], true );
$this -> assertEquals ([ 'remote' => []], $result );
$result = $this -> provider -> getAccessList ([ $file1 ], false );
$this -> assertEquals ([ 'remote' => false ], $result );
2018-01-16 13:24:52 -05:00
$this -> addressHandler -> method ( 'generateRemoteURL' )
-> willReturn ( 'remoteurl.com' );
2017-01-04 02:59:43 -05:00
$share1 = $this -> shareManager -> newShare ();
$share1 -> setSharedWith ( 'user@server.com' )
-> setSharedBy ( $u1 -> getUID ())
-> setShareOwner ( $u1 -> getUID ())
2024-10-10 06:40:31 -04:00
-> setPermissions ( Constants :: PERMISSION_READ )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $file1 )
-> setTarget ( '' );
2017-01-04 02:59:43 -05:00
$this -> provider -> create ( $share1 );
2017-04-10 09:40:30 -04:00
$share2 = $this -> shareManager -> newShare ();
$share2 -> setSharedWith ( 'foobar@localhost' )
-> setSharedBy ( $u1 -> getUID ())
-> setShareOwner ( $u1 -> getUID ())
2024-10-10 06:40:31 -04:00
-> setPermissions ( Constants :: PERMISSION_READ )
2020-06-24 10:49:16 -04:00
-> setShareType ( IShare :: TYPE_REMOTE )
2026-03-03 09:25:03 -05:00
-> setNode ( $file1 )
-> setTarget ( '' );
2017-04-10 09:40:30 -04:00
$this -> provider -> create ( $share2 );
2017-01-04 02:59:43 -05:00
$result = $this -> provider -> getAccessList ([ $file1 ], true );
2017-04-10 09:40:30 -04:00
$this -> assertEquals ([ 'remote' => [
'user@server.com' => [
'token' => 'token1' ,
'node_id' => $file1 -> getId (),
],
'foobar@localhost' => [
'token' => 'token2' ,
'node_id' => $file1 -> getId (),
],
]], $result );
2017-04-11 06:40:36 -04:00
$result = $this -> provider -> getAccessList ([ $file1 ], false );
$this -> assertEquals ([ 'remote' => true ], $result );
2017-01-04 02:59:43 -05:00
$u1 -> delete ();
}
2016-02-04 10:08:35 -05:00
}