summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2015-03-13 12:29:13 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2015-06-03 21:21:54 +0200
commitfe1de11b23a33fce6587cf1eae869e3f409e4c68 (patch)
treebbf04806f640ee3bbce807ad8ba534829faaf5f7 /tests
parentd1f99f10036dd859a5fa36cddeb4663665a17c58 (diff)
downloadnextcloud-server-fe1de11b23a33fce6587cf1eae869e3f409e4c68.tar.gz
nextcloud-server-fe1de11b23a33fce6587cf1eae869e3f409e4c68.zip
OCS Fixes to allow setting of password without removing additional settings
- Added setPassword to share.php - Fixed OCS API call - Added unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share/share.php230
1 files changed, 230 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 8f3d927be34..5c0463c979e 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1180,6 +1180,236 @@ 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('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('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('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('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 {