diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-08 14:44:17 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-08 14:44:17 +0200 |
commit | 103d451459efe539f13e0bebf968cf94c322ec0e (patch) | |
tree | 5ed22f078da852d709ed65c3bc3304ac8547ca5f /tests | |
parent | d01a2acbcf2aa0dbea56bc1ad7cb855dfabdd746 (diff) | |
parent | 3b1f0e60194aea021433031bd62b3173b912d712 (diff) | |
download | nextcloud-server-103d451459efe539f13e0bebf968cf94c322ec0e.tar.gz nextcloud-server-103d451459efe539f13e0bebf968cf94c322ec0e.zip |
Merge pull request #14987 from rullzer/ocs_password_fix2
OCS Fixes to allow setting of password without removing additional settings
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/share/share.php | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php index f35a0fa8e43..523f7b379a0 100644 --- a/tests/lib/share/share.php +++ b/tests/lib/share/share.php @@ -1128,6 +1128,240 @@ class Test_Share extends \Test\TestCase { \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days'); \OC_Appconfig::deleteKey('core', 'shareapi_enforce_expire_date'); } + + /** + * Cannot set password is there is no user + * + * @expectedException Exception + * @expectedExceptionMessage User not logged in + */ + public function testSetPasswordNoUser() { + $userSession = $this->getMockBuilder('\OCP\IUserSession') + ->disableOriginalConstructor() + ->getMock(); + + $connection = $this->getMockBuilder('\OC\DB\Connection') + ->disableOriginalConstructor() + ->getMock(); + + $config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + + \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); + } + + /** + * Test setting a password when everything is fine + */ + public function testSetPassword() { + $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('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') + ->disableOriginalConstructor() + ->getMock(); + $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\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' => 'user']); + $qb->method('execute')->willReturn($ret); + + + $connection = $this->getMockBuilder('\OC\DB\Connection') + ->disableOriginalConstructor() + ->getMock(); + $connection->method('createQueryBuilder')->willReturn($qb); + + $config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + + + $res = \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); + + $this->assertTrue($res); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Cannot remove password + * + * Test removing a password when password is enforced + */ + public function testSetPasswordRemove() { + $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('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') + ->disableOriginalConstructor() + ->getMock(); + $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\QueryBuilder') + ->disableOriginalConstructor() + ->getMock(); + $qb->method('update')->will($this->returnSelf()); + $qb->method('select')->will($this->returnSelf()); + $qb->method('from')->will($this->returnSelf()); + $qb->method('set')->will($this->returnSelf()); + $qb->method('where')->will($this->returnSelf()); + $qb->method('andWhere')->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' => 'user']); + $qb->method('execute')->willReturn($ret); + + + $connection = $this->getMockBuilder('\OC\DB\Connection') + ->disableOriginalConstructor() + ->getMock(); + $connection->method('createQueryBuilder')->willReturn($qb); + + $config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $config->method('getAppValue')->willReturn('yes'); + + \OC\Share\Share::setPassword($userSession, $connection, $config, 1, ''); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Share not found + * + * Test modification of invaid share + */ + public function testSetPasswordInvalidShare() { + $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('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') + ->disableOriginalConstructor() + ->getMock(); + $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\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([]); + $qb->method('execute')->willReturn($ret); + + + $connection = $this->getMockBuilder('\OC\DB\Connection') + ->disableOriginalConstructor() + ->getMock(); + $connection->method('createQueryBuilder')->willReturn($qb); + + $config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + + + \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); + } + + /** + * @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('\Doctrine\DBAL\Query\Expression\ExpressionBuilder') + ->disableOriginalConstructor() + ->getMock(); + $qb = $this->getMockBuilder('\Doctrine\DBAL\Query\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('createQueryBuilder')->willReturn($qb); + + $config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + + + \OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass'); + } + } class DummyShareClass extends \OC\Share\Share { |