Esempio n. 1
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Cannot update share of a different user
  *
  * Test modification of share of another user
  */
 public function testSetPasswordShareOtherUser()
 {
     $user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
     $user->method('getUID')->willReturn('user');
     $userSession = $this->getMockBuilder('\\OCP\\IUserSession')->disableOriginalConstructor()->getMock();
     $userSession->method('getUser')->willReturn($user);
     $ex = $this->getMockBuilder('\\OC\\DB\\QueryBuilder\\ExpressionBuilder\\ExpressionBuilder')->disableOriginalConstructor()->getMock();
     $qb = $this->getMockBuilder('\\OC\\DB\\QueryBuilder\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $qb->method('update')->will($this->returnSelf());
     $qb->method('set')->will($this->returnSelf());
     $qb->method('where')->will($this->returnSelf());
     $qb->method('andWhere')->will($this->returnSelf());
     $qb->method('select')->will($this->returnSelf());
     $qb->method('from')->will($this->returnSelf());
     $qb->method('setParameter')->will($this->returnSelf());
     $qb->method('expr')->willReturn($ex);
     $ret = $this->getMockBuilder('\\Doctrine\\DBAL\\Driver\\ResultStatement')->disableOriginalConstructor()->getMock();
     $ret->method('fetch')->willReturn(['uid_owner' => 'user2']);
     $qb->method('execute')->willReturn($ret);
     $connection = $this->getMockBuilder('\\OC\\DB\\Connection')->disableOriginalConstructor()->getMock();
     $connection->method('getQueryBuilder')->willReturn($qb);
     $config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
 }
Esempio n. 2
0
 /**
  * Set expiration date for a share
  * @param int $shareId
  * @param string $password
  * @return boolean
  */
 public static function setPassword($shareId, $password)
 {
     $userSession = \OC::$server->getUserSession();
     $connection = \OC::$server->getDatabaseConnection();
     $config = \OC::$server->getConfig();
     return \OC\Share\Share::setPassword($userSession, $connection, $config, $shareId, $password);
 }