summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Collaboration/Collaborators/SearchResultTest.php105
-rw-r--r--tests/lib/DB/MigratorTest.php39
-rw-r--r--tests/lib/Encryption/DecryptAllTest.php16
-rw-r--r--tests/lib/Encryption/EncryptionWrapperTest.php3
-rw-r--r--tests/lib/Encryption/Keys/StorageTest.php3
-rw-r--r--tests/lib/Encryption/UpdateTest.php3
-rw-r--r--tests/lib/Encryption/UtilTest.php3
-rw-r--r--tests/lib/FileChunkingTest.php2
-rw-r--r--tests/lib/Files/Node/FolderTest.php6
-rw-r--r--tests/lib/Files/Node/NodeTest.php3
-rw-r--r--tests/lib/Files/Node/RootTest.php2
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncryptionTest.php8
-rw-r--r--tests/lib/Files/ViewTest.php4
-rw-r--r--tests/lib/LoggerTest.php26
-rw-r--r--tests/lib/Security/CertificateManagerTest.php3
-rw-r--r--tests/lib/Session/CryptoWrappingTest.php3
16 files changed, 203 insertions, 26 deletions
diff --git a/tests/lib/Collaboration/Collaborators/SearchResultTest.php b/tests/lib/Collaboration/Collaborators/SearchResultTest.php
new file mode 100644
index 00000000000..90ea90237a1
--- /dev/null
+++ b/tests/lib/Collaboration/Collaborators/SearchResultTest.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Joas Schilling
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Collaboration\Collaborators;
+
+
+use OC\Collaboration\Collaborators\Search;
+use OC\Collaboration\Collaborators\SearchResult;
+use OCP\Collaboration\Collaborators\ISearch;
+use OCP\Collaboration\Collaborators\ISearchPlugin;
+use OCP\Collaboration\Collaborators\SearchResultType;
+use OCP\IContainer;
+use OCP\Share;
+use Test\TestCase;
+
+class SearchResultTest extends TestCase {
+ /** @var IContainer|\PHPUnit_Framework_MockObject_MockObject */
+ protected $container;
+ /** @var ISearch */
+ protected $search;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->container = $this->createMock(IContainer::class);
+
+ $this->search = new Search($this->container);
+ }
+
+ public function dataAddResultSet() {
+ return [
+ [[], ['exact' => []]],
+ [['users' => ['exact' => null, 'loose' => []]], ['exact' => ['users' => []], 'users' => []]],
+ [['groups' => ['exact' => null, 'loose' => ['l1']]], ['exact' => ['groups' => []], 'groups' => ['l1']]],
+ [['users' => ['exact' => ['e1'], 'loose' => []]], ['exact' => ['users' => ['e1']], 'users' => []]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataAddResultSet
+ * @param array $toAdd
+ * @param array $expected
+ */
+ public function testAddResultSet(array $toAdd, array $expected) {
+ $result = new SearchResult();
+
+ foreach ($toAdd as $type => $results) {
+ $result->addResultSet(new SearchResultType($type), $results['loose'], $results['exact']);
+ }
+
+ $this->assertEquals($expected, $result->asArray());
+ }
+
+ public function dataHasResult() {
+ $result = ['value' => ['shareWith' => 'l1']];
+ return [
+ [[],'users', 'n1', false],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'users', 'l1', true],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'users', 'l2', false],
+ [['users' => ['exact' => null, 'loose' => [$result]]], 'groups', 'l1', false],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'users', 'l1', true],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'users', 'l2', false],
+ [['users' => ['exact' => [$result], 'loose' => []]], 'groups', 'l1', false],
+
+ ];
+ }
+
+ /**
+ * @dataProvider dataHasResult
+ * @param array $toAdd
+ * @param string $type
+ * @param string $id
+ * @param bool $expected
+ */
+ public function testHasResult(array $toAdd, $type, $id, $expected) {
+ $result = new SearchResult();
+
+ foreach ($toAdd as $addType => $results) {
+ $result->addResultSet(new SearchResultType($addType), $results['loose'], $results['exact']);
+ }
+
+ $this->assertSame($expected, $result->hasResult(new SearchResultType($type), $id));
+ }
+
+}
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index e4f45c4bb86..ea718240c5e 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -41,6 +41,9 @@ class MigratorTest extends \Test\TestCase {
/** @var string */
private $tableName;
+ /** @var string */
+ private $tableNameTmp;
+
protected function setUp() {
parent::setUp();
@@ -50,11 +53,23 @@ class MigratorTest extends \Test\TestCase {
$this->markTestSkipped('DB migration tests are not supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
- $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
+ $this->tableName = $this->getUniqueTableName();
+ $this->tableNameTmp = $this->getUniqueTableName();
+ }
+
+ private function getUniqueTableName() {
+ return strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
}
protected function tearDown() {
- $this->connection->exec('DROP TABLE ' . $this->tableName);
+ // Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE)
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
+
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
parent::tearDown();
}
@@ -200,4 +215,24 @@ class MigratorTest extends \Test\TestCase {
$this->assertTrue(true);
}
+
+ public function testAddingForeignKey() {
+ $startSchema = new Schema([], [], $this->getSchemaConfig());
+ $table = $startSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer', ['autoincrement' => true]);
+ $table->addColumn('name', 'string');
+ $table->setPrimaryKey(['id']);
+
+ $fkName = "fkc";
+ $tableFk = $startSchema->createTable($this->tableNameTmp);
+ $tableFk->addColumn('fk_id', 'integer');
+ $tableFk->addColumn('name', 'string');
+ $tableFk->addForeignKeyConstraint($this->tableName, array('fk_id'), array('id'), array(), $fkName);
+
+ $migrator = $this->manager->getMigrator();
+ $migrator->migrate($startSchema);
+
+
+ $this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName));
+ }
}
diff --git a/tests/lib/Encryption/DecryptAllTest.php b/tests/lib/Encryption/DecryptAllTest.php
index c52619c3b12..06c5e0e2df8 100644
--- a/tests/lib/Encryption/DecryptAllTest.php
+++ b/tests/lib/Encryption/DecryptAllTest.php
@@ -28,9 +28,13 @@ use OC\Encryption\Exceptions\DecryptionFailedException;
use OC\Encryption\Manager;
use OC\Files\FileInfo;
use OC\Files\View;
+use OCP\Files\Storage;
use OCP\IUserManager;
use OCP\UserInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
+use Symfony\Component\Console\Helper\ProgressBar;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
/**
@@ -70,11 +74,11 @@ class DecryptAllTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->encryptionManager = $this->getMockBuilder('OC\Encryption\Manager')
->disableOriginalConstructor()->getMock();
- $this->view = $this->getMockBuilder('OC\Files\View')
+ $this->view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()->getMock();
- $this->inputInterface = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')
+ $this->inputInterface = $this->getMockBuilder(InputInterface::class)
->disableOriginalConstructor()->getMock();
- $this->outputInterface = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
+ $this->outputInterface = $this->getMockBuilder(OutputInterface::class)
->disableOriginalConstructor()->getMock();
$this->userInterface = $this->getMockBuilder(UserInterface::class)
->disableOriginalConstructor()->getMock();
@@ -253,11 +257,11 @@ class DecryptAllTest extends TestCase {
->setMethods(['decryptFile'])
->getMock();
- $storage = $this->getMockBuilder('OCP\Files\Storage')
+ $storage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()->getMock();
- $sharedStorage = $this->getMockBuilder('OCP\Files\Storage')
+ $sharedStorage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()->getMock();
$sharedStorage->expects($this->once())->method('instanceOfStorage')
@@ -296,7 +300,7 @@ class DecryptAllTest extends TestCase {
->method('decryptFile')
->with('/user1/files/foo/subfile');
- $progressBar = $this->getMockBuilder('Symfony\Component\Console\Helper\ProgressBar')
+ $progressBar = $this->getMockBuilder(ProgressBar::class)
->disableOriginalConstructor()->getMock();
$this->invokePrivate($instance, 'decryptUsersFiles', ['user1', $progressBar, '']);
diff --git a/tests/lib/Encryption/EncryptionWrapperTest.php b/tests/lib/Encryption/EncryptionWrapperTest.php
index 6a6a3db2f68..d20efa8821f 100644
--- a/tests/lib/Encryption/EncryptionWrapperTest.php
+++ b/tests/lib/Encryption/EncryptionWrapperTest.php
@@ -26,6 +26,7 @@ namespace Test\Encryption;
use OC\Encryption\EncryptionWrapper;
use OC\Encryption\Manager;
use OC\Memcache\ArrayCache;
+use OCP\Files\Storage;
use OCP\ILogger;
use Test\TestCase;
@@ -59,7 +60,7 @@ class EncryptionWrapperTest extends TestCase {
* @dataProvider provideWrapStorage
*/
public function testWrapStorage($expectedWrapped, $wrappedStorages) {
- $storage = $this->getMockBuilder('OC\Files\Storage\Storage')
+ $storage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();
diff --git a/tests/lib/Encryption/Keys/StorageTest.php b/tests/lib/Encryption/Keys/StorageTest.php
index a5924d1dc88..cd8f1e9b953 100644
--- a/tests/lib/Encryption/Keys/StorageTest.php
+++ b/tests/lib/Encryption/Keys/StorageTest.php
@@ -24,6 +24,7 @@
namespace Test\Encryption\Keys;
use OC\Encryption\Keys\Storage;
+use OC\Files\View;
use OCP\IConfig;
use Test\TestCase;
@@ -48,7 +49,7 @@ class StorageTest extends TestCase {
->disableOriginalConstructor()
->getMock();
- $this->view = $this->getMockBuilder('OC\Files\View')
+ $this->view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
diff --git a/tests/lib/Encryption/UpdateTest.php b/tests/lib/Encryption/UpdateTest.php
index ccd2bb796fc..a8cbef70d75 100644
--- a/tests/lib/Encryption/UpdateTest.php
+++ b/tests/lib/Encryption/UpdateTest.php
@@ -24,6 +24,7 @@ namespace Test\Encryption;
use OC\Encryption\Update;
+use OC\Files\Mount\Manager;
use OC\Files\View;
use Test\TestCase;
@@ -60,7 +61,7 @@ class UpdateTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->util = $this->getMockBuilder('\OC\Encryption\Util')
->disableOriginalConstructor()->getMock();
- $this->mountManager = $this->getMockBuilder('\OC\Files\Mount\Manager')
+ $this->mountManager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()->getMock();
$this->encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager')
->disableOriginalConstructor()->getMock();
diff --git a/tests/lib/Encryption/UtilTest.php b/tests/lib/Encryption/UtilTest.php
index e313274516e..1e1b21d3671 100644
--- a/tests/lib/Encryption/UtilTest.php
+++ b/tests/lib/Encryption/UtilTest.php
@@ -3,6 +3,7 @@
namespace Test\Encryption;
use OC\Encryption\Util;
+use OC\Files\View;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use Test\TestCase;
@@ -33,7 +34,7 @@ class UtilTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->view = $this->getMockBuilder('OC\Files\View')
+ $this->view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
diff --git a/tests/lib/FileChunkingTest.php b/tests/lib/FileChunkingTest.php
index cf0fed251a4..42fc820c5d0 100644
--- a/tests/lib/FileChunkingTest.php
+++ b/tests/lib/FileChunkingTest.php
@@ -47,7 +47,7 @@ class FileChunkingTest extends \Test\TestCase {
* @param $expected
*/
public function testIsComplete($total, array $present, $expected) {
- $fileChunking = $this->getMockBuilder('\OC_FileChunking')
+ $fileChunking = $this->getMockBuilder(\OC_FileChunking::class)
->setMethods(['getCache'])
->setConstructorArgs([[
'name' => 'file',
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index ec043c7b81e..6479dad58d3 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -786,7 +786,7 @@ class FolderTest extends NodeTest {
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
- $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ $folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
$baseTime = 1000;
@@ -847,7 +847,7 @@ class FolderTest extends NodeTest {
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
- $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ $folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
$baseTime = 1000;
@@ -906,7 +906,7 @@ class FolderTest extends NodeTest {
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
->getMock();
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */
- $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo')
+ $folderInfo = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()->getMock();
$baseTime = 1000;
diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php
index 160787411f1..9200ae69f75 100644
--- a/tests/lib/Files/Node/NodeTest.php
+++ b/tests/lib/Files/Node/NodeTest.php
@@ -9,6 +9,7 @@
namespace Test\Files\Node;
use OC\Files\FileInfo;
+use OC\Files\Mount\Manager;
use OC\Files\View;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IRootFolder;
@@ -52,7 +53,7 @@ abstract class NodeTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator);
- $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
+ $this->manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->view = $this->getMockBuilder(View::class)
diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php
index 2f81a96d486..fd050c8d90c 100644
--- a/tests/lib/Files/Node/RootTest.php
+++ b/tests/lib/Files/Node/RootTest.php
@@ -47,7 +47,7 @@ class RootTest extends \Test\TestCase {
->getMock();
$this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator);
- $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager')
+ $this->manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache')
diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
index 459abf3b64c..c184752ff7e 100644
--- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
@@ -719,7 +719,7 @@ class EncryptionTest extends Storage {
}
public function testCopyBetweenStorageMinimumEncryptedVersion() {
- $storage2 = $this->getMockBuilder('OCP\Files\Storage')
+ $storage2 = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();
@@ -768,7 +768,7 @@ class EncryptionTest extends Storage {
* @param bool $expectedEncrypted
*/
public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) {
- $storage2 = $this->getMockBuilder('OCP\Files\Storage')
+ $storage2 = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();
@@ -830,11 +830,11 @@ class EncryptionTest extends Storage {
*/
public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) {
- $sourceStorage = $this->getMockBuilder('OCP\Files\Storage')
+ $sourceStorage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();
- $targetStorage = $this->getMockBuilder('OCP\Files\Storage')
+ $targetStorage = $this->getMockBuilder(Storage::class)
->disableOriginalConstructor()
->getMock();
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index cab8bd62739..33d5cc0a8a6 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -2350,7 +2350,7 @@ class ViewTest extends \Test\TestCase {
return;
}
- $eventHandler = $this->getMockBuilder('\stdclass')
+ $eventHandler = $this->getMockBuilder(\stdclass::class)
->setMethods(['preCallback', 'postCallback'])
->getMock();
@@ -2425,7 +2425,7 @@ class ViewTest extends \Test\TestCase {
Filesystem::getMountManager()->addMount($mount);
// Listen for events
- $eventHandler = $this->getMockBuilder('\stdclass')
+ $eventHandler = $this->getMockBuilder(\stdclass::class)
->setMethods(['umount', 'post_umount'])
->getMock();
$eventHandler->expects($this->once())
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php
index da9cedc9f56..3a30bbd1d3b 100644
--- a/tests/lib/LoggerTest.php
+++ b/tests/lib/LoggerTest.php
@@ -138,6 +138,32 @@ class LoggerTest extends TestCase {
}
}
+ /**
+ * @dataProvider userAndPasswordData
+ */
+ public function testDetectclosure($user, $password) {
+ $a = function($user, $password) {
+ throw new \Exception('test');
+ };
+
+ try {
+ $a($user, $password);
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ }
+ $logLines = $this->getLogs();
+
+ foreach($logLines as $logLine) {
+ $log = explode('\n', $logLine);
+ unset($log[1]); // Remove `testDetectclosure(` because we are not testing this here, but the closure on stack trace 0
+ $logLine = implode('\n', $log);
+
+ $this->assertNotContains($user, $logLine);
+ $this->assertNotContains($password, $logLine);
+ $this->assertContains('{closure}(*** sensitive parameters replaced ***)', $logLine);
+ }
+ }
+
public function dataGetLogClass() {
return [
['file', \OC\Log\File::class],
diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php
index 6bdb647abc5..2804ad99c0f 100644
--- a/tests/lib/Security/CertificateManagerTest.php
+++ b/tests/lib/Security/CertificateManagerTest.php
@@ -9,6 +9,7 @@
namespace Test\Security;
use OC\Files\Storage\Temporary;
+use OC\Files\View;
use \OC\Security\CertificateManager;
use OCP\IConfig;
use OCP\ILogger;
@@ -152,7 +153,7 @@ class CertificateManagerTest extends \Test\TestCase {
$expected
) {
- $view = $this->getMockBuilder('OC\Files\View')
+ $view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()->getMock();
$config = $this->createMock(IConfig::class);
diff --git a/tests/lib/Session/CryptoWrappingTest.php b/tests/lib/Session/CryptoWrappingTest.php
index e1fadbf933f..f34148fb50e 100644
--- a/tests/lib/Session/CryptoWrappingTest.php
+++ b/tests/lib/Session/CryptoWrappingTest.php
@@ -22,6 +22,7 @@
namespace Test\Session;
use OC\Session\CryptoSessionData;
+use OCP\ISession;
use Test\TestCase;
class CryptoWrappingTest extends TestCase {
@@ -37,7 +38,7 @@ class CryptoWrappingTest extends TestCase {
protected function setUp() {
parent::setUp();
- $this->wrappedSession = $this->getMockBuilder('OCP\ISession')
+ $this->wrappedSession = $this->getMockBuilder(ISession::class)
->disableOriginalConstructor()
->getMock();
$this->crypto = $this->getMockBuilder('OCP\Security\ICrypto')