diff options
21 files changed, 301 insertions, 63 deletions
diff --git a/.drone.yml b/.drone.yml index 2b5407e0df6..35ed0c74593 100644 --- a/.drone.yml +++ b/.drone.yml @@ -33,6 +33,13 @@ pipeline: when: matrix: TESTS: signed-off-check + htaccess-checker: + image: nextcloudci/php7.0:php7.0-2 + commands: + - php ./build/htaccess-checker.php + when: + matrix: + TESTS: htaccess-checker syntax-php5.6: image: nextcloudci/php5.6:php5.6-2 commands: @@ -332,6 +339,7 @@ pipeline: matrix: include: - TESTS: signed-off-check + - TESTS: htaccess-checker - TESTS: nodb-codecov - TESTS: db-codecov - TESTS: integration-capabilities_features diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 8fec7d5c04e..18d0d973586 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -769,8 +769,7 @@ OC.Uploader.prototype = _.extend({ data.originalFiles.selection = { uploads: [], filesToUpload: data.originalFiles.length, - totalBytes: 0, - biggestFileBytes: 0 + totalBytes: 0 }; } // TODO: move originalFiles to a separate container, maybe inside OC.Upload @@ -825,18 +824,6 @@ OC.Uploader.prototype = _.extend({ } else { // add size selection.totalBytes += file.size; - // update size of biggest file - selection.biggestFileBytes = Math.max(selection.biggestFileBytes, file.size); - } - - // check PHP upload limit against biggest file - if (selection.biggestFileBytes > $('#upload_limit').val()) { - data.textStatus = 'sizeexceedlimit'; - data.errorThrown = t('files', - 'Total file size {size1} exceeds upload limit {size2}', { - 'size1': humanFileSize(selection.biggestFileBytes), - 'size2': humanFileSize($('#upload_limit').val()) - }); } // check free space diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 0be098b2e73..1681e2c7e48 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -59,7 +59,6 @@ return; } if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { - $('#max_upload').val(response.data.uploadMaxFilesize); $('#free_space').val(response.data.freeSpace); $('#upload.button').attr('data-original-title', response.data.maxHumanFilesize); $('#usedSpacePercent').val(response.data.usedSpacePercent); @@ -71,7 +70,6 @@ return; } if (response[0].uploadMaxFilesize !== undefined) { - $('#max_upload').val(response[0].uploadMaxFilesize); $('#upload.button').attr('data-original-title', response[0].maxHumanFilesize); $('#usedSpacePercent').val(response[0].usedSpacePercent); Files.displayStorageWarnings(); diff --git a/apps/files/list.php b/apps/files/list.php index a932cc9a805..93044d4c587 100644 --- a/apps/files/list.php +++ b/apps/files/list.php @@ -24,11 +24,9 @@ $config = \OC::$server->getConfig(); // TODO: move this to the generated config.js $publicUploadEnabled = $config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'); -$uploadLimit=OCP\Util::uploadLimit(); // renders the controls and table headers template $tmpl = new OCP\Template('files', 'list', ''); -$tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); $tmpl->printPage(); diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index e741849f38b..d66f12f4aff 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -15,8 +15,6 @@ through ajax instead (updateStorageStatistics). */ ?> <input type="hidden" name="permissions" value="" id="permissions"> - <input type="hidden" id="max_upload" name="MAX_FILE_SIZE" value="<?php isset($_['uploadMaxFilesize']) ? p($_['uploadMaxFilesize']) : '' ?>"> - <input type="hidden" id="upload_limit" value="<?php isset($_['uploadLimit']) ? p($_['uploadLimit']) : '' ?>"> <input type="hidden" id="free_space" value="<?php isset($_['freeSpace']) ? p($_['freeSpace']) : '' ?>"> <?php if(isset($_['dirToken'])):?> <input type="hidden" id="publicUploadRequestToken" name="requesttoken" value="<?php p($_['requesttoken']) ?>" /> diff --git a/apps/files/tests/js/fileUploadSpec.js b/apps/files/tests/js/fileUploadSpec.js index 19f8cde7e44..fa686dbf3e2 100644 --- a/apps/files/tests/js/fileUploadSpec.js +++ b/apps/files/tests/js/fileUploadSpec.js @@ -35,7 +35,6 @@ describe('OC.Upload tests', function() { // need a dummy button because file-upload checks on it $('#testArea').append( '<input type="file" id="file_upload_start" name="files[]" multiple="multiple">' + - '<input type="hidden" id="upload_limit" name="upload_limit" value="10000000">' + // 10 MB '<input type="hidden" id="free_space" name="free_space" value="50000000">' + // 50 MB // TODO: handlebars! '<div id="new">' + @@ -97,19 +96,6 @@ describe('OC.Upload tests', function() { expect(result[0].submit.calledOnce).toEqual(true); expect(failStub.notCalled).toEqual(true); }); - it('does not add file if it exceeds upload limit', function() { - var result; - $('#upload_limit').val(1000); - - result = addFiles(uploader, [testFile]); - - expect(result[0]).toEqual(null); - expect(failStub.calledOnce).toEqual(true); - expect(failStub.getCall(0).args[1].textStatus).toEqual('sizeexceedlimit'); - expect(failStub.getCall(0).args[1].errorThrown).toEqual( - 'Total file size 5 KB exceeds upload limit 1000 B' - ); - }); it('does not add file if it exceeds free space', function() { var result; $('#free_space').val(1000); diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 62725115dd6..5ad7d3a99f1 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -342,9 +342,8 @@ class ShareController extends Controller { $freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188 } - $uploadLimit = Util::uploadLimit(); - $maxUploadFilesize = min($freeSpace, $uploadLimit); $hideFileList = $share->getPermissions() & \OCP\Constants::PERMISSION_READ ? false : true; + $maxUploadFilesize = $freeSpace; $folder = new Template('files', 'list', ''); $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath())); @@ -356,7 +355,6 @@ class ShareController extends Controller { $folder->assign('uploadMaxFilesize', $maxUploadFilesize); $folder->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); $folder->assign('freeSpace', $freeSpace); - $folder->assign('uploadLimit', $uploadLimit); // PHP upload limit $folder->assign('usedSpacePercent', 0); $folder->assign('trash', false); $shareTmpl['folder'] = $folder->fetchPage(); diff --git a/build/htaccess-checker.php b/build/htaccess-checker.php new file mode 100644 index 00000000000..b6932d6543a --- /dev/null +++ b/build/htaccess-checker.php @@ -0,0 +1,35 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @author Lukas Reschke <lukas@statuscode.ch> + * + * @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/>. + * + */ + +/** + * Script to check that the main .htaccess file doesn't include some automated + * changes done by Nextcloud. + */ + +$htaccess = file_get_contents(__DIR__ . '/../.htaccess'); +if(strpos($htaccess, 'DO NOT CHANGE ANYTHING') !== false) { + echo(".htaccess file has invalid changes!\n"); + exit(1); +} else { + exit(0); +} diff --git a/lib/base.php b/lib/base.php index 28fc57161c3..909a62040ee 100644 --- a/lib/base.php +++ b/lib/base.php @@ -377,6 +377,7 @@ class OC { \OCP\Util::addScript('update'); \OCP\Util::addStyle('update'); + /** @var \OCP\App\IAppManager $appManager */ $appManager = \OC::$server->getAppManager(); $tmpl = new OC_Template('', 'update.admin', 'guest'); @@ -385,8 +386,17 @@ class OC { // get third party apps $ocVersion = \OCP\Util::getVersion(); + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); + foreach ($incompatibleApps as $appInfo) { + if ($appManager->isShipped($appInfo['id'])) { + $l = \OC::$server->getL10N('core'); + $hint = $l->t('The files of the app "%$1s" (%$2s) were not replaced correctly.', [$appInfo['name'], $appInfo['id']]); + throw new \OC\HintException('The files of the app "' . $appInfo['name'] . '" (' . $appInfo['id'] . ') were not replaced correctly.', $hint); + } + } + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); - $tmpl->assign('incompatibleAppsList', $appManager->getIncompatibleApps($ocVersion)); + $tmpl->assign('incompatibleAppsList', $incompatibleApps); $tmpl->assign('productName', 'Nextcloud'); // for now $tmpl->assign('oldTheme', $oldTheme); $tmpl->printPage(); diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index dfe2e86b617..497ff0c8a26 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -67,7 +67,11 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection { * @return \OCP\DB\QueryBuilder\IQueryBuilder */ public function getQueryBuilder() { - return new QueryBuilder($this); + return new QueryBuilder( + $this, + \OC::$server->getSystemConfig(), + \OC::$server->getLogger() + ); } /** diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index eac77dd98fd..d5dd9cf0366 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -31,16 +31,24 @@ use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder; +use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryFunction; use OCP\DB\QueryBuilder\IParameter; use OCP\IDBConnection; +use OCP\ILogger; class QueryBuilder implements IQueryBuilder { /** @var \OCP\IDBConnection */ private $connection; + /** @var SystemConfig */ + private $systemConfig; + + /** @var ILogger */ + private $logger; + /** @var \Doctrine\DBAL\Query\QueryBuilder */ private $queryBuilder; @@ -56,10 +64,14 @@ class QueryBuilder implements IQueryBuilder { /** * Initializes a new QueryBuilder. * - * @param \OCP\IDBConnection $connection + * @param IDBConnection $connection + * @param SystemConfig $systemConfig + * @param ILogger $logger */ - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) { $this->connection = $connection; + $this->systemConfig = $systemConfig; + $this->logger = $logger; $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection); $this->helper = new QuoteHelper(); } @@ -139,6 +151,29 @@ class QueryBuilder implements IQueryBuilder { * @return \Doctrine\DBAL\Driver\Statement|int */ public function execute() { + if ($this->systemConfig->getValue('log_query', false)) { + $params = []; + foreach ($this->getParameters() as $placeholder => $value) { + if (is_array($value)) { + $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; + } else { + $params[] = $placeholder . ' => \'' . $value . '\''; + } + } + if (empty($params)) { + $this->logger->debug('DB QueryBuilder: \'{query}\'', [ + 'query' => $this->getSQL(), + 'app' => 'core', + ]); + } else { + $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ + 'query' => $this->getSQL(), + 'params' => implode(', ', $params), + 'app' => 'core', + ]); + } + } + return $this->queryBuilder->execute(); } diff --git a/lib/private/Files/Mount/ObjectHomeMountProvider.php b/lib/private/Files/Mount/ObjectHomeMountProvider.php index c1eea34a72e..87878562a42 100644 --- a/lib/private/Files/Mount/ObjectHomeMountProvider.php +++ b/lib/private/Files/Mount/ObjectHomeMountProvider.php @@ -121,7 +121,8 @@ class ObjectHomeMountProvider implements IHomeMountProvider { $config['arguments']['bucket'] = ''; } $mapper = new \OC\Files\ObjectStore\Mapper($user); - $config['arguments']['bucket'] .= $mapper->getBucket(); + $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64; + $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets); $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); } else { diff --git a/lib/private/Files/ObjectStore/Mapper.php b/lib/private/Files/ObjectStore/Mapper.php index bfb4e998150..81f8a9e3fa5 100644 --- a/lib/private/Files/ObjectStore/Mapper.php +++ b/lib/private/Files/ObjectStore/Mapper.php @@ -44,10 +44,12 @@ class Mapper { } /** + * @param int $numBuckets * @return string */ - public function getBucket() { + public function getBucket($numBuckets = 64) { $hash = md5($this->user->getUID()); - return substr($hash, 0, 3); + $num = hexdec(substr($hash, 0, 4)); + return (string)($num % $numBuckets); } -}
\ No newline at end of file +} diff --git a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php index cf4cdfa5036..9d2e723a6d3 100644 --- a/lib/private/Security/CSRF/TokenStorage/SessionStorage.php +++ b/lib/private/Security/CSRF/TokenStorage/SessionStorage.php @@ -41,6 +41,13 @@ class SessionStorage { } /** + * @param ISession $session + */ + public function setSession(ISession $session) { + $this->session = $session; + } + + /** * Returns the current token or throws an exception if none is found. * * @return string diff --git a/lib/private/Server.php b/lib/private/Server.php index 6f25098eb35..dca50c15733 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -710,13 +710,15 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerService('CsrfTokenManager', function (Server $c) { $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); - $sessionStorage = new SessionStorage($c->getSession()); return new CsrfTokenManager( $tokenGenerator, - $sessionStorage + $c->query(SessionStorage::class) ); }); + $this->registerService(SessionStorage::class, function (Server $c) { + return new SessionStorage($c->getSession()); + }); $this->registerService('ContentSecurityPolicyManager', function (Server $c) { return new ContentSecurityPolicyManager(); }); @@ -945,6 +947,7 @@ class Server extends ServerContainer implements IServerContainer { * @param \OCP\ISession $session */ public function setSession(\OCP\ISession $session) { + $this->query(SessionStorage::class)->setSession($session); return $this->query('UserSession')->setSession($session); } diff --git a/lib/private/Updater.php b/lib/private/Updater.php index cd2934f7196..e7f7a944902 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -382,6 +382,9 @@ class Updater extends BasicEmitter { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); if(!OC_App::isAppCompatible($version, $info)) { + if (OC_App::isShipped($app)) { + throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); + } OC_App::disable($app); $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); } diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 3c10d25c535..22808f586ef 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -25,7 +25,9 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use OC\DB\QueryBuilder\Literal; use OC\DB\QueryBuilder\Parameter; use OC\DB\QueryBuilder\QueryBuilder; +use OC\SystemConfig; use OCP\IDBConnection; +use OCP\ILogger; /** * Class QueryBuilderTest @@ -41,11 +43,19 @@ class QueryBuilderTest extends \Test\TestCase { /** @var IDBConnection */ protected $connection; + /** @var SystemConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $config; + + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + protected $logger; + protected function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); - $this->queryBuilder = new QueryBuilder($this->connection); + $this->config = $this->createMock(SystemConfig::class); + $this->logger = $this->createMock(ILogger::class); + $this->queryBuilder = new QueryBuilder($this->connection, $this->config, $this->logger); } protected function createTestingRows($appId = 'testFirstResult') { @@ -166,7 +176,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataSelect() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ // select('column1') [['configvalue'], ['configvalue' => '99']], @@ -232,7 +244,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataSelectAlias() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ ['configvalue', 'cv', ['cv' => '99']], [$queryBuilder->expr()->literal('column1'), 'thing', ['thing' => 'column1']], @@ -301,7 +315,9 @@ class QueryBuilderTest extends \Test\TestCase { } public function dataAddSelect() { - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection()); + $config = $this->createMock(SystemConfig::class); + $logger = $this->createMock(ILogger::class); + $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); return [ // addSelect('column1') [['configvalue'], ['appid' => 'testFirstResult', 'configvalue' => '99']], @@ -1200,4 +1216,130 @@ class QueryBuilderTest extends \Test\TestCase { $this->queryBuilder->getColumnName($column, $prefix) ); } + + public function testExecuteWithoutLogger() { + $queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class); + $queryBuilder + ->expects($this->once()) + ->method('execute') + ->willReturn(3); + $this->logger + ->expects($this->never()) + ->method('debug'); + $this->config + ->expects($this->once()) + ->method('getValue') + ->with('log_query', false) + ->willReturn(false); + + $this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]); + $this->assertEquals(3, $this->queryBuilder->execute()); + } + + public function testExecuteWithLoggerAndNamedArray() { + $queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class); + $queryBuilder + ->expects($this->at(0)) + ->method('getParameters') + ->willReturn([ + 'foo' => 'bar', + 'key' => 'value', + ]); + $queryBuilder + ->expects($this->at(1)) + ->method('getSQL') + ->willReturn('SELECT * FROM FOO WHERE BAR = ?'); + $queryBuilder + ->expects($this->once()) + ->method('execute') + ->willReturn(3); + $this->logger + ->expects($this->once()) + ->method('debug') + ->with( + 'DB QueryBuilder: \'{query}\' with parameters: {params}', + [ + 'query' => 'SELECT * FROM FOO WHERE BAR = ?', + 'params' => 'foo => \'bar\', key => \'value\'', + 'app' => 'core', + ] + ); + $this->config + ->expects($this->once()) + ->method('getValue') + ->with('log_query', false) + ->willReturn(true); + + $this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]); + $this->assertEquals(3, $this->queryBuilder->execute()); + } + + public function testExecuteWithLoggerAndUnnamedArray() { + $queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class); + $queryBuilder + ->expects($this->at(0)) + ->method('getParameters') + ->willReturn(['Bar']); + $queryBuilder + ->expects($this->at(1)) + ->method('getSQL') + ->willReturn('SELECT * FROM FOO WHERE BAR = ?'); + $queryBuilder + ->expects($this->once()) + ->method('execute') + ->willReturn(3); + $this->logger + ->expects($this->once()) + ->method('debug') + ->with( + 'DB QueryBuilder: \'{query}\' with parameters: {params}', + [ + 'query' => 'SELECT * FROM FOO WHERE BAR = ?', + 'params' => '0 => \'Bar\'', + 'app' => 'core', + ] + ); + $this->config + ->expects($this->once()) + ->method('getValue') + ->with('log_query', false) + ->willReturn(true); + + $this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]); + $this->assertEquals(3, $this->queryBuilder->execute()); + } + + public function testExecuteWithLoggerAndNoParams() { + $queryBuilder = $this->createMock(\Doctrine\DBAL\Query\QueryBuilder::class); + $queryBuilder + ->expects($this->at(0)) + ->method('getParameters') + ->willReturn([]); + $queryBuilder + ->expects($this->at(1)) + ->method('getSQL') + ->willReturn('SELECT * FROM FOO WHERE BAR = ?'); + $queryBuilder + ->expects($this->once()) + ->method('execute') + ->willReturn(3); + $this->logger + ->expects($this->once()) + ->method('debug') + ->with( + 'DB QueryBuilder: \'{query}\'', + [ + 'query' => 'SELECT * FROM FOO WHERE BAR = ?', + 'app' => 'core', + ] + ); + $this->config + ->expects($this->once()) + ->method('getValue') + ->with('log_query', false) + ->willReturn(true); + + $this->invokePrivate($this->queryBuilder, 'queryBuilder', [$queryBuilder]); + $this->assertEquals(3, $this->queryBuilder->execute()); + } } diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php index 0af90991d60..9aa0143b4a7 100644 --- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php +++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php @@ -80,7 +80,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->equalTo('uid'), $this->equalTo('homeobjectstore'), $this->equalTo('bucket'), - $this->equalTo('987'), + $this->equalTo('49'), $this->equalTo(null) ); @@ -94,7 +94,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->assertArrayHasKey('objectstore', $config['arguments']); $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); $this->assertArrayHasKey('bucket', $config['arguments']); - $this->assertEquals('987', $config['arguments']['bucket']); + $this->assertEquals('49', $config['arguments']['bucket']); } public function testMultiBucketWithPrefix() { @@ -127,7 +127,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->equalTo('uid'), $this->equalTo('homeobjectstore'), $this->equalTo('bucket'), - $this->equalTo('myBucketPrefix987'), + $this->equalTo('myBucketPrefix49'), $this->equalTo(null) ); @@ -141,7 +141,7 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->assertArrayHasKey('objectstore', $config['arguments']); $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); $this->assertArrayHasKey('bucket', $config['arguments']); - $this->assertEquals('myBucketPrefix987', $config['arguments']['bucket']); + $this->assertEquals('myBucketPrefix49', $config['arguments']['bucket']); } public function testMultiBucketBucketAlreadySet() { diff --git a/tests/lib/Files/ObjectStore/MapperTest.php b/tests/lib/Files/ObjectStore/MapperTest.php index 18bdcdfd005..19451622fa3 100644 --- a/tests/lib/Files/ObjectStore/MapperTest.php +++ b/tests/lib/Files/ObjectStore/MapperTest.php @@ -28,24 +28,28 @@ class MapperTest extends \Test\TestCase { public function dataGetBucket() { return [ - ['user', substr(md5('user'), 0, 3)], - ['USER', substr(md5('USER'), 0, 3)], - ['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', substr(md5('bc0e8b52-a66c-1035-90c6-d9663bda9e3f'), 0, 3)], + ['user', 64, '17'], + ['USER', 64, '0'], + ['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', 64, '56'], + ['user', 8, '1'], + ['user', 2, '1'], + ['USER', 2, '0'], ]; } /** * @dataProvider dataGetBucket * @param string $username + * @param int $numBuckets * @param string $expectedBucket */ - public function testGetBucket($username, $expectedBucket) { + public function testGetBucket($username, $numBuckets, $expectedBucket) { $user = $this->createMock(IUser::class); $user->method('getUID') ->willReturn($username); $mapper = new Mapper($user); - $this->assertSame($expectedBucket, $mapper->getBucket()); + $this->assertSame($expectedBucket, $mapper->getBucket($numBuckets)); } } diff --git a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php index 550fa49e1b2..d1e76684507 100644 --- a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php +++ b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php @@ -21,6 +21,8 @@ namespace Test\Security\CSRF\TokenStorage; +use OCP\ISession; + class SessionStorageTest extends \Test\TestCase { /** @var \OCP\ISession */ private $session; @@ -106,4 +108,15 @@ class SessionStorageTest extends \Test\TestCase { ->willReturn(false); $this->assertSame(false, $this->sessionStorage->hasToken()); } + + public function testSetSession() { + $session = $this->createMock(ISession::class); + $session + ->expects($this->once()) + ->method('get') + ->with('requesttoken') + ->willReturn('MyToken'); + $this->sessionStorage->setSession($session); + $this->assertSame('MyToken', $this->sessionStorage->getToken()); + } } diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index cffcc02817c..38da26a21a9 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -21,6 +21,8 @@ namespace Test\Security; +use OC\SystemConfig; +use OCP\ILogger; use \OCP\Security\ICrypto; use \OCP\IDBConnection; use \OC\Security\CredentialsManager; @@ -45,7 +47,7 @@ class CredentialsManagerTest extends \Test\TestCase { $this->manager = new CredentialsManager($this->crypto, $this->dbConnection); } - private function getQeuryResult($row) { + private function getQueryResult($row) { $result = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement') ->disableOriginalConstructor() ->getMock(); @@ -87,12 +89,16 @@ class CredentialsManagerTest extends \Test\TestCase { ->willReturn(json_encode('bar')); $qb = $this->getMockBuilder('\OC\DB\QueryBuilder\QueryBuilder') - ->setConstructorArgs([$this->dbConnection]) + ->setConstructorArgs([ + $this->dbConnection, + $this->createMock(SystemConfig::class), + $this->createMock(ILogger::class), + ]) ->setMethods(['execute']) ->getMock(); $qb->expects($this->once()) ->method('execute') - ->willReturn($this->getQeuryResult(['credentials' => 'baz'])); + ->willReturn($this->getQueryResult(['credentials' => 'baz'])); $this->dbConnection->expects($this->once()) ->method('getQueryBuilder') |