Exemplo n.º 1
0
 public function testUpdate()
 {
     $share = $this->shareManager->newShare();
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->method('getId')->willReturn(42);
     $node->method('getName')->willReturn('myFile');
     $share->setSharedWith('*****@*****.**')->setSharedBy('sharedBy')->setShareOwner('shareOwner')->setPermissions(19)->setNode($node);
     $this->tokenHandler->method('generateToken')->willReturn('token');
     $this->notifications->expects($this->once())->method('sendRemoteShare')->with($this->equalTo('token'), $this->equalTo('*****@*****.**'), $this->equalTo('myFile'), $this->anything(), 'sharedBy')->willReturn(true);
     $this->rootFolder->expects($this->never())->method($this->anything());
     $share = $this->provider->create($share);
     $share->setPermissions(1);
     $this->provider->update($share);
     $share = $this->provider->getShareById($share->getId());
     $this->assertEquals(1, $share->getPermissions());
 }
Exemplo n.º 2
0
 /**
  * update share information to keep federated re-shares in sync
  *
  * @param array $params
  * @return \OC_OCS_Result
  */
 public function updatePermissions($params)
 {
     $id = (int) $params['id'];
     $token = $this->request->getParam('token', null);
     $permissions = $this->request->getParam('permissions', null);
     try {
         $share = $this->federatedShareProvider->getShareById($id);
     } catch (Share\Exceptions\ShareNotFound $e) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
     }
     $validPermission = ctype_digit($permissions);
     $validToken = $this->verifyShare($share, $token);
     if ($validPermission && $validToken) {
         $this->updatePermissionsInDatabase($share, (int) $permissions);
     } else {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST);
     }
     return new \OC_OCS_Result();
 }
 /**
  * @dataProvider datatTestUpdate
  *
  */
 public function testUpdate($owner, $sharedBy)
 {
     $this->provider = $this->getMockBuilder('OCA\\FederatedFileSharing\\FederatedShareProvider')->setConstructorArgs([$this->connection, $this->addressHandler, $this->notifications, $this->tokenHandler, $this->l, $this->logger, $this->rootFolder, $this->config, $this->userManager])->setMethods(['sendPermissionUpdate'])->getMock();
     $share = $this->shareManager->newShare();
     $node = $this->getMock('\\OCP\\Files\\File');
     $node->method('getId')->willReturn(42);
     $node->method('getName')->willReturn('myFile');
     $this->addressHandler->expects($this->any())->method('splitUserRemote')->willReturn(['user', 'server.com']);
     $share->setSharedWith('*****@*****.**')->setSharedBy($sharedBy)->setShareOwner($owner)->setPermissions(19)->setNode($node);
     $this->tokenHandler->method('generateToken')->willReturn('token');
     $this->addressHandler->expects($this->any())->method('generateRemoteURL')->willReturn('http://localhost/');
     $this->notifications->expects($this->once())->method('sendRemoteShare')->with($this->equalTo('token'), $this->equalTo('*****@*****.**'), $this->equalTo('myFile'), $this->anything(), $owner, $owner . '@http://localhost/', $sharedBy, $sharedBy . '@http://localhost/')->willReturn(true);
     if ($owner === $sharedBy) {
         $this->provider->expects($this->never())->method('sendPermissionUpdate');
     } else {
         $this->provider->expects($this->once())->method('sendPermissionUpdate');
     }
     $this->rootFolder->expects($this->never())->method($this->anything());
     $share = $this->provider->create($share);
     $share->setPermissions(1);
     $this->provider->update($share);
     $share = $this->provider->getShareById($share->getId());
     $this->assertEquals(1, $share->getPermissions());
 }