diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Repair/RepairInvalidSharesTest.php | 87 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 18 | ||||
-rw-r--r-- | tests/lib/User/SessionTest.php | 30 |
3 files changed, 117 insertions, 18 deletions
diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php index a1e871bcc80..1ac42e53bf6 100644 --- a/tests/lib/Repair/RepairInvalidSharesTest.php +++ b/tests/lib/Repair/RepairInvalidSharesTest.php @@ -124,6 +124,93 @@ class RepairInvalidSharesTest extends TestCase { } /** + * Test remove expiration date for non-link shares + */ + public function testAddShareLinkDeletePermission() { + $oldPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE; + $newPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE; + + // share with old permissions + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK), + 'uid_owner' => $qb->expr()->literal('user1'), + 'item_type' => $qb->expr()->literal('folder'), + 'item_source' => $qb->expr()->literal(123), + 'item_target' => $qb->expr()->literal('/123'), + 'file_source' => $qb->expr()->literal(123), + 'file_target' => $qb->expr()->literal('/test'), + 'permissions' => $qb->expr()->literal($oldPerms), + 'stime' => $qb->expr()->literal(time()), + ]) + ->execute(); + + $bogusShareId = $this->getLastShareId(); + + // share with read-only permissions + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_LINK), + 'uid_owner' => $qb->expr()->literal('user1'), + 'item_type' => $qb->expr()->literal('folder'), + 'item_source' => $qb->expr()->literal(123), + 'item_target' => $qb->expr()->literal('/123'), + 'file_source' => $qb->expr()->literal(123), + 'file_target' => $qb->expr()->literal('/test'), + 'permissions' => $qb->expr()->literal(\OCP\Constants::PERMISSION_READ), + 'stime' => $qb->expr()->literal(time()), + ]) + ->execute(); + + $keepThisShareId = $this->getLastShareId(); + + // user share to keep + $qb = $this->connection->getQueryBuilder(); + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(Constants::SHARE_TYPE_USER), + 'share_with' => $qb->expr()->literal('recipientuser1'), + 'uid_owner' => $qb->expr()->literal('user1'), + 'item_type' => $qb->expr()->literal('folder'), + 'item_source' => $qb->expr()->literal(123), + 'item_target' => $qb->expr()->literal('/123'), + 'file_source' => $qb->expr()->literal(123), + 'file_target' => $qb->expr()->literal('/test'), + 'permissions' => $qb->expr()->literal(3), + 'stime' => $qb->expr()->literal(time()), + ]) + ->execute(); + + $keepThisShareId2 = $this->getLastShareId(); + + /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') + ->disableOriginalConstructor() + ->getMock(); + + $this->repair->run($outputMock); + + $results = $this->connection->getQueryBuilder() + ->select('*') + ->from('share') + ->orderBy('permissions', 'ASC') + ->execute() + ->fetchAll(); + + $this->assertCount(3, $results); + + $untouchedShare = $results[0]; + $untouchedShare2 = $results[1]; + $updatedShare = $results[2]; + $this->assertEquals($keepThisShareId, $untouchedShare['id'], 'sanity check'); + $this->assertEquals($keepThisShareId2, $untouchedShare2['id'], 'sanity check'); + $this->assertEquals($bogusShareId, $updatedShare['id'], 'sanity check'); + $this->assertEquals($newPerms, $updatedShare['permissions'], 'delete permission was added'); + } + + /** * Test remove shares where the parent share does not exist anymore */ public function testSharesNonExistingParent() { diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 5f7579474aa..689e47d8c52 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -1329,24 +1329,6 @@ class ManagerTest extends \Test\TestCase { /** * @expectedException Exception - * @expectedExceptionMessage Link shares can't have delete permissions - */ - public function testLinkCreateChecksDeletePermissions() { - $share = $this->manager->newShare(); - - $share->setPermissions(\OCP\Constants::PERMISSION_DELETE); - - $this->config - ->method('getAppValue') - ->will($this->returnValueMap([ - ['core', 'shareapi_allow_links', 'yes', 'yes'], - ])); - - $this->invokePrivate($this->manager, 'linkCreateChecks', [$share]); - } - - /** - * @expectedException Exception * @expectedExceptionMessage Public upload not allowed */ public function testLinkCreateChecksNoPublicUpload() { diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index eef4c7ff5ea..447c6142f34 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -315,6 +315,36 @@ class SessionTest extends \Test\TestCase { } /** + * When using a device token, the loginname must match the one that was used + * when generating the token on the browser. + */ + public function testLoginWithDifferentTokenLoginName() { + $session = $this->getMock('\OC\Session\Memory', array(), array('')); + $manager = $this->getMock('\OC\User\Manager'); + $backend = $this->getMock('\Test\Util\User\Dummy'); + $userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config); + $username = 'user123'; + $token = new \OC\Authentication\Token\DefaultToken(); + $token->setLoginName($username); + + $session->expects($this->never()) + ->method('set'); + $session->expects($this->once()) + ->method('regenerateId'); + $this->tokenProvider->expects($this->once()) + ->method('getToken') + ->with('bar') + ->will($this->returnValue($token)); + + $manager->expects($this->once()) + ->method('checkPassword') + ->with('foo', 'bar') + ->will($this->returnValue(false)); + + $userSession->login('foo', 'bar'); + } + + /** * @expectedException \OC\Authentication\Exceptions\PasswordLoginForbiddenException */ public function testLogClientInNoTokenPasswordWith2fa() { |