use OCP\AppFramework\Http\Template\PublicTemplateResponse;
use OCP\AppFramework\Http\Template\SimpleMenuAction;
use OCP\Constants;
+use OCP\Files\File;
use OCP\Files\NotFoundException;
use OCP\Files\Storage;
use OCP\IConfig;
$this->shareController->setToken('token');
- $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner = $this->createMock(IUser::class);
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
+ $owner->method('isEnabled')->willReturn(true);
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
+ $initiator = $this->createMock(IUser::class);
+ $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
+ $initiator->method('getUID')->willReturn('initiatorUID');
+ $initiator->method('isEnabled')->willReturn(true);
+
+ $file = $this->createMock(File::class);
$file->method('getName')->willReturn('file1.txt');
$file->method('getMimetype')->willReturn('text/plain');
$file->method('getSize')->willReturn(33);
$share->setId(42);
$share->setPassword('password')
->setShareOwner('ownerUID')
+ ->setSharedBy('initiatorUID')
->setNode($file)
->setNote($note)
->setTarget('/file1.txt');
->with('core', 'shareapi_public_link_disclaimertext', null)
->willReturn('My disclaimer text');
- $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
+ $this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
+ if ($uid === 'ownerUID') {
+ return $owner;
+ }
+ if ($uid === 'initiatorUID') {
+ return $initiator;
+ }
+ return null;
+ });
$this->eventDispatcher->expects($this->once())
->method('dispatch')
$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
+ $owner->method('isEnabled')->willReturn(true);
+
+ $initiator = $this->createMock(IUser::class);
+ $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
+ $initiator->method('getUID')->willReturn('initiatorUID');
+ $initiator->method('isEnabled')->willReturn(true);
$file = $this->getMockBuilder('OCP\Files\File')->getMock();
$file->method('getName')->willReturn('file1.txt');
$share->setId(42);
$share->setPassword('password')
->setShareOwner('ownerUID')
+ ->setSharedBy('initiatorUID')
->setNode($file)
->setNote($note)
->setTarget('/file1.txt')
->with('core', 'shareapi_public_link_disclaimertext', null)
->willReturn('My disclaimer text');
- $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
+ $this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
+ if ($uid === 'ownerUID') {
+ return $owner;
+ }
+ if ($uid === 'initiatorUID') {
+ return $initiator;
+ }
+ return null;
+ });
$this->eventDispatcher->expects($this->once())
->method('dispatch')
$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
+ $owner->method('isEnabled')->willReturn(true);
+
+ $initiator = $this->createMock(IUser::class);
+ $initiator->method('getDisplayName')->willReturn('initiatorDisplay');
+ $initiator->method('getUID')->willReturn('initiatorUID');
+ $initiator->method('isEnabled')->willReturn(true);
/* @var MockObject|Storage $storage */
$storage = $this->getMockBuilder(Storage::class)
$share->setId(42);
$share->setPermissions(Constants::PERMISSION_CREATE)
->setShareOwner('ownerUID')
+ ->setSharedBy('initiatorUID')
->setNode($folder)
->setTarget('/fileDrop');
->with('token')
->willReturn($share);
- $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
+ $this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
+ if ($uid === 'ownerUID') {
+ return $owner;
+ }
+ if ($uid === 'initiatorUID') {
+ return $initiator;
+ }
+ return null;
+ });
$this->l10n->expects($this->any())
->method('t')
self::assertEquals($expectedResponse, $response);
}
-
+
public function testShowShareInvalid() {
$this->expectException(\OCP\Files\NotFoundException::class);
$expectedResponse = new DataResponse('Share is read-only');
$this->assertEquals($expectedResponse, $response);
}
+
+ public function testDisabledOwner() {
+ $this->shareController->setToken('token');
+
+ $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner->method('isEnabled')->willReturn(false);
+
+ $initiator = $this->createMock(IUser::class);
+ $initiator->method('isEnabled')->willReturn(false);
+
+ /* @var MockObject|Folder $folder */
+ $folder = $this->createMock(Folder::class);
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
+ $share->setPermissions(Constants::PERMISSION_CREATE)
+ ->setShareOwner('ownerUID')
+ ->setSharedBy('initiatorUID')
+ ->setNode($folder)
+ ->setTarget('/share');
+
+ $this->shareManager
+ ->expects($this->once())
+ ->method('getShareByToken')
+ ->with('token')
+ ->willReturn($share);
+
+ $this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
+ if ($uid === 'ownerUID') {
+ return $owner;
+ }
+ if ($uid === 'initiatorUID') {
+ return $initiator;
+ }
+ return null;
+ });
+
+ $this->expectException(NotFoundException::class);
+
+ $this->shareController->showShare();
+ }
+
+ public function testDisabledInitiator() {
+ $this->shareController->setToken('token');
+
+ $owner = $this->getMockBuilder(IUser::class)->getMock();
+ $owner->method('isEnabled')->willReturn(false);
+
+ $initiator = $this->createMock(IUser::class);
+ $initiator->method('isEnabled')->willReturn(true);
+
+ /* @var MockObject|Folder $folder */
+ $folder = $this->createMock(Folder::class);
+
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
+ $share->setPermissions(Constants::PERMISSION_CREATE)
+ ->setShareOwner('ownerUID')
+ ->setSharedBy('initiatorUID')
+ ->setNode($folder)
+ ->setTarget('/share');
+
+ $this->shareManager
+ ->expects($this->once())
+ ->method('getShareByToken')
+ ->with('token')
+ ->willReturn($share);
+
+ $this->userManager->method('get')->willReturnCallback(function(string $uid) use ($owner, $initiator) {
+ if ($uid === 'ownerUID') {
+ return $owner;
+ }
+ if ($uid === 'initiatorUID') {
+ return $initiator;
+ }
+ return null;
+ });
+
+ $this->expectException(NotFoundException::class);
+
+ $this->shareController->showShare();
+ }
}