summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Security/CSRF/CsrfTokenManagerTest.php8
-rw-r--r--tests/lib/Security/CSRF/CsrfTokenTest.php8
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php91
-rw-r--r--tests/lib/Share20/ManagerTest.php132
4 files changed, 229 insertions, 10 deletions
diff --git a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php
index 6f7842fdfd9..f9dd8127e5a 100644
--- a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php
+++ b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php
@@ -137,15 +137,19 @@ class CsrfTokenManagerTest extends \Test\TestCase {
}
public function testIsTokenValidWithValidToken() {
+ $a = 'abc';
+ $b = 'def';
+ $xorB64 = 'BQcF';
+ $tokenVal = sprintf('%s:%s', $xorB64, base64_encode($a));
$this->storageInterface
->expects($this->once())
->method('hasToken')
->willReturn(true);
- $token = new \OC\Security\CSRF\CsrfToken('XlQhHjgWCgBXAEI0Khl+IQEiCXN2LUcDHAQTQAc1HQs=:qgkUlg8l3m8WnkOG4XM9Az33pAt1vSVMx4hcJFsxdqc=');
+ $token = new \OC\Security\CSRF\CsrfToken($tokenVal);
$this->storageInterface
->expects($this->once())
->method('getToken')
- ->willReturn('/3JKTq2ldmzcDr1f5zDJ7Wt0lEgqqfKF');
+ ->willReturn($b);
$this->assertSame(true, $this->csrfTokenManager->isTokenValid($token));
}
diff --git a/tests/lib/Security/CSRF/CsrfTokenTest.php b/tests/lib/Security/CSRF/CsrfTokenTest.php
index d19d1de916c..fbb92cd315a 100644
--- a/tests/lib/Security/CSRF/CsrfTokenTest.php
+++ b/tests/lib/Security/CSRF/CsrfTokenTest.php
@@ -36,7 +36,11 @@ class CsrfTokenTest extends \Test\TestCase {
}
public function testGetDecryptedValue() {
- $csrfToken = new \OC\Security\CSRF\CsrfToken('XlQhHjgWCgBXAEI0Khl+IQEiCXN2LUcDHAQTQAc1HQs=:qgkUlg8l3m8WnkOG4XM9Az33pAt1vSVMx4hcJFsxdqc=');
- $this->assertSame('/3JKTq2ldmzcDr1f5zDJ7Wt0lEgqqfKF', $csrfToken->getDecryptedValue());
+ $a = 'abc';
+ $b = 'def';
+ $xorB64 = 'BQcF';
+ $tokenVal = sprintf('%s:%s', $xorB64, base64_encode($a));
+ $csrfToken = new \OC\Security\CSRF\CsrfToken($tokenVal);
+ $this->assertSame($b, $csrfToken->getDecryptedValue());
}
}
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index 778c1cb5722..5870da8d218 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -2298,4 +2298,95 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount($toDelete ? 0 : 1, $data);
}
+
+ public function testGetSharesInFolder() {
+ $userManager = \OC::$server->getUserManager();
+ $groupManager = \OC::$server->getGroupManager();
+ $rootFolder = \OC::$server->getRootFolder();
+
+ $provider = new DefaultShareProvider(
+ $this->dbConn,
+ $userManager,
+ $groupManager,
+ $rootFolder
+ );
+
+ $u1 = $userManager->createUser('testShare1', 'test');
+ $u2 = $userManager->createUser('testShare2', 'test');
+ $u3 = $userManager->createUser('testShare3', 'test');
+
+ $g1 = $groupManager->createGroup('group1');
+
+ $u1Folder = $rootFolder->getUserFolder($u1->getUID());
+ $folder1 = $u1Folder->newFolder('foo');
+ $file1 = $folder1->newFile('bar');
+ $folder2 = $folder1->newFolder('baz');
+
+ $shareManager = \OC::$server->getShareManager();
+ $share1 = $shareManager->newShare();
+ $share1->setNode($folder1)
+ ->setSharedBy($u1->getUID())
+ ->setSharedWith($u2->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ $share1 = $this->provider->create($share1);
+
+ $share2 = $shareManager->newShare();
+ $share2->setNode($file1)
+ ->setSharedBy($u2->getUID())
+ ->setSharedWith($u3->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share2 = $this->provider->create($share2);
+
+ $share3 = $shareManager->newShare();
+ $share3->setNode($folder2)
+ ->setSharedBy($u2->getUID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share3 = $this->provider->create($share3);
+
+ $share4 = $shareManager->newShare();
+ $share4->setNode($folder2)
+ ->setSharedBy($u1->getUID())
+ ->setSharedWith($g1->getGID())
+ ->setShareOwner($u1->getUID())
+ ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+ ->setPermissions(\OCP\Constants::PERMISSION_READ);
+ $share4 = $this->provider->create($share4);
+
+ $result = $provider->getSharesInFolder($u1->getUID(), $folder1, false);
+ $this->assertCount(1, $result);
+ $shares = array_pop($result);
+ $this->assertCount(1, $shares);
+ $this->assertSame($folder2->getId(), $shares[0]->getNodeId());
+
+ $result = $provider->getSharesInFolder($u1->getUID(), $folder1, true);
+ $this->assertCount(2, $result);
+
+ $file_shares = $result[$file1->getId()];
+ $this->assertCount(1, $file_shares);
+ $this->assertSame($file1->getId(), $file_shares[0]->getNodeId());
+ $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $file_shares[0]->getShareType());
+
+ $folder_shares = $result[$folder2->getId()];
+ $this->assertCount(2, $folder_shares);
+ $this->assertSame($folder2->getId(), $folder_shares[0]->getNodeId());
+ $this->assertSame($folder2->getId(), $folder_shares[1]->getNodeId());
+ $this->assertSame(\OCP\Share::SHARE_TYPE_LINK, $folder_shares[0]->getShareType());
+ $this->assertSame(\OCP\Share::SHARE_TYPE_GROUP, $folder_shares[1]->getShareType());
+
+ $provider->delete($share1);
+ $provider->delete($share2);
+ $provider->delete($share3);
+ $provider->delete($share4);
+
+ $u1->delete();
+ $u2->delete();
+ $u3->delete();
+ $g1->delete();
+ }
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 72ba4da6e5d..bd85e3c73aa 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -22,6 +22,7 @@ namespace Test\Share20;
use OC\Files\Mount\MoveableMount;
use OC\HintException;
+use OC\Share20\DefaultShareProvider;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -29,6 +30,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\Storage;
use OCP\IGroup;
+use OCP\IServerContainer;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Share\Exceptions\ShareNotFound;
@@ -118,13 +120,9 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher
);
- $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->defaultProvider = $this->createMock(DefaultShareProvider::class);
$this->defaultProvider->method('identifier')->willReturn('default');
$this->factory->setProvider($this->defaultProvider);
-
-
}
/**
@@ -2531,12 +2529,111 @@ class ManagerTest extends \Test\TestCase {
$this->manager->moveShare($share, 'recipient');
}
+
+
+ /**
+ * @dataProvider dataTestShareProviderExists
+ */
+ public function testShareProviderExists($shareType, $expected) {
+
+ $factory = $this->getMockBuilder('OCP\Share\IProviderFactory')->getMock();
+ $factory->expects($this->any())->method('getProviderForType')
+ ->willReturnCallback(function ($id) {
+ if ($id === \OCP\Share::SHARE_TYPE_USER) {
+ return true;
+ }
+ throw new Exception\ProviderException();
+ });
+
+ $manager = new Manager(
+ $this->logger,
+ $this->config,
+ $this->secureRandom,
+ $this->hasher,
+ $this->mountManager,
+ $this->groupManager,
+ $this->l,
+ $factory,
+ $this->userManager,
+ $this->rootFolder,
+ $this->eventDispatcher
+ );
+ $this->assertSame($expected,
+ $manager->shareProviderExists($shareType)
+ );
+ }
+
+ public function dataTestShareProviderExists() {
+ return [
+ [\OCP\Share::SHARE_TYPE_USER, true],
+ [42, false],
+ ];
+ }
+
+ public function testGetSharesInFolder() {
+ $factory = new DummyFactory2($this->createMock(IServerContainer::class));
+
+ $manager = new Manager(
+ $this->logger,
+ $this->config,
+ $this->secureRandom,
+ $this->hasher,
+ $this->mountManager,
+ $this->groupManager,
+ $this->l,
+ $factory,
+ $this->userManager,
+ $this->rootFolder,
+ $this->eventDispatcher
+ );
+
+ $factory->setProvider($this->defaultProvider);
+ $extraProvider = $this->createMock(IShareProvider::class);
+ $factory->setSecondProvider($extraProvider);
+
+ $share1 = $this->createMock(IShare::class);
+ $share2 = $this->createMock(IShare::class);
+ $share3 = $this->createMock(IShare::class);
+ $share4 = $this->createMock(IShare::class);
+
+ $folder = $this->createMock(Folder::class);
+
+ $this->defaultProvider->method('getSharesInFolder')
+ ->with(
+ $this->equalTo('user'),
+ $this->equalTo($folder),
+ $this->equalTo(false)
+ )->willReturn([
+ 1 => [$share1],
+ 2 => [$share2],
+ ]);
+
+ $extraProvider->method('getSharesInFolder')
+ ->with(
+ $this->equalTo('user'),
+ $this->equalTo($folder),
+ $this->equalTo(false)
+ )->willReturn([
+ 2 => [$share3],
+ 3 => [$share4],
+ ]);
+
+ $result = $manager->getSharesInFolder('user', $folder, false);
+
+ $expects = [
+ 1 => [$share1],
+ 2 => [$share2, $share3],
+ 3 => [$share4],
+ ];
+
+ $this->assertSame($expects, $result);
+ }
}
class DummyFactory implements IProviderFactory {
/** @var IShareProvider */
- private $provider;
+ protected $provider;
public function __construct(\OCP\IServerContainer $serverContainer) {
@@ -2564,4 +2661,27 @@ class DummyFactory implements IProviderFactory {
public function getProviderForType($shareType) {
return $this->provider;
}
+
+ /**
+ * @return IShareProvider[]
+ */
+ public function getAllProviders() {
+ return [$this->provider];
+ }
+}
+
+class DummyFactory2 extends DummyFactory {
+ /** @var IShareProvider */
+ private $provider2;
+
+ /**
+ * @param IShareProvider $provider
+ */
+ public function setSecondProvider($provider) {
+ $this->provider2 = $provider;
+ }
+
+ public function getAllProviders() {
+ return [$this->provider, $this->provider2];
+ }
}