123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967 |
- <?php
- /**
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
- namespace Test\Share20;
- use OC\Share20\DefaultShareProvider;
- use OC\Share20\ShareAttributes;
- use OCP\AppFramework\Utility\ITimeFactory;
- use OCP\DB\QueryBuilder\IQueryBuilder;
- use OCP\Defaults;
- use OCP\Files\File;
- use OCP\Files\Folder;
- use OCP\Files\IRootFolder;
- use OCP\IDBConnection;
- use OCP\IGroup;
- use OCP\IGroupManager;
- use OCP\IL10N;
- use OCP\IURLGenerator;
- use OCP\IUser;
- use OCP\IUserManager;
- use OCP\L10N\IFactory;
- use OCP\Mail\IMailer;
- use OCP\Share\IShare;
- use PHPUnit\Framework\MockObject\MockObject;
- /**
- * Class DefaultShareProviderTest
- *
- * @package Test\Share20
- * @group DB
- */
- class DefaultShareProviderTest extends \Test\TestCase {
- /** @var IDBConnection */
- protected $dbConn;
- /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
- /** @var IGroupManager | \PHPUnit\Framework\MockObject\MockObject */
- protected $groupManager;
- /** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
- protected $rootFolder;
- /** @var DefaultShareProvider */
- protected $provider;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IMailer */
- protected $mailer;
- /** @var IFactory|MockObject */
- protected $l10nFactory;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IL10N */
- protected $l10n;
- /** @var \PHPUnit\Framework\MockObject\MockObject|Defaults */
- protected $defaults;
- /** @var \PHPUnit\Framework\MockObject\MockObject|IURLGenerator */
- protected $urlGenerator;
- /** @var ITimeFactory|MockObject */
- protected $timeFactory;
- protected function setUp(): void {
- $this->dbConn = \OC::$server->getDatabaseConnection();
- $this->userManager = $this->createMock(IUserManager::class);
- $this->groupManager = $this->createMock(IGroupManager::class);
- $this->rootFolder = $this->createMock(IRootFolder::class);
- $this->mailer = $this->createMock(IMailer::class);
- $this->l10nFactory = $this->createMock(IFactory::class);
- $this->l10n = $this->createMock(IL10N::class);
- $this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->userManager->expects($this->any())->method('userExists')->willReturn(true);
- $this->timeFactory->expects($this->any())->method('now')->willReturn(new \DateTimeImmutable("2023-05-04 00:00 Europe/Berlin"));
- //Empty share table
- $this->dbConn->getQueryBuilder()->delete('share')->execute();
- $this->provider = new DefaultShareProvider(
- $this->dbConn,
- $this->userManager,
- $this->groupManager,
- $this->rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- );
- }
- protected function tearDown(): void {
- $this->dbConn->getQueryBuilder()->delete('share')->execute();
- $this->dbConn->getQueryBuilder()->delete('filecache')->execute();
- $this->dbConn->getQueryBuilder()->delete('storages')->execute();
- }
- /**
- * @param int $shareType
- * @param string $sharedWith
- * @param string $sharedBy
- * @param string $shareOwner
- * @param string $itemType
- * @param int $fileSource
- * @param string $fileTarget
- * @param int $permissions
- * @param $token
- * @param $expiration
- * @return int
- */
- private function addShareToDB($shareType, $sharedWith, $sharedBy, $shareOwner,
- $itemType, $fileSource, $fileTarget, $permissions, $token, $expiration,
- $parent = null) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share');
- if ($shareType) {
- $qb->setValue('share_type', $qb->expr()->literal($shareType));
- }
- if ($sharedWith) {
- $qb->setValue('share_with', $qb->expr()->literal($sharedWith));
- }
- if ($sharedBy) {
- $qb->setValue('uid_initiator', $qb->expr()->literal($sharedBy));
- }
- if ($shareOwner) {
- $qb->setValue('uid_owner', $qb->expr()->literal($shareOwner));
- }
- if ($itemType) {
- $qb->setValue('item_type', $qb->expr()->literal($itemType));
- }
- if ($fileSource) {
- $qb->setValue('file_source', $qb->expr()->literal($fileSource));
- }
- if ($fileTarget) {
- $qb->setValue('file_target', $qb->expr()->literal($fileTarget));
- }
- if ($permissions) {
- $qb->setValue('permissions', $qb->expr()->literal($permissions));
- }
- if ($token) {
- $qb->setValue('token', $qb->expr()->literal($token));
- }
- if ($expiration) {
- $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATE));
- }
- if ($parent) {
- $qb->setValue('parent', $qb->expr()->literal($parent));
- }
- $this->assertEquals(1, $qb->execute());
- return$qb->getLastInsertId();
- }
- public function testGetShareByIdNotExist() {
- $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
- $this->provider->getShareById(1);
- }
- public function testGetShareByIdUserShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $qb->execute();
- $id = $qb->getLastInsertId();
- $sharedBy = $this->createMock(IUser::class);
- $sharedBy->method('getUID')->willReturn('sharedBy');
- $shareOwner = $this->createMock(IUser::class);
- $shareOwner->method('getUID')->willReturn('shareOwner');
- $ownerPath = $this->createMock(File::class);
- $shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $shareOwnerFolder],
- ]);
- $share = $this->provider->getShareById($id);
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getNode());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetShareByIdLazy() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $qb->execute();
- $id = $qb->getLastInsertId();
- $this->rootFolder->expects($this->never())->method('getUserFolder');
- $share = $this->provider->getShareById($id);
- // We do not fetch the node so the rootfolder is never called.
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetShareByIdLazy2() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $qb->execute();
- $id = $qb->getLastInsertId();
- $ownerPath = $this->createMock(File::class);
- $shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
- $this->rootFolder
- ->method('getUserFolder')
- ->with('shareOwner')
- ->willReturn($shareOwnerFolder);
- $share = $this->provider->getShareById($id);
- // We fetch the node so the root folder is eventually called
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getNode());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetShareByIdGroupShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- // Get the id
- $id = $qb->getLastInsertId();
- $ownerPath = $this->createMock(Folder::class);
- $shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $shareOwnerFolder],
- ]);
- $share = $this->provider->getShareById($id);
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getNode());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetShareByIdUserGroupShare() {
- $id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null);
- $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id);
- $user0 = $this->createMock(IUser::class);
- $user0->method('getUID')->willReturn('user0');
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $group0 = $this->createMock(IGroup::class);
- $group0->method('inGroup')->with($user1)->willReturn(true);
- $group0->method('getDisplayName')->willReturn('g0-displayname');
- $node = $this->createMock(Folder::class);
- $node->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user0')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$node]);
- $this->userManager->method('get')->willReturnMap([
- ['user0', $user0],
- ['user1', $user1],
- ]);
- $this->groupManager->method('get')->with('group0')->willReturn($group0);
- $share = $this->provider->getShareById($id, 'user1');
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
- $this->assertSame('group0', $share->getSharedWith());
- $this->assertSame('user0', $share->getSharedBy());
- $this->assertSame('user0', $share->getShareOwner());
- $this->assertSame($node, $share->getNode());
- $this->assertEquals(0, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
- $this->assertEquals('userTarget', $share->getTarget());
- }
- public function testGetShareByIdLinkShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
- 'password' => $qb->expr()->literal('password'),
- 'password_by_talk' => $qb->expr()->literal(true),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- 'token' => $qb->expr()->literal('token'),
- 'expiration' => $qb->expr()->literal('2000-01-02 00:00:00'),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $ownerPath = $this->createMock(Folder::class);
- $shareOwnerFolder = $this->createMock(Folder::class);
- $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $shareOwnerFolder],
- ]);
- $share = $this->provider->getShareById($id);
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(IShare::TYPE_LINK, $share->getShareType());
- $this->assertNull($share->getSharedWith());
- $this->assertEquals('password', $share->getPassword());
- $this->assertEquals(true, $share->getSendPasswordByTalk());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getNode());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals('token', $share->getToken());
- $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testDeleteSingleShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $share = $this->createMock(IShare::class);
- $share->method('getId')->willReturn($id);
- /** @var DefaultShareProvider $provider */
- $provider = $this->getMockBuilder(DefaultShareProvider::class)
- ->setConstructorArgs([
- $this->dbConn,
- $this->userManager,
- $this->groupManager,
- $this->rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- ])
- ->setMethods(['getShareById'])
- ->getMock();
- $provider->delete($share);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share');
- $cursor = $qb->execute();
- $result = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertEmpty($result);
- }
- public function testDeleteSingleShareLazy() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $this->rootFolder->expects($this->never())->method($this->anything());
- $share = $this->provider->getShareById($id);
- $this->provider->delete($share);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share');
- $cursor = $qb->execute();
- $result = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertEmpty($result);
- }
- public function testDeleteGroupShareWithUserGroupShares() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(2),
- 'share_with' => $qb->expr()->literal('sharedWithUser'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $this->assertEquals(1, $qb->execute());
- $share = $this->createMock(IShare::class);
- $share->method('getId')->willReturn($id);
- $share->method('getShareType')->willReturn(IShare::TYPE_GROUP);
- /** @var DefaultShareProvider $provider */
- $provider = $this->getMockBuilder(DefaultShareProvider::class)
- ->setConstructorArgs([
- $this->dbConn,
- $this->userManager,
- $this->groupManager,
- $this->rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- ])
- ->setMethods(['getShareById'])
- ->getMock();
- $provider->delete($share);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share');
- $cursor = $qb->execute();
- $result = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertEmpty($result);
- }
- public function testGetChildren() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $qb->execute();
- // Get the id
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('user1'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('user2'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $qb->execute();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('group1'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('user3'),
- 'item_type' => $qb->expr()->literal('folder'),
- 'file_source' => $qb->expr()->literal(3),
- 'file_target' => $qb->expr()->literal('myTarget2'),
- 'permissions' => $qb->expr()->literal(4),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $qb->execute();
- $ownerPath = $this->createMock(Folder::class);
- $ownerFolder = $this->createMock(Folder::class);
- $ownerFolder->method('getById')->willReturn([$ownerPath]);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['shareOwner', $ownerFolder],
- ]);
- $share = $this->createMock(IShare::class);
- $share->method('getId')->willReturn($id);
- $children = $this->provider->getChildren($share);
- $this->assertCount(2, $children);
- //Child1
- $this->assertEquals(IShare::TYPE_USER, $children[0]->getShareType());
- $this->assertEquals('user1', $children[0]->getSharedWith());
- $this->assertEquals('user2', $children[0]->getSharedBy());
- $this->assertEquals('shareOwner', $children[0]->getShareOwner());
- $this->assertEquals($ownerPath, $children[0]->getNode());
- $this->assertEquals(2, $children[0]->getPermissions());
- $this->assertEquals(null, $children[0]->getToken());
- $this->assertEquals(null, $children[0]->getExpirationDate());
- $this->assertEquals('myTarget1', $children[0]->getTarget());
- //Child2
- $this->assertEquals(IShare::TYPE_GROUP, $children[1]->getShareType());
- $this->assertEquals('group1', $children[1]->getSharedWith());
- $this->assertEquals('user3', $children[1]->getSharedBy());
- $this->assertEquals('shareOwner', $children[1]->getShareOwner());
- $this->assertEquals($ownerPath, $children[1]->getNode());
- $this->assertEquals(4, $children[1]->getPermissions());
- $this->assertEquals(null, $children[1]->getToken());
- $this->assertEquals(null, $children[1]->getExpirationDate());
- $this->assertEquals('myTarget2', $children[1]->getTarget());
- }
- public function testCreateUserShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
- $shareOwner = $this->createMock(IUser::class);
- $shareOwner->method('getUID')->willReturn('shareOwner');
- $path = $this->createMock(File::class);
- $path->method('getId')->willReturn(100);
- $path->method('getOwner')->willReturn($shareOwner);
- $ownerFolder = $this->createMock(Folder::class);
- $userFolder = $this->createMock(Folder::class);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['sharedBy', $userFolder],
- ['shareOwner', $ownerFolder],
- ]);
- $userFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $share->setShareType(IShare::TYPE_USER);
- $share->setSharedWith('sharedWith');
- $share->setSharedBy('sharedBy');
- $share->setShareOwner('shareOwner');
- $share->setNode($path);
- $share->setSharedWithDisplayName('Displayed Name');
- $share->setSharedWithAvatar('/path/to/image.svg');
- $share->setPermissions(1);
- $attrs = new ShareAttributes();
- $attrs->setAttribute('permissions', 'download', true);
- $share->setAttributes($attrs);
- $share->setTarget('/target');
- $share2 = $this->provider->create($share);
- $this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
- $this->assertSame(IShare::TYPE_USER, $share2->getShareType());
- $this->assertSame('sharedWith', $share2->getSharedWith());
- $this->assertSame('sharedBy', $share2->getSharedBy());
- $this->assertSame('shareOwner', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
- $this->assertSame($path, $share2->getNode());
- // Data is kept after creation
- $this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
- $this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
- $this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
- $this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());
- $this->assertSame(
- [
- [
- 'scope' => 'permissions',
- 'key' => 'download',
- 'enabled' => true
- ]
- ],
- $share->getAttributes()->toArray()
- );
- }
- public function testCreateGroupShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
- $shareOwner = $this->createMock(IUser::class);
- $shareOwner->method('getUID')->willReturn('shareOwner');
- $path = $this->createMock(Folder::class);
- $path->method('getId')->willReturn(100);
- $path->method('getOwner')->willReturn($shareOwner);
- $ownerFolder = $this->createMock(Folder::class);
- $userFolder = $this->createMock(Folder::class);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['sharedBy', $userFolder],
- ['shareOwner', $ownerFolder],
- ]);
- $userFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $share->setShareType(IShare::TYPE_GROUP);
- $share->setSharedWith('sharedWith');
- $share->setSharedBy('sharedBy');
- $share->setShareOwner('shareOwner');
- $share->setNode($path);
- $share->setPermissions(1);
- $share->setSharedWithDisplayName('Displayed Name');
- $share->setSharedWithAvatar('/path/to/image.svg');
- $share->setTarget('/target');
- $attrs = new ShareAttributes();
- $attrs->setAttribute('permissions', 'download', true);
- $share->setAttributes($attrs);
- $share2 = $this->provider->create($share);
- $this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
- $this->assertSame(IShare::TYPE_GROUP, $share2->getShareType());
- $this->assertSame('sharedWith', $share2->getSharedWith());
- $this->assertSame('sharedBy', $share2->getSharedBy());
- $this->assertSame('shareOwner', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
- $this->assertSame($path, $share2->getNode());
- // Data is kept after creation
- $this->assertSame('Displayed Name', $share->getSharedWithDisplayName());
- $this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
- $this->assertSame('Displayed Name', $share2->getSharedWithDisplayName());
- $this->assertSame('/path/to/image.svg', $share2->getSharedWithAvatar());
- $this->assertSame(
- [
- [
- 'scope' => 'permissions',
- 'key' => 'download',
- 'enabled' => true
- ]
- ],
- $share->getAttributes()->toArray()
- );
- }
- public function testCreateLinkShare() {
- $share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
- $shareOwner = $this->createMock(IUser::class);
- $shareOwner->method('getUID')->willReturn('shareOwner');
- $path = $this->createMock(Folder::class);
- $path->method('getId')->willReturn(100);
- $path->method('getOwner')->willReturn($shareOwner);
- $ownerFolder = $this->createMock(Folder::class);
- $userFolder = $this->createMock(Folder::class);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap([
- ['sharedBy', $userFolder],
- ['shareOwner', $ownerFolder],
- ]);
- $userFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $ownerFolder->method('getById')
- ->with(100)
- ->willReturn([$path]);
- $share->setShareType(IShare::TYPE_LINK);
- $share->setSharedBy('sharedBy');
- $share->setShareOwner('shareOwner');
- $share->setNode($path);
- $share->setPermissions(1);
- $share->setPassword('password');
- $share->setSendPasswordByTalk(true);
- $share->setToken('token');
- $expireDate = new \DateTime();
- $share->setExpirationDate($expireDate);
- $share->setTarget('/target');
- $share2 = $this->provider->create($share);
- $this->assertNotNull($share2->getId());
- $this->assertSame('ocinternal:'.$share2->getId(), $share2->getFullId());
- $this->assertSame(IShare::TYPE_LINK, $share2->getShareType());
- $this->assertSame('sharedBy', $share2->getSharedBy());
- $this->assertSame('shareOwner', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
- $this->assertSame($path, $share2->getNode());
- $this->assertSame('password', $share2->getPassword());
- $this->assertSame(true, $share2->getSendPasswordByTalk());
- $this->assertSame('token', $share2->getToken());
- $this->assertEquals($expireDate->getTimestamp(), $share2->getExpirationDate()->getTimestamp());
- }
- public function testGetShareByToken() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
- 'password' => $qb->expr()->literal('password'),
- 'password_by_talk' => $qb->expr()->literal(true),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- 'token' => $qb->expr()->literal('secrettoken'),
- ]);
- $qb->execute();
- $id = $qb->getLastInsertId();
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getShareByToken('secrettoken');
- $this->assertEquals($id, $share->getId());
- $this->assertSame('shareOwner', $share->getShareOwner());
- $this->assertSame('sharedBy', $share->getSharedBy());
- $this->assertSame('secrettoken', $share->getToken());
- $this->assertSame('password', $share->getPassword());
- $this->assertSame(true, $share->getSendPasswordByTalk());
- $this->assertSame(null, $share->getSharedWith());
- }
- public function testGetShareByTokenNotFound() {
- $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
- $this->provider->getShareByToken('invalidtoken');
- }
- private function createTestStorageEntry($storageStringId) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('storages')
- ->values([
- 'id' => $qb->expr()->literal($storageStringId),
- ]);
- $this->assertEquals(1, $qb->execute());
- return $qb->getLastInsertId();
- }
- private function createTestFileEntry($path, $storage = 1) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('filecache')
- ->values([
- 'storage' => $qb->expr()->literal($storage),
- 'path' => $qb->expr()->literal($path),
- 'path_hash' => $qb->expr()->literal(md5($path)),
- 'name' => $qb->expr()->literal(basename($path)),
- ]);
- $this->assertEquals(1, $qb->execute());
- return $qb->getLastInsertId();
- }
- public function storageAndFileNameProvider() {
- return [
- // regular file on regular storage
- ['home::shareOwner', 'files/test.txt', 'files/test2.txt'],
- // regular file on external storage
- ['smb::whatever', 'files/test.txt', 'files/test2.txt'],
- // regular file on external storage in trashbin-like folder,
- ['smb::whatever', 'files_trashbin/files/test.txt', 'files_trashbin/files/test2.txt'],
- ];
- }
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2) {
- $storageId = $this->createTestStorageEntry($storageStringId);
- $fileId = $this->createTestFileEntry($fileName1, $storageId);
- $fileId2 = $this->createTestFileEntry($fileName2, $storageId);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith2'),
- 'uid_owner' => $qb->expr()->literal('shareOwner2'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy2'),
- 'item_type' => $qb->expr()->literal('file2'),
- 'file_source' => $qb->expr()->literal($fileId2),
- 'file_target' => $qb->expr()->literal('myTarget2'),
- 'permissions' => $qb->expr()->literal(14),
- ]);
- $this->assertEquals(1, $qb->execute());
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
- $share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1, 0);
- $this->assertCount(1, $share);
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- }
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2) {
- $storageId = $this->createTestStorageEntry($storageStringId);
- $fileId = $this->createTestFileEntry($fileName1, $storageId);
- $fileId2 = $this->createTestFileEntry($fileName2, $storageId);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner2'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy2'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId2),
- 'file_target' => $qb->expr()->literal('myTarget2'),
- 'permissions' => $qb->expr()->literal(14),
- ]);
- $this->assertEquals(1, $qb->execute());
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $groups = [];
- foreach (range(0, 100) as $i) {
- $groups[] = 'group'.$i;
- }
- $groups[] = 'sharedWith';
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->createMock(IUser::class);
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->createMock(IUser::class);
- $initiator->method('getUID')->willReturn('sharedBy');
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
- $share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_GROUP, null, 20, 1);
- $this->assertCount(1, $share);
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
- }
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroupUserModified($storageStringId, $fileName1, $fileName2) {
- $storageId = $this->createTestStorageEntry($storageStringId);
- $fileId = $this->createTestFileEntry($fileName1, $storageId);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- /*
- * Wrong share. Should not be taken by code.
- */
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(2),
- 'share_with' => $qb->expr()->literal('user2'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId),
- 'file_target' => $qb->expr()->literal('wrongTarget'),
- 'permissions' => $qb->expr()->literal(31),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $this->assertEquals(1, $qb->execute());
- /*
- * Correct share. should be taken by code path.
- */
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(2),
- 'share_with' => $qb->expr()->literal('user'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($fileId),
- 'file_target' => $qb->expr()->literal('userTarget'),
- 'permissions' => $qb->expr()->literal(0),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $this->assertEquals(1, $qb->execute());
- $groups = ['sharedWith'];
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user');
- $owner = $this->createMock(IUser::class);
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->createMock(IUser::class);
- $initiator->method('getUID')->willReturn('sharedBy');
- $this->userManager->method('get')->willReturnMap([
- ['user', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
- $share = $this->provider->getSharedWith('user', IShare::TYPE_GROUP, null, -1, 0);
- $this->assertCount(1, $share);
- $share = $share[0];
- $this->assertSame((string)$id, $share->getId());
- $this->assertSame('sharedWith', $share->getSharedWith());
- $this->assertSame('shareOwner', $share->getShareOwner());
- $this->assertSame('sharedBy', $share->getSharedBy());
- $this->assertSame(IShare::TYPE_GROUP, $share->getShareType());
- $this->assertSame(0, $share->getPermissions());
- $this->assertSame('userTarget', $share->getTarget());
- }
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithUserWithNode($storageStringId, $fileName1, $fileName2) {
- $storageId = $this->createTestStorageEntry($storageStringId);
- $fileId = $this->createTestFileEntry($fileName1, $storageId);
- $fileId2 = $this->createTestFileEntry($fileName2, $storageId);
- $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user1',
- 'file', $fileId, 'myTarget', 31, null, null, null);
- $id = $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user1',
- 'file', $fileId2, 'myTarget', 31, null, null, null);
- $user0 = $this->createMock(IUser::class);
- $user0->method('getUID')->willReturn('user0');
- $user0->method('getDisplayName')->willReturn('user0');
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user0->method('getDisplayName')->willReturn('user0');
- $this->userManager->method('get')->willReturnMap([
- ['user0', $user0],
- ['user1', $user1],
- ]);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn($fileId2);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId2)->willReturn([$file]);
- $share = $this->provider->getSharedWith('user0', IShare::TYPE_USER, $file, -1, 0);
- $this->assertCount(1, $share);
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertSame('user0', $share->getSharedWith());
- $this->assertSame('user1', $share->getShareOwner());
- $this->assertSame('user1', $share->getSharedBy());
- $this->assertSame($file, $share->getNode());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- }
- /**
- * @dataProvider storageAndFileNameProvider
- */
- public function testGetSharedWithGroupWithNode($storageStringId, $fileName1, $fileName2) {
- $storageId = $this->createTestStorageEntry($storageStringId);
- $fileId = $this->createTestFileEntry($fileName1, $storageId);
- $fileId2 = $this->createTestFileEntry($fileName2, $storageId);
- $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user1',
- 'file', $fileId, 'myTarget', 31, null, null, null);
- $id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user1',
- 'file', $fileId2, 'myTarget', 31, null, null, null);
- $user0 = $this->createMock(IUser::class);
- $user0->method('getUID')->willReturn('user0');
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $this->userManager->method('get')->willReturnMap([
- ['user0', $user0],
- ['user1', $user1],
- ]);
- $this->groupManager->method('getUserGroupIds')->with($user0)->willReturn(['group0']);
- $node = $this->createMock(Folder::class);
- $node->method('getId')->willReturn($fileId2);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with($fileId2)->willReturn([$node]);
- $share = $this->provider->getSharedWith('user0', IShare::TYPE_GROUP, $node, -1, 0);
- $this->assertCount(1, $share);
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertSame('group0', $share->getSharedWith());
- $this->assertSame('user1', $share->getShareOwner());
- $this->assertSame('user1', $share->getSharedBy());
- $this->assertSame($node, $share->getNode());
- $this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
- }
- public function shareTypesProvider() {
- return [
- [IShare::TYPE_USER, false],
- [IShare::TYPE_GROUP, false],
- [IShare::TYPE_USER, true],
- [IShare::TYPE_GROUP, true],
- ];
- }
- /**
- * @dataProvider shareTypesProvider
- */
- public function testGetSharedWithWithDeletedFile($shareType, $trashed) {
- if ($trashed) {
- // exists in database but is in trash
- $storageId = $this->createTestStorageEntry('home::shareOwner');
- $deletedFileId = $this->createTestFileEntry('files_trashbin/files/test.txt.d1465553223', $storageId);
- } else {
- // fileid that doesn't exist in the database
- $deletedFileId = 123;
- }
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal($shareType),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal($deletedFileId),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with($deletedFileId)->willReturn([$file]);
- $groups = [];
- foreach (range(0, 100) as $i) {
- $groups[] = 'group'.$i;
- }
- $groups[] = 'sharedWith';
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('sharedWith');
- $owner = $this->createMock(IUser::class);
- $owner->method('getUID')->willReturn('shareOwner');
- $initiator = $this->createMock(IUser::class);
- $initiator->method('getUID')->willReturn('sharedBy');
- $this->userManager->method('get')->willReturnMap([
- ['sharedWith', $user],
- ['shareOwner', $owner],
- ['sharedBy', $initiator],
- ]);
- $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);
- $share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1, 0);
- $this->assertCount(0, $share);
- }
- public function testGetSharesBy() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy2'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('userTarget'),
- 'permissions' => $qb->expr()->literal(0),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $this->assertEquals(1, $qb->execute());
- $file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, null, false, 1, 0);
- $this->assertCount(1, $share);
- /** @var IShare $share */
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetSharesNode() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(43),
- 'file_target' => $qb->expr()->literal('userTarget'),
- 'permissions' => $qb->expr()->literal(0),
- 'parent' => $qb->expr()->literal($id),
- ]);
- $this->assertEquals(1, $qb->execute());
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharesBy('sharedBy', IShare::TYPE_USER, $file, false, 1, 0);
- $this->assertCount(1, $share);
- /** @var IShare $share */
- $share = $share[0];
- $this->assertEquals($id, $share->getId());
- $this->assertEquals('sharedWith', $share->getSharedWith());
- $this->assertEquals('shareOwner', $share->getShareOwner());
- $this->assertEquals('sharedBy', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals('myTarget', $share->getTarget());
- }
- public function testGetSharesReshare() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('shareOwner'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id1 = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('shareOwner'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('userTarget'),
- 'permissions' => $qb->expr()->literal(0),
- ]);
- $this->assertEquals(1, $qb->execute());
- $id2 = $qb->getLastInsertId();
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
- $this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $shares = $this->provider->getSharesBy('shareOwner', IShare::TYPE_USER, null, true, -1, 0);
- $this->assertCount(2, $shares);
- /** @var IShare $share */
- $share = $shares[0];
- $this->assertEquals($id1, $share->getId());
- $this->assertSame('sharedWith', $share->getSharedWith());
- $this->assertSame('shareOwner', $share->getShareOwner());
- $this->assertSame('shareOwner', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals('myTarget', $share->getTarget());
- $share = $shares[1];
- $this->assertEquals($id2, $share->getId());
- $this->assertSame('sharedWith', $share->getSharedWith());
- $this->assertSame('shareOwner', $share->getShareOwner());
- $this->assertSame('sharedBy', $share->getSharedBy());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals(0, $share->getPermissions());
- $this->assertEquals('userTarget', $share->getTarget());
- }
- public function testDeleteFromSelfGroupNoCustomShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('group'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group');
- $group->method('inGroup')->with($user2)->willReturn(true);
- $group->method('getDisplayName')->willReturn('group-displayname');
- $this->groupManager->method('get')->with('group')->willReturn($group);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, 'user2');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(2)))
- ->execute();
- $shares = $stmt->fetchAll();
- $stmt->closeCursor();
- $this->assertCount(1, $shares);
- $share2 = $shares[0];
- $this->assertEquals($id, $share2['parent']);
- $this->assertEquals(0, $share2['permissions']);
- $this->assertEquals('user2', $share2['share_with']);
- }
- public function testDeleteFromSelfGroupAlreadyCustomShare() {
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('group'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(2),
- 'share_with' => $qb->expr()->literal('user2'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2),
- 'parent' => $qb->expr()->literal($id),
- ])->execute();
- $this->assertEquals(1, $stmt);
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group');
- $group->method('inGroup')->with($user2)->willReturn(true);
- $group->method('getDisplayName')->willReturn('group-displayname');
- $this->groupManager->method('get')->with('group')->willReturn($group);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, 'user2');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(2)))
- ->execute();
- $shares = $stmt->fetchAll();
- $stmt->closeCursor();
- $this->assertCount(1, $shares);
- $share2 = $shares[0];
- $this->assertEquals($id, $share2['parent']);
- $this->assertEquals(0, $share2['permissions']);
- $this->assertEquals('user2', $share2['share_with']);
- }
- public function testDeleteFromSelfGroupUserNotInGroup() {
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('group'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group');
- $group->method('inGroup')->with($user2)->willReturn(false);
- $group->method('getDisplayName')->willReturn('group-displayname');
- $this->groupManager->method('get')->with('group')->willReturn($group);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, 'user2');
- }
- public function testDeleteFromSelfGroupDoesNotExist() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
- $this->expectExceptionMessage('Group "group" does not exist');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('group'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $this->groupManager->method('get')->with('group')->willReturn(null);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, 'user2');
- }
- public function testDeleteFromSelfUser() {
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('user2'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user1->method('getDisplayName')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $user2->method('getDisplayName')->willReturn('user2');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, 'user2');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
- ->execute();
- $shares = $stmt->fetchAll();
- $stmt->closeCursor();
- $this->assertCount(0, $shares);
- }
- public function testDeleteFromSelfUserNotRecipient() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
- $this->expectExceptionMessage('Recipient does not match');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('user2'),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2)
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user1->method('getDisplayName')->willReturn('user1');
- $user2 = $this->createMock(IUser::class);
- $user2->method('getUID')->willReturn('user2');
- $user2->method('getDisplayName')->willReturn('user2');
- $user3 = $this->createMock(IUser::class);
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ['user2', $user2],
- ]);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user3);
- }
- public function testDeleteFromSelfLink() {
- $this->expectException(\OC\Share20\Exception\ProviderException::class);
- $this->expectExceptionMessage('Invalid shareType');
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
- 'uid_owner' => $qb->expr()->literal('user1'),
- 'uid_initiator' => $qb->expr()->literal('user1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(1),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(2),
- 'token' => $qb->expr()->literal('token'),
- ])->execute();
- $this->assertEquals(1, $stmt);
- $id = $qb->getLastInsertId();
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $this->userManager->method('get')->willReturnMap([
- ['user1', $user1],
- ]);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->with(1)->willReturn([$file]);
- $share = $this->provider->getShareById($id);
- $this->provider->deleteFromSelf($share, $user1);
- }
- public function testUpdateUser() {
- $id = $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user2',
- 'file', 42, 'target', 31, null, null);
- $users = [];
- for ($i = 0; $i < 6; $i++) {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $user->method('getDisplayName')->willReturn('user' . $i);
- $users['user'.$i] = $user;
- }
- $this->userManager->method('get')->willReturnCallback(
- function ($userId) use ($users) {
- return $users[$userId];
- }
- );
- $file1 = $this->createMock(File::class);
- $file1->method('getId')->willReturn(42);
- $file2 = $this->createMock(File::class);
- $file2->method('getId')->willReturn(43);
- $folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
- $folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->willReturnMap([
- ['user2', $folder1],
- ['user5', $folder2],
- ]);
- $share = $this->provider->getShareById($id);
- $share->setSharedWith('user3');
- $share->setSharedBy('user4');
- $share->setShareOwner('user5');
- $share->setNode($file2);
- $share->setPermissions(1);
- $share2 = $this->provider->update($share);
- $this->assertEquals($id, $share2->getId());
- $this->assertSame('user3', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $share2 = $this->provider->getShareById($id);
- $this->assertEquals($id, $share2->getId());
- $this->assertSame('user3', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- }
- public function testUpdateLink() {
- $id = $this->addShareToDB(IShare::TYPE_LINK, null, 'user1', 'user2',
- 'file', 42, 'target', 31, null, null);
- $users = [];
- for ($i = 0; $i < 6; $i++) {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
- }
- $this->userManager->method('get')->willReturnCallback(
- function ($userId) use ($users) {
- return $users[$userId];
- }
- );
- $file1 = $this->createMock(File::class);
- $file1->method('getId')->willReturn(42);
- $file2 = $this->createMock(File::class);
- $file2->method('getId')->willReturn(43);
- $folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
- $folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->willReturnMap([
- ['user2', $folder1],
- ['user5', $folder2],
- ]);
- $share = $this->provider->getShareById($id);
- $share->setPassword('password');
- $share->setSendPasswordByTalk(true);
- $share->setSharedBy('user4');
- $share->setShareOwner('user5');
- $share->setNode($file2);
- $share->setPermissions(1);
- $share2 = $this->provider->update($share);
- $this->assertEquals($id, $share2->getId());
- $this->assertEquals('password', $share2->getPassword());
- $this->assertSame(true, $share2->getSendPasswordByTalk());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $share2 = $this->provider->getShareById($id);
- $this->assertEquals($id, $share2->getId());
- $this->assertEquals('password', $share2->getPassword());
- $this->assertSame(true, $share2->getSendPasswordByTalk());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- }
- public function testUpdateLinkRemovePassword() {
- $id = $this->addShareToDB(IShare::TYPE_LINK, 'foo', 'user1', 'user2',
- 'file', 42, 'target', 31, null, null);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->update('share');
- $qb->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
- $qb->set('password', $qb->createNamedParameter('password'));
- $this->assertEquals(1, $qb->execute());
- $users = [];
- for ($i = 0; $i < 6; $i++) {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
- }
- $this->userManager->method('get')->willReturnCallback(
- function ($userId) use ($users) {
- return $users[$userId];
- }
- );
- $file1 = $this->createMock(File::class);
- $file1->method('getId')->willReturn(42);
- $file2 = $this->createMock(File::class);
- $file2->method('getId')->willReturn(43);
- $folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
- $folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->willReturnMap([
- ['user2', $folder1],
- ['user5', $folder2],
- ]);
- $share = $this->provider->getShareById($id);
- $share->setPassword(null);
- $share->setSharedBy('user4');
- $share->setShareOwner('user5');
- $share->setNode($file2);
- $share->setPermissions(1);
- $share2 = $this->provider->update($share);
- $this->assertEquals($id, $share2->getId());
- $this->assertEquals(null, $share2->getPassword());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $share2 = $this->provider->getShareById($id);
- $this->assertEquals($id, $share2->getId());
- $this->assertEquals(null, $share2->getPassword());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- }
- public function testUpdateGroupNoSub() {
- $id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user2',
- 'file', 42, 'target', 31, null, null);
- $users = [];
- for ($i = 0; $i < 6; $i++) {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
- }
- $this->userManager->method('get')->willReturnCallback(
- function ($userId) use ($users) {
- return $users[$userId];
- }
- );
- $groups = [];
- for ($i = 0; $i < 2; $i++) {
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group'.$i);
- $group->method('getDisplayName')->willReturn('group-displayname' . $i);
- $groups['group'.$i] = $group;
- }
- $this->groupManager->method('get')->willReturnCallback(
- function ($groupId) use ($groups) {
- return $groups[$groupId];
- }
- );
- $file1 = $this->createMock(File::class);
- $file1->method('getId')->willReturn(42);
- $file2 = $this->createMock(File::class);
- $file2->method('getId')->willReturn(43);
- $folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
- $folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->willReturnMap([
- ['user2', $folder1],
- ['user5', $folder2],
- ]);
- $share = $this->provider->getShareById($id);
- $share->setSharedWith('group0');
- $share->setSharedBy('user4');
- $share->setShareOwner('user5');
- $share->setNode($file2);
- $share->setPermissions(1);
- $share2 = $this->provider->update($share);
- $this->assertEquals($id, $share2->getId());
- // Group shares do not allow updating the recipient
- $this->assertSame('group0', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $share2 = $this->provider->getShareById($id);
- $this->assertEquals($id, $share2->getId());
- // Group shares do not allow updating the recipient
- $this->assertSame('group0', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- }
- public function testUpdateGroupSubShares() {
- $id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user2',
- 'file', 42, 'target', 31, null, null);
- $id2 = $this->addShareToDB(2, 'user0', 'user1', 'user2',
- 'file', 42, 'mytarget', 31, null, null, $id);
- $id3 = $this->addShareToDB(2, 'user3', 'user1', 'user2',
- 'file', 42, 'mytarget2', 0, null, null, $id);
- $users = [];
- for ($i = 0; $i < 6; $i++) {
- $user = $this->createMock(IUser::class);
- $user->method('getUID')->willReturn('user'.$i);
- $users['user'.$i] = $user;
- }
- $this->userManager->method('get')->willReturnCallback(
- function ($userId) use ($users) {
- return $users[$userId];
- }
- );
- $groups = [];
- for ($i = 0; $i < 2; $i++) {
- $group = $this->createMock(IGroup::class);
- $group->method('getGID')->willReturn('group'.$i);
- $group->method('getDisplayName')->willReturn('group-displayname'.$i);
- $groups['group'.$i] = $group;
- }
- $this->groupManager->method('get')->willReturnCallback(
- function ($groupId) use ($groups) {
- return $groups[$groupId];
- }
- );
- $file1 = $this->createMock(File::class);
- $file1->method('getId')->willReturn(42);
- $file2 = $this->createMock(File::class);
- $file2->method('getId')->willReturn(43);
- $folder1 = $this->createMock(Folder::class);
- $folder1->method('getById')->with(42)->willReturn([$file1]);
- $folder2 = $this->createMock(Folder::class);
- $folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->willReturnMap([
- ['user2', $folder1],
- ['user5', $folder2],
- ]);
- $share = $this->provider->getShareById($id);
- $share->setSharedWith('group0');
- $share->setSharedBy('user4');
- $share->setShareOwner('user5');
- $share->setNode($file2);
- $share->setPermissions(1);
- $share2 = $this->provider->update($share);
- $this->assertEquals($id, $share2->getId());
- // Group shares do not allow updating the recipient
- $this->assertSame('group0', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $share2 = $this->provider->getShareById($id);
- $this->assertEquals($id, $share2->getId());
- // Group shares do not allow updating the recipient
- $this->assertSame('group0', $share2->getSharedWith());
- $this->assertSame('user4', $share2->getSharedBy());
- $this->assertSame('user5', $share2->getShareOwner());
- $this->assertSame(1, $share2->getPermissions());
- $qb = $this->dbConn->getQueryBuilder();
- $stmt = $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('parent', $qb->createNamedParameter($id)))
- ->orderBy('id')
- ->execute();
- $shares = $stmt->fetchAll();
- $this->assertSame('user0', $shares[0]['share_with']);
- $this->assertSame('user4', $shares[0]['uid_initiator']);
- $this->assertSame('user5', $shares[0]['uid_owner']);
- $this->assertSame(1, (int)$shares[0]['permissions']);
- $this->assertSame('user3', $shares[1]['share_with']);
- $this->assertSame('user4', $shares[1]['uid_initiator']);
- $this->assertSame('user5', $shares[1]['uid_owner']);
- $this->assertSame(0, (int)$shares[1]['permissions']);
- $stmt->closeCursor();
- }
- public function testMoveUserShare() {
- $id = $this->addShareToDB(IShare::TYPE_USER, 'user0', 'user1', 'user1', 'file',
- 42, 'mytaret', 31, null, null);
- $user0 = $this->createMock(IUser::class);
- $user0->method('getUID')->willReturn('user0');
- $user0->method('getDisplayName')->willReturn('user0');
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $user1->method('getDisplayName')->willReturn('user1');
- $this->userManager->method('get')->willReturnMap([
- ['user0', $user0],
- ['user1', $user1],
- ]);
- $file = $this->createMock(File::class);
- $file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$file]);
- $share = $this->provider->getShareById($id, null);
- $share->setTarget('/newTarget');
- $this->provider->move($share, $user0);
- $share = $this->provider->getShareById($id, null);
- $this->assertSame('/newTarget', $share->getTarget());
- }
- public function testMoveGroupShare() {
- $id = $this->addShareToDB(IShare::TYPE_GROUP, 'group0', 'user1', 'user1', 'file',
- 42, 'mytaret', 31, null, null);
- $user0 = $this->createMock(IUser::class);
- $user0->method('getUID')->willReturn('user0');
- $user1 = $this->createMock(IUser::class);
- $user1->method('getUID')->willReturn('user1');
- $group0 = $this->createMock(IGroup::class);
- $group0->method('getGID')->willReturn('group0');
- $group0->method('inGroup')->with($user0)->willReturn(true);
- $group0->method('getDisplayName')->willReturn('group0-displayname');
- $this->groupManager->method('get')->with('group0')->willReturn($group0);
- $this->userManager->method('get')->willReturnMap([
- ['user0', $user0],
- ['user1', $user1],
- ]);
- $folder = $this->createMock(Folder::class);
- $folder->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
- $this->rootFolder->method('getById')->willReturn([$folder]);
- $share = $this->provider->getShareById($id, 'user0');
- $share->setTarget('/newTarget');
- $this->provider->move($share, 'user0');
- $share = $this->provider->getShareById($id, 'user0');
- $this->assertSame('/newTarget', $share->getTarget());
- $share->setTarget('/ultraNewTarget');
- $this->provider->move($share, 'user0');
- $share = $this->provider->getShareById($id, 'user0');
- $this->assertSame('/ultraNewTarget', $share->getTarget());
- }
- public function dataDeleteUser() {
- return [
- [IShare::TYPE_USER, 'a', 'b', 'c', 'a', true],
- [IShare::TYPE_USER, 'a', 'b', 'c', 'b', false],
- [IShare::TYPE_USER, 'a', 'b', 'c', 'c', true],
- [IShare::TYPE_USER, 'a', 'b', 'c', 'd', false],
- [IShare::TYPE_GROUP, 'a', 'b', 'c', 'a', true],
- [IShare::TYPE_GROUP, 'a', 'b', 'c', 'b', false],
- // The group c is still valid but user c is deleted so group share stays
- [IShare::TYPE_GROUP, 'a', 'b', 'c', 'c', false],
- [IShare::TYPE_GROUP, 'a', 'b', 'c', 'd', false],
- [IShare::TYPE_LINK, 'a', 'b', 'c', 'a', true],
- // To avoid invisible link shares delete initiated link shares as well (see #22327)
- [IShare::TYPE_LINK, 'a', 'b', 'c', 'b', true],
- [IShare::TYPE_LINK, 'a', 'b', 'c', 'c', false],
- [IShare::TYPE_LINK, 'a', 'b', 'c', 'd', false],
- ];
- }
- /**
- * @dataProvider dataDeleteUser
- *
- * @param int $type The shareType (user/group/link)
- * @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
- */
- public function testDeleteUser($type, $owner, $initiator, $recipient, $deletedUser, $rowDeleted) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter($type))
- ->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))
- ->execute();
- $id = $qb->getLastInsertId();
- $this->provider->userDeleted($deletedUser, $type);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where(
- $qb->expr()->eq('id', $qb->createNamedParameter($id))
- );
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount($rowDeleted ? 0 : 1, $data);
- }
- public function dataDeleteUserGroup() {
- return [
- ['a', 'b', 'c', 'a', true, true],
- ['a', 'b', 'c', 'b', false, false],
- ['a', 'b', 'c', 'c', false, true],
- ['a', 'b', 'c', 'd', false, false],
- ];
- }
- /**
- * @dataProvider dataDeleteUserGroup
- *
- * @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 usergroup share (uid)
- * @param string $deletedUser The user that is deleted
- * @param bool $groupShareDeleted
- * @param bool $userGroupShareDeleted
- */
- public function testDeleteUserGroup($owner, $initiator, $recipient, $deletedUser, $groupShareDeleted, $userGroupShareDeleted) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP))
- ->setValue('uid_owner', $qb->createNamedParameter($owner))
- ->setValue('uid_initiator', $qb->createNamedParameter($initiator))
- ->setValue('share_with', $qb->createNamedParameter('group'))
- ->setValue('item_type', $qb->createNamedParameter('file'))
- ->setValue('item_source', $qb->createNamedParameter(42))
- ->setValue('file_source', $qb->createNamedParameter(42))
- ->execute();
- $groupId = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter(2))
- ->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))
- ->execute();
- $userGroupId = $qb->getLastInsertId();
- $this->provider->userDeleted($deletedUser, IShare::TYPE_GROUP);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where(
- $qb->expr()->eq('id', $qb->createNamedParameter($userGroupId))
- );
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount($userGroupShareDeleted ? 0 : 1, $data);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where(
- $qb->expr()->eq('id', $qb->createNamedParameter($groupId))
- );
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount($groupShareDeleted ? 0 : 1, $data);
- }
- public function dataGroupDeleted() {
- return [
- [
- [
- 'type' => IShare::TYPE_USER,
- 'recipient' => 'user',
- 'children' => []
- ], 'group', false
- ],
- [
- [
- 'type' => IShare::TYPE_USER,
- 'recipient' => 'user',
- 'children' => []
- ], 'user', false
- ],
- [
- [
- 'type' => IShare::TYPE_LINK,
- 'recipient' => 'user',
- 'children' => []
- ], 'group', false
- ],
- [
- [
- 'type' => IShare::TYPE_GROUP,
- 'recipient' => 'group1',
- 'children' => [
- 'foo',
- 'bar'
- ]
- ], 'group2', false
- ],
- [
- [
- 'type' => IShare::TYPE_GROUP,
- 'recipient' => 'group1',
- 'children' => [
- 'foo',
- 'bar'
- ]
- ], 'group1', true
- ],
- ];
- }
- /**
- * @dataProvider dataGroupDeleted
- *
- * @param $shares
- * @param $groupToDelete
- * @param $shouldBeDeleted
- */
- public function testGroupDeleted($shares, $groupToDelete, $shouldBeDeleted) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter($shares['type']))
- ->setValue('uid_owner', $qb->createNamedParameter('owner'))
- ->setValue('uid_initiator', $qb->createNamedParameter('initiator'))
- ->setValue('share_with', $qb->createNamedParameter($shares['recipient']))
- ->setValue('item_type', $qb->createNamedParameter('file'))
- ->setValue('item_source', $qb->createNamedParameter(42))
- ->setValue('file_source', $qb->createNamedParameter(42))
- ->execute();
- $ids = [$qb->getLastInsertId()];
- foreach ($shares['children'] as $child) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter(2))
- ->setValue('uid_owner', $qb->createNamedParameter('owner'))
- ->setValue('uid_initiator', $qb->createNamedParameter('initiator'))
- ->setValue('share_with', $qb->createNamedParameter($child))
- ->setValue('item_type', $qb->createNamedParameter('file'))
- ->setValue('item_source', $qb->createNamedParameter(42))
- ->setValue('file_source', $qb->createNamedParameter(42))
- ->setValue('parent', $qb->createNamedParameter($ids[0]))
- ->execute();
- $ids[] = $qb->getLastInsertId();
- }
- $this->provider->groupDeleted($groupToDelete);
- $qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('*')
- ->from('share')
- ->where($qb->expr()->in('id', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
- ->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount($shouldBeDeleted ? 0 : count($ids), $data);
- }
- public function dataUserDeletedFromGroup() {
- return [
- ['group1', 'user1', true],
- ['group1', 'user2', false],
- ['group2', 'user1', false],
- ];
- }
- /**
- * Given a group share with 'group1'
- * And a user specific group share with 'user1'.
- * User $user is deleted from group $gid.
- *
- * @dataProvider dataUserDeletedFromGroup
- *
- * @param string $group
- * @param string $user
- * @param bool $toDelete
- */
- public function testUserDeletedFromGroup($group, $user, $toDelete) {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP))
- ->setValue('uid_owner', $qb->createNamedParameter('owner'))
- ->setValue('uid_initiator', $qb->createNamedParameter('initiator'))
- ->setValue('share_with', $qb->createNamedParameter('group1'))
- ->setValue('item_type', $qb->createNamedParameter('file'))
- ->setValue('item_source', $qb->createNamedParameter(42))
- ->setValue('file_source', $qb->createNamedParameter(42));
- $qb->execute();
- $id1 = $qb->getLastInsertId();
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->setValue('share_type', $qb->createNamedParameter(2))
- ->setValue('uid_owner', $qb->createNamedParameter('owner'))
- ->setValue('uid_initiator', $qb->createNamedParameter('initiator'))
- ->setValue('share_with', $qb->createNamedParameter('user1'))
- ->setValue('item_type', $qb->createNamedParameter('file'))
- ->setValue('item_source', $qb->createNamedParameter(42))
- ->setValue('file_source', $qb->createNamedParameter(42))
- ->setValue('parent', $qb->createNamedParameter($id1));
- $qb->execute();
- $id2 = $qb->getLastInsertId();
- $this->provider->userDeletedFromGroup($user, $group);
- $qb = $this->dbConn->getQueryBuilder();
- $qb->select('*')
- ->from('share')
- ->where($qb->expr()->eq('id', $qb->createNamedParameter($id2)));
- $cursor = $qb->execute();
- $data = $cursor->fetchAll();
- $cursor->closeCursor();
- $this->assertCount($toDelete ? 0 : 1, $data);
- }
- public function testGetSharesInFolder() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
- $provider = new DefaultShareProvider(
- $this->dbConn,
- $userManager,
- $groupManager,
- $rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- );
- $password = md5(time());
- $u1 = $userManager->createUser('testShare1', $password);
- $u2 = $userManager->createUser('testShare2', $password);
- $u3 = $userManager->createUser('testShare3', $password);
- $g1 = $groupManager->createGroup('group1');
- $u1Folder = $rootFolder->getUserFolder($u1->getUID());
- $folder1 = $u1Folder->newFolder('foo');
- $file1 = $folder1->newFile('bar');
- $folder2 = $folder1->newFolder('baz');
- $shareManager = \OC::$server->getShareManager();
- $share1 = $shareManager->newShare();
- $share1->setNode($folder1)
- ->setSharedBy($u1->getUID())
- ->setSharedWith($u2->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share1 = $this->provider->create($share1);
- $share2 = $shareManager->newShare();
- $share2->setNode($file1)
- ->setSharedBy($u2->getUID())
- ->setSharedWith($u3->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share2 = $this->provider->create($share2);
- $share3 = $shareManager->newShare();
- $share3->setNode($folder2)
- ->setSharedBy($u2->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share3 = $this->provider->create($share3);
- $share4 = $shareManager->newShare();
- $share4->setNode($folder2)
- ->setSharedBy($u1->getUID())
- ->setSharedWith($g1->getGID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share4 = $this->provider->create($share4);
- $result = $provider->getSharesInFolder($u1->getUID(), $folder1, false);
- $this->assertCount(1, $result);
- $shares = array_pop($result);
- $this->assertCount(1, $shares);
- $this->assertSame($folder2->getId(), $shares[0]->getNodeId());
- $result = $provider->getSharesInFolder($u1->getUID(), $folder1, true);
- $this->assertCount(2, $result);
- $file_shares = $result[$file1->getId()];
- $this->assertCount(1, $file_shares);
- $this->assertSame($file1->getId(), $file_shares[0]->getNodeId());
- $this->assertSame(IShare::TYPE_USER, $file_shares[0]->getShareType());
- $folder_shares = $result[$folder2->getId()];
- $this->assertCount(2, $folder_shares);
- $this->assertSame($folder2->getId(), $folder_shares[0]->getNodeId());
- $this->assertSame($folder2->getId(), $folder_shares[1]->getNodeId());
- $this->assertSame(IShare::TYPE_LINK, $folder_shares[0]->getShareType());
- $this->assertSame(IShare::TYPE_GROUP, $folder_shares[1]->getShareType());
- $provider->delete($share1);
- $provider->delete($share2);
- $provider->delete($share3);
- $provider->delete($share4);
- $u1->delete();
- $u2->delete();
- $u3->delete();
- $g1->delete();
- }
- public function testGetAccessListNoCurrentAccessRequired() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
- $provider = new DefaultShareProvider(
- $this->dbConn,
- $userManager,
- $groupManager,
- $rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- );
- $u1 = $userManager->createUser('testShare1', 'test');
- $u2 = $userManager->createUser('testShare2', 'test');
- $u3 = $userManager->createUser('testShare3', 'test');
- $u4 = $userManager->createUser('testShare4', 'test');
- $u5 = $userManager->createUser('testShare5', 'test');
- $g1 = $groupManager->createGroup('group1');
- $g1->addUser($u3);
- $g1->addUser($u4);
- $u1Folder = $rootFolder->getUserFolder($u1->getUID());
- $folder1 = $u1Folder->newFolder('foo');
- $folder2 = $folder1->newFolder('baz');
- $file1 = $folder2->newFile('bar');
- $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
- $this->assertCount(0, $result['users']);
- $this->assertFalse($result['public']);
- $shareManager = \OC::$server->getShareManager();
- $share1 = $shareManager->newShare();
- $share1->setNode($folder1)
- ->setSharedBy($u1->getUID())
- ->setSharedWith($u2->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share1 = $this->provider->create($share1);
- $share2 = $shareManager->newShare();
- $share2->setNode($folder2)
- ->setSharedBy($u2->getUID())
- ->setSharedWith($g1->getGID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share2 = $this->provider->create($share2);
- $shareManager->deleteFromSelf($share2, $u4->getUID());
- $share3 = $shareManager->newShare();
- $share3->setNode($file1)
- ->setSharedBy($u3->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share3 = $this->provider->create($share3);
- $share4 = $shareManager->newShare();
- $share4->setNode($file1)
- ->setSharedBy($u3->getUID())
- ->setSharedWith($u5->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share4 = $this->provider->create($share4);
- $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
- $this->assertCount(4, $result['users']);
- $this->assertContains('testShare2', $result['users']);
- $this->assertContains('testShare3', $result['users']);
- $this->assertContains('testShare4', $result['users']);
- $this->assertContains('testShare5', $result['users']);
- $this->assertTrue($result['public']);
- $provider->delete($share1);
- $provider->delete($share2);
- $provider->delete($share3);
- $provider->delete($share4);
- $u1->delete();
- $u2->delete();
- $u3->delete();
- $u4->delete();
- $u5->delete();
- $g1->delete();
- }
- public function testGetAccessListCurrentAccessRequired() {
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
- $rootFolder = \OC::$server->getRootFolder();
- $provider = new DefaultShareProvider(
- $this->dbConn,
- $userManager,
- $groupManager,
- $rootFolder,
- $this->mailer,
- $this->defaults,
- $this->l10nFactory,
- $this->urlGenerator,
- $this->timeFactory
- );
- $u1 = $userManager->createUser('testShare1', 'test');
- $u2 = $userManager->createUser('testShare2', 'test');
- $u3 = $userManager->createUser('testShare3', 'test');
- $u4 = $userManager->createUser('testShare4', 'test');
- $u5 = $userManager->createUser('testShare5', 'test');
- $g1 = $groupManager->createGroup('group1');
- $g1->addUser($u3);
- $g1->addUser($u4);
- $u1Folder = $rootFolder->getUserFolder($u1->getUID());
- $folder1 = $u1Folder->newFolder('foo');
- $folder2 = $folder1->newFolder('baz');
- $file1 = $folder2->newFile('bar');
- $result = $provider->getAccessList([$folder1, $folder2, $file1], false);
- $this->assertCount(0, $result['users']);
- $this->assertFalse($result['public']);
- $shareManager = \OC::$server->getShareManager();
- $share1 = $shareManager->newShare();
- $share1->setNode($folder1)
- ->setSharedBy($u1->getUID())
- ->setSharedWith($u2->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share1 = $this->provider->create($share1);
- $share2 = $shareManager->newShare();
- $share2->setNode($folder2)
- ->setSharedBy($u2->getUID())
- ->setSharedWith($g1->getGID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_GROUP)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
- $share2 = $this->provider->create($share2);
- $shareManager->deleteFromSelf($share2, $u4->getUID());
- $share3 = $shareManager->newShare();
- $share3->setNode($file1)
- ->setSharedBy($u3->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_LINK)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share3 = $this->provider->create($share3);
- $share4 = $shareManager->newShare();
- $share4->setNode($file1)
- ->setSharedBy($u3->getUID())
- ->setSharedWith($u5->getUID())
- ->setShareOwner($u1->getUID())
- ->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ);
- $share4 = $this->provider->create($share4);
- $result = $provider->getAccessList([$folder1, $folder2, $file1], true);
- $this->assertCount(3, $result['users']);
- $this->assertArrayHasKey('testShare2', $result['users']);
- $this->assertArrayHasKey('testShare3', $result['users']);
- $this->assertArrayHasKey('testShare5', $result['users']);
- $this->assertTrue($result['public']);
- $provider->delete($share1);
- $provider->delete($share2);
- $provider->delete($share3);
- $provider->delete($share4);
- $u1->delete();
- $u2->delete();
- $u3->delete();
- $u4->delete();
- $u5->delete();
- $g1->delete();
- }
- public function testGetAllShares() {
- $qb = $this->dbConn->getQueryBuilder();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_USER),
- 'share_with' => $qb->expr()->literal('sharedWith1'),
- 'uid_owner' => $qb->expr()->literal('shareOwner1'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy1'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget1'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $qb->execute();
- $id1 = $qb->getLastInsertId();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP),
- 'share_with' => $qb->expr()->literal('sharedWith2'),
- 'uid_owner' => $qb->expr()->literal('shareOwner2'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy2'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(43),
- 'file_target' => $qb->expr()->literal('myTarget2'),
- 'permissions' => $qb->expr()->literal(14),
- ]);
- $qb->execute();
- $id2 = $qb->getLastInsertId();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
- 'token' => $qb->expr()->literal('token3'),
- 'uid_owner' => $qb->expr()->literal('shareOwner3'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy3'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(44),
- 'file_target' => $qb->expr()->literal('myTarget3'),
- 'permissions' => $qb->expr()->literal(15),
- ]);
- $qb->execute();
- $id3 = $qb->getLastInsertId();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_EMAIL),
- 'share_with' => $qb->expr()->literal('shareOwner4'),
- 'token' => $qb->expr()->literal('token4'),
- 'uid_owner' => $qb->expr()->literal('shareOwner4'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy4'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(45),
- 'file_target' => $qb->expr()->literal('myTarget4'),
- 'permissions' => $qb->expr()->literal(16),
- ]);
- $qb->execute();
- $id4 = $qb->getLastInsertId();
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK),
- 'token' => $qb->expr()->literal('token5'),
- 'uid_owner' => $qb->expr()->literal('shareOwner5'),
- 'uid_initiator' => $qb->expr()->literal('sharedBy5'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(46),
- 'file_target' => $qb->expr()->literal('myTarget5'),
- 'permissions' => $qb->expr()->literal(17),
- ]);
- $qb->execute();
- $id5 = $qb->getLastInsertId();
- $ownerPath1 = $this->createMock(File::class);
- $shareOwner1Folder = $this->createMock(Folder::class);
- $shareOwner1Folder->method('getById')->willReturn([$ownerPath1]);
- $ownerPath2 = $this->createMock(File::class);
- $shareOwner2Folder = $this->createMock(Folder::class);
- $shareOwner2Folder->method('getById')->willReturn([$ownerPath2]);
- $ownerPath3 = $this->createMock(File::class);
- $shareOwner3Folder = $this->createMock(Folder::class);
- $shareOwner3Folder->method('getById')->willReturn([$ownerPath3]);
- $ownerPath4 = $this->createMock(File::class);
- $shareOwner4Folder = $this->createMock(Folder::class);
- $shareOwner4Folder->method('getById')->willReturn([$ownerPath4]);
- $ownerPath5 = $this->createMock(File::class);
- $shareOwner5Folder = $this->createMock(Folder::class);
- $shareOwner5Folder->method('getById')->willReturn([$ownerPath5]);
- $this->rootFolder
- ->method('getUserFolder')
- ->willReturnMap(
- [
- ['shareOwner1', $shareOwner1Folder],
- ['shareOwner2', $shareOwner2Folder],
- ['shareOwner3', $shareOwner3Folder],
- ['shareOwner4', $shareOwner4Folder],
- ['shareOwner5', $shareOwner5Folder],
- ]
- );
- $shares = iterator_to_array($this->provider->getAllShares());
- $this->assertEquals(4, count($shares));
- $share = $shares[0];
- // We fetch the node so the root folder is eventually called
- $this->assertEquals($id1, $share->getId());
- $this->assertEquals(IShare::TYPE_USER, $share->getShareType());
- $this->assertEquals('sharedWith1', $share->getSharedWith());
- $this->assertEquals('sharedBy1', $share->getSharedBy());
- $this->assertEquals('shareOwner1', $share->getShareOwner());
- $this->assertEquals($ownerPath1, $share->getNode());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals('myTarget1', $share->getTarget());
- $share = $shares[1];
- $this->assertEquals($id2, $share->getId());
- $this->assertEquals(IShare::TYPE_GROUP, $share->getShareType());
- $this->assertEquals('sharedWith2', $share->getSharedWith());
- $this->assertEquals('sharedBy2', $share->getSharedBy());
- $this->assertEquals('shareOwner2', $share->getShareOwner());
- $this->assertEquals($ownerPath2, $share->getNode());
- $this->assertEquals(14, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals('myTarget2', $share->getTarget());
- $share = $shares[2];
- $this->assertEquals($id3, $share->getId());
- $this->assertEquals(IShare::TYPE_LINK, $share->getShareType());
- $this->assertEquals(null, $share->getSharedWith());
- $this->assertEquals('sharedBy3', $share->getSharedBy());
- $this->assertEquals('shareOwner3', $share->getShareOwner());
- $this->assertEquals($ownerPath3, $share->getNode());
- $this->assertEquals(15, $share->getPermissions());
- $this->assertEquals('token3', $share->getToken());
- $this->assertEquals('myTarget3', $share->getTarget());
- $share = $shares[3];
- $this->assertEquals($id5, $share->getId());
- $this->assertEquals(IShare::TYPE_LINK, $share->getShareType());
- $this->assertEquals(null, $share->getSharedWith());
- $this->assertEquals('sharedBy5', $share->getSharedBy());
- $this->assertEquals('shareOwner5', $share->getShareOwner());
- $this->assertEquals($ownerPath5, $share->getNode());
- $this->assertEquals(17, $share->getPermissions());
- $this->assertEquals('token5', $share->getToken());
- $this->assertEquals('myTarget5', $share->getTarget());
- }
- }
|