summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2015-04-28 14:00:36 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2015-06-03 21:32:20 +0200
commit5865a3af8cedaac7fc9649cf17f660393ea90b9a (patch)
tree2bb8118cdf9ca240558bfc8eefcef761dd32739b /tests
parent783188d683c01208e4db40db71aec419b23b9f33 (diff)
downloadnextcloud-server-5865a3af8cedaac7fc9649cf17f660393ea90b9a.tar.gz
nextcloud-server-5865a3af8cedaac7fc9649cf17f660393ea90b9a.zip
Added unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share/share.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 314fd59ec70..3b6814a44b3 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -1203,6 +1203,52 @@ class Test_Share extends \Test\TestCase {
\OC\Share\Share::setPassword($userSession, $connection, $config, 1, 'pass');
}
+ public function testPasswords() {
+ $pass = 'secret';
+
+ $this->shareUserTestFileAsLink();
+
+ $userSession = \OC::$server->getUserSession();
+ $connection = \OC::$server->getDatabaseConnection();
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ // Find the share ID in the db
+ $qb = $connection->createQueryBuilder();
+ $qb->select('`id`')
+ ->from('`*PREFIX*share`')
+ ->where('`item_type` = :type')
+ ->andWhere('`item_source` = :source')
+ ->andWhere('`uid_owner` = :owner')
+ ->andWhere('`share_type` = :share_type')
+ ->setParameter('type', 'test')
+ ->setParameter('source', 'test.txt')
+ ->setParameter('owner', $this->user1)
+ ->setParameter('share_type', \OCP\Share::SHARE_TYPE_LINK);
+
+ $res = $qb->execute()->fetchAll();
+ $this->assertCount(1, $res);
+ $id = $res[0]['id'];
+
+ // Set password on share
+ $res = \OC\Share\Share::setPassword($userSession, $connection, $config, $id, $pass);
+ $this->assertTrue($res);
+
+ // Fetch the hash from the database
+ $qb = $connection->createQueryBuilder();
+ $qb->select('`share_with`')
+ ->from('`*PREFIX*share`')
+ ->where('`id` = :id')
+ ->setParameter('id', $id);
+ $hash = $qb->execute()->fetch()['share_with'];
+
+ $hasher = \OC::$server->getHasher();
+
+ // Verify hash
+ $this->assertTrue($hasher->verify($pass, $hash));
+ }
+
/**
* Test setting a password when everything is fine
*/