Browse Source
Merge pull request #719 from nextcloud/lockdown
Merge pull request #719 from nextcloud/lockdown
Allow restricting of app password permissionspull/2164/head
committed by
GitHub
28 changed files with 1336 additions and 41 deletions
-
1apps/dav/lib/Connector/Sabre/Auth.php
-
7db_structure.xml
-
4lib/composer/composer/autoload_classmap.php
-
4lib/composer/composer/autoload_static.php
-
33lib/private/Authentication/Token/DefaultToken.php
-
31lib/private/Authentication/Token/DefaultTokenMapper.php
-
17lib/private/Authentication/Token/DefaultTokenProvider.php
-
11lib/private/Authentication/Token/IProvider.php
-
23lib/private/Authentication/Token/IToken.php
-
42lib/private/Files/Filesystem.php
-
122lib/private/Lockdown/Filesystem/NullCache.php
-
177lib/private/Lockdown/Filesystem/NullStorage.php
-
46lib/private/Lockdown/LockdownManager.php
-
11lib/private/Server.php
-
1lib/private/User/Session.php
-
50lib/public/Lockdown/ILockdownManager.php
-
20settings/Controller/AuthSettingsController.php
-
57settings/css/settings.css
-
53settings/js/authtoken_view.js
-
39tests/Settings/Controller/AuthSettingsControllerTest.php
-
40tests/lib/Authentication/Token/DefaultTokenMapperTest.php
-
23tests/lib/Authentication/Token/DefaultTokenProviderTest.php
-
49tests/lib/Authentication/Token/DefaultTokenTest.php
-
63tests/lib/Lockdown/Filesystem/NoFSTest.php
-
157tests/lib/Lockdown/Filesystem/NullCacheTest.php
-
245tests/lib/Lockdown/Filesystem/NullStorageTest.php
-
49tests/lib/Lockdown/LockdownManagerTest.php
-
2version.php
@ -0,0 +1,122 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* This code is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License, version 3, |
|||
* as published by the Free Software Foundation. |
|||
* |
|||
* 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, version 3, |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|||
* |
|||
*/ |
|||
|
|||
namespace OC\Lockdown\Filesystem; |
|||
|
|||
use OC\Files\Cache\CacheEntry; |
|||
use OCP\Constants; |
|||
use OCP\Files\Cache\ICache; |
|||
use OCP\Files\Cache\ICacheEntry; |
|||
use OCP\Files\FileInfo; |
|||
|
|||
class NullCache implements ICache { |
|||
public function getNumericStorageId() { |
|||
return -1; |
|||
} |
|||
|
|||
public function get($file) { |
|||
return $file !== '' ? null : |
|||
new CacheEntry([ |
|||
'fileid' => -1, |
|||
'parent' => -1, |
|||
'name' => '', |
|||
'path' => '', |
|||
'size' => '0', |
|||
'mtime' => time(), |
|||
'storage_mtime' => time(), |
|||
'etag' => '', |
|||
'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|||
'mimepart' => 'httpd', |
|||
'permissions' => Constants::PERMISSION_READ |
|||
]); |
|||
} |
|||
|
|||
public function getFolderContents($folder) { |
|||
return []; |
|||
} |
|||
|
|||
public function getFolderContentsById($fileId) { |
|||
return []; |
|||
} |
|||
|
|||
public function put($file, array $data) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function insert($file, array $data) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function update($id, array $data) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function getId($file) { |
|||
return -1; |
|||
} |
|||
|
|||
public function getParentId($file) { |
|||
return -1; |
|||
} |
|||
|
|||
public function inCache($file) { |
|||
return $file === ''; |
|||
} |
|||
|
|||
public function remove($file) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function move($source, $target) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function getStatus($file) { |
|||
return ICache::COMPLETE; |
|||
} |
|||
|
|||
public function search($pattern) { |
|||
return []; |
|||
} |
|||
|
|||
public function searchByMime($mimetype) { |
|||
return []; |
|||
} |
|||
|
|||
public function searchByTag($tag, $userId) { |
|||
return []; |
|||
} |
|||
|
|||
public function getIncomplete() { |
|||
return []; |
|||
} |
|||
|
|||
public function getPathById($id) { |
|||
return ''; |
|||
} |
|||
|
|||
public function normalize($path) { |
|||
return $path; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,177 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* This code is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License, version 3, |
|||
* as published by the Free Software Foundation. |
|||
* |
|||
* 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, version 3, |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|||
* |
|||
*/ |
|||
|
|||
namespace OC\Lockdown\Filesystem; |
|||
|
|||
use Icewind\Streams\IteratorDirectory; |
|||
use OC\Files\Storage\Common; |
|||
|
|||
class NullStorage extends Common { |
|||
public function __construct($parameters) { |
|||
parent::__construct($parameters); |
|||
} |
|||
|
|||
public function getId() { |
|||
return 'null'; |
|||
} |
|||
|
|||
public function mkdir($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function rmdir($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function opendir($path) { |
|||
return new IteratorDirectory([]); |
|||
} |
|||
|
|||
public function is_dir($path) { |
|||
return $path === ''; |
|||
} |
|||
|
|||
public function is_file($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function stat($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function filetype($path) { |
|||
return ($path === '') ? 'dir' : false; |
|||
} |
|||
|
|||
public function filesize($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function isCreatable($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function isReadable($path) { |
|||
return $path === ''; |
|||
} |
|||
|
|||
public function isUpdatable($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function isDeletable($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function isSharable($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function getPermissions($path) { |
|||
return null; |
|||
} |
|||
|
|||
public function file_exists($path) { |
|||
return $path === ''; |
|||
} |
|||
|
|||
public function filemtime($path) { |
|||
return ($path === '') ? time() : false; |
|||
} |
|||
|
|||
public function file_get_contents($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function file_put_contents($path, $data) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function unlink($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function rename($path1, $path2) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function copy($path1, $path2) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function fopen($path, $mode) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function getMimeType($path) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function hash($type, $path, $raw = false) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function free_space($path) { |
|||
return 0; |
|||
} |
|||
|
|||
public function touch($path, $mtime = null) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function getLocalFile($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function hasUpdated($path, $time) { |
|||
return false; |
|||
} |
|||
|
|||
public function getETag($path) { |
|||
return ''; |
|||
} |
|||
|
|||
public function isLocal() { |
|||
return false; |
|||
} |
|||
|
|||
public function getDirectDownload($path) { |
|||
return false; |
|||
} |
|||
|
|||
public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|||
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|||
} |
|||
|
|||
public function test() { |
|||
return true; |
|||
} |
|||
|
|||
public function getOwner($path) { |
|||
return null; |
|||
} |
|||
|
|||
public function getCache($path = '', $storage = null) { |
|||
return new NullCache(); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* This code is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License, version 3, |
|||
* as published by the Free Software Foundation. |
|||
* |
|||
* 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, version 3, |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|||
* |
|||
*/ |
|||
|
|||
namespace OC\Lockdown; |
|||
|
|||
use OC\Authentication\Token\IToken; |
|||
use OCP\Lockdown\ILockdownManager; |
|||
|
|||
class LockdownManager implements ILockdownManager { |
|||
private $enabled = false; |
|||
|
|||
/** @var array|null */ |
|||
private $scope; |
|||
|
|||
public function enable() { |
|||
$this->enabled = true; |
|||
} |
|||
|
|||
public function setToken(IToken $token) { |
|||
$this->scope = $token->getScopeAsArray(); |
|||
$this->enable(); |
|||
} |
|||
|
|||
public function canAccessFilesystem() { |
|||
if (!$this->enabled) { |
|||
return true; |
|||
} |
|||
return !$this->scope || $this->scope['filesystem']; |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* This code is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License, version 3, |
|||
* as published by the Free Software Foundation. |
|||
* |
|||
* 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, version 3, |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|||
* |
|||
*/ |
|||
|
|||
namespace OCP\Lockdown; |
|||
|
|||
use OC\Authentication\Token\IToken; |
|||
|
|||
/** |
|||
* @since 9.2 |
|||
*/ |
|||
interface ILockdownManager { |
|||
/** |
|||
* Enable the lockdown restrictions |
|||
* |
|||
* @since 9.2 |
|||
*/ |
|||
public function enable(); |
|||
|
|||
/** |
|||
* Set the active token to get the restrictions from and enable the lockdown |
|||
* |
|||
* @param IToken $token |
|||
* @since 9.2 |
|||
*/ |
|||
public function setToken(IToken $token); |
|||
|
|||
/** |
|||
* Check whether or not filesystem access is allowed |
|||
* |
|||
* @return bool |
|||
* @since 9.2 |
|||
*/ |
|||
public function canAccessFilesystem(); |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
<?php |
|||
/** |
|||
* @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* @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\Authentication\Token; |
|||
|
|||
use OC\Authentication\Token\DefaultToken; |
|||
use Test\TestCase; |
|||
|
|||
class DefaultTokenTest extends TestCase { |
|||
public function testSetScopeAsArray() { |
|||
$scope = ['filesystem' => false]; |
|||
$token = new DefaultToken(); |
|||
$token->setScope($scope); |
|||
$this->assertEquals(json_encode($scope), $token->getScope()); |
|||
$this->assertEquals($scope, $token->getScopeAsArray()); |
|||
} |
|||
|
|||
public function testSetScopeAsString() { |
|||
$scope = ['filesystem' => false]; |
|||
$token = new DefaultToken(); |
|||
$token->setScope(json_encode($scope)); |
|||
$this->assertEquals(json_encode($scope), $token->getScope()); |
|||
$this->assertEquals($scope, $token->getScopeAsArray()); |
|||
} |
|||
|
|||
public function testDefaultScope() { |
|||
$scope = ['filesystem' => true]; |
|||
$token = new DefaultToken(); |
|||
$this->assertEquals($scope, $token->getScopeAsArray()); |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
<?php |
|||
/** |
|||
* @copyright 2016, Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* @author Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* @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\Lockdown\Filesystem; |
|||
|
|||
use OC\Authentication\Token\DefaultToken; |
|||
use OC\Files\Filesystem; |
|||
use OC\Lockdown\Filesystem\NullStorage; |
|||
use Test\Traits\UserTrait; |
|||
|
|||
/** |
|||
* @group DB |
|||
*/ |
|||
class NoFSTest extends \Test\TestCase { |
|||
use UserTrait; |
|||
|
|||
public function tearDown() { |
|||
$token = new DefaultToken(); |
|||
$token->setScope([ |
|||
'filesystem' => true |
|||
]); |
|||
\OC::$server->getLockdownManager()->setToken($token); |
|||
return parent::tearDown(); |
|||
} |
|||
|
|||
public function setUp() { |
|||
parent::setUp(); |
|||
$token = new DefaultToken(); |
|||
$token->setScope([ |
|||
'filesystem' => false |
|||
]); |
|||
|
|||
\OC::$server->getLockdownManager()->setToken($token); |
|||
$this->createUser('foo', 'var'); |
|||
} |
|||
|
|||
public function testSetupFS() { |
|||
\OC_Util::tearDownFS(); |
|||
\OC_Util::setupFS('foo'); |
|||
|
|||
$this->assertInstanceOf(NullStorage::class, Filesystem::getStorage('/foo/files')); |
|||
} |
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
<?php |
|||
/** |
|||
* @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl> |
|||
* |
|||
* @author Roeland Jago Douma <roeland@famdouma.nl> |
|||
* |
|||
* @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\Lockdown\Filesystem; |
|||
|
|||
use OC\ForbiddenException; |
|||
use OC\Lockdown\Filesystem\NullCache; |
|||
use OCP\Constants; |
|||
use OCP\Files\Cache\ICache; |
|||
use OCP\Files\FileInfo; |
|||
|
|||
class NulLCacheTest extends \Test\TestCase { |
|||
|
|||
/** @var NullCache */ |
|||
private $cache; |
|||
|
|||
public function setUp() { |
|||
parent::setUp(); |
|||
|
|||
$this->cache = new NullCache(); |
|||
} |
|||
|
|||
public function testGetNumericStorageId() { |
|||
$this->assertSame(-1, $this->cache->getNumericStorageId()); |
|||
} |
|||
|
|||
public function testGetEmpty() { |
|||
$this->assertNull($this->cache->get('foo')); |
|||
} |
|||
|
|||
public function testGet() { |
|||
$data = $this->cache->get(''); |
|||
|
|||
$this->assertEquals(-1, $data['fileid']); |
|||
$this->assertEquals(-1, $data['parent']); |
|||
$this->assertEquals('', $data['name']); |
|||
$this->assertEquals('', $data['path']); |
|||
$this->assertEquals('0', $data['size']); |
|||
$this->assertEquals('', $data['etag']); |
|||
$this->assertEquals(FileInfo::MIMETYPE_FOLDER, $data['mimetype']); |
|||
$this->assertEquals('httpd', $data['mimepart']); |
|||
$this->assertEquals(Constants::PERMISSION_READ, $data['permissions']); |
|||
} |
|||
|
|||
public function testGetFolderContents() { |
|||
$this->assertSame([], $this->cache->getFolderContents('foo')); |
|||
} |
|||
|
|||
public function testGetFolderContentsById() { |
|||
$this->assertSame([], $this->cache->getFolderContentsById(42)); |
|||
} |
|||
|
|||
public function testPut() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->put('foo', ['size' => 100]); |
|||
} |
|||
|
|||
public function testInsert() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->insert('foo', ['size' => 100]); |
|||
} |
|||
|
|||
public function testUpdate() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->update('foo', ['size' => 100]); |
|||
} |
|||
|
|||
public function testGetId() { |
|||
$this->assertSame(-1, $this->cache->getId('foo')); |
|||
} |
|||
|
|||
public function testGetParentId() { |
|||
$this->assertSame(-1, $this->cache->getParentId('foo')); |
|||
} |
|||
|
|||
public function testInCache() { |
|||
$this->assertTrue($this->cache->inCache('')); |
|||
$this->assertFalse($this->cache->inCache('foo')); |
|||
} |
|||
|
|||
public function testRemove() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->remove('foo'); |
|||
} |
|||
|
|||
public function testMove() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->move('foo', 'bar'); |
|||
} |
|||
|
|||
public function testMoveFromCache() { |
|||
$sourceCache = $this->createMock(ICache::class); |
|||
|
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->cache->moveFromCache($sourceCache, 'foo', 'bar'); |
|||
} |
|||
|
|||
public function testGetStatus() { |
|||
$this->assertSame(ICache::COMPLETE, $this->cache->getStatus('foo')); |
|||
} |
|||
|
|||
public function testSearch() { |
|||
$this->assertSame([], $this->cache->search('foo')); |
|||
} |
|||
|
|||
public function testSearchByMime() { |
|||
$this->assertSame([], $this->cache->searchByMime('foo')); |
|||
} |
|||
|
|||
public function testSearchByTag() { |
|||
$this->assertSame([], $this->cache->searchByTag('foo', 'user')); |
|||
} |
|||
|
|||
public function testGetIncomplete() { |
|||
$this->assertSame([], $this->cache->getIncomplete()); |
|||
} |
|||
|
|||
public function testGetPathById() { |
|||
$this->assertSame('', $this->cache->getPathById(42)); |
|||
} |
|||
|
|||
public function testNormalize() { |
|||
$this->assertSame('foo/ bar /', $this->cache->normalize('foo/ bar /')); |
|||
} |
|||
} |
|||
@ -0,0 +1,245 @@ |
|||
<?php |
|||
/** |
|||
* @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl> |
|||
* |
|||
* @author Roeland Jago Douma <roeland@famdouma.nl> |
|||
* |
|||
* @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\Lockdown\Filesystem; |
|||
|
|||
use Icewind\Streams\IteratorDirectory; |
|||
use OC\ForbiddenException; |
|||
use OC\Lockdown\Filesystem\NullCache; |
|||
use OC\Lockdown\Filesystem\NullStorage; |
|||
use OCP\Files\Storage; |
|||
use Test\TestCase; |
|||
|
|||
class NullStorageTest extends TestCase { |
|||
|
|||
/** @var NullStorage */ |
|||
private $storage; |
|||
|
|||
public function setUp() { |
|||
parent::setUp(); |
|||
|
|||
$this->storage = new NullStorage([]); |
|||
} |
|||
|
|||
public function testGetId() { |
|||
$this->assertSame('null', $this->storage->getId()); |
|||
} |
|||
|
|||
public function testMkdir() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->mkdir('foo'); |
|||
} |
|||
|
|||
public function testRmdir() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->rmdir('foo'); |
|||
} |
|||
|
|||
public function testOpendir() { |
|||
$this->assertInstanceOf(IteratorDirectory::class, $this->storage->opendir('foo')); |
|||
} |
|||
|
|||
public function testIs_dir() { |
|||
$this->assertTrue($this->storage->is_dir('')); |
|||
$this->assertFalse($this->storage->is_dir('foo')); |
|||
} |
|||
|
|||
public function testIs_file() { |
|||
$this->assertFalse($this->storage->is_file('foo')); |
|||
} |
|||
|
|||
public function testStat() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->stat('foo'); |
|||
} |
|||
|
|||
public function testFiletype() { |
|||
$this->assertSame('dir', $this->storage->filetype('')); |
|||
$this->assertFalse($this->storage->filetype('foo')); |
|||
} |
|||
|
|||
public function testFilesize() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->filesize('foo'); |
|||
} |
|||
|
|||
public function testIsCreatable() { |
|||
$this->assertFalse($this->storage->isCreatable('foo')); |
|||
} |
|||
|
|||
public function testIsReadable() { |
|||
$this->assertTrue($this->storage->isReadable('')); |
|||
$this->assertFalse($this->storage->isReadable('foo')); |
|||
} |
|||
|
|||
public function testIsUpdatable() { |
|||
$this->assertFalse($this->storage->isUpdatable('foo')); |
|||
} |
|||
|
|||
public function testIsDeletable() { |
|||
$this->assertFalse($this->storage->isDeletable('foo')); |
|||
} |
|||
|
|||
public function testIsSharable() { |
|||
$this->assertFalse($this->storage->isSharable('foo')); |
|||
} |
|||
|
|||
public function testGetPermissions() { |
|||
$this->assertNull($this->storage->getPermissions('foo')); |
|||
} |
|||
|
|||
public function testFile_exists() { |
|||
$this->assertTrue($this->storage->file_exists('')); |
|||
$this->assertFalse($this->storage->file_exists('foo')); |
|||
} |
|||
|
|||
public function testFilemtime() { |
|||
$this->assertFalse($this->storage->filemtime('foo')); |
|||
} |
|||
|
|||
public function testFile_get_contents() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->file_get_contents('foo'); |
|||
} |
|||
|
|||
public function testFile_put_contents() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->file_put_contents('foo', 'bar'); |
|||
} |
|||
|
|||
public function testUnlink() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->unlink('foo'); |
|||
} |
|||
|
|||
public function testRename() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->rename('foo', 'bar'); |
|||
} |
|||
|
|||
public function testCopy() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->copy('foo', 'bar'); |
|||
} |
|||
|
|||
public function testFopen() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->fopen('foo', 'R'); |
|||
} |
|||
|
|||
public function testGetMimeType() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->getMimeType('foo'); |
|||
} |
|||
|
|||
public function testHash() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->hash('md5', 'foo', true); |
|||
} |
|||
|
|||
public function testFree_space() { |
|||
$this->assertSame(0, $this->storage->free_space('foo')); |
|||
} |
|||
|
|||
public function testTouch() { |
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->touch('foo'); |
|||
} |
|||
|
|||
public function testGetLocalFile() { |
|||
$this->assertFalse($this->storage->getLocalFile('foo')); |
|||
} |
|||
|
|||
public function testHasUpdated() { |
|||
$this->assertFalse($this->storage->hasUpdated('foo', 42)); |
|||
} |
|||
|
|||
public function testGetETag() { |
|||
$this->assertSame('', $this->storage->getETag('foo')); |
|||
} |
|||
|
|||
public function testIsLocal() { |
|||
$this->assertFalse($this->storage->isLocal()); |
|||
} |
|||
|
|||
public function testGetDirectDownload() { |
|||
$this->assertFalse($this->storage->getDirectDownload('foo')); |
|||
} |
|||
|
|||
public function testCopyFromStorage() { |
|||
$sourceStorage = $this->createMock(Storage::class); |
|||
|
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->copyFromStorage($sourceStorage, 'foo', 'bar'); |
|||
} |
|||
|
|||
public function testMoveFromStorage() { |
|||
$sourceStorage = $this->createMock(Storage::class); |
|||
|
|||
$this->expectException(ForbiddenException::class); |
|||
$this->expectExceptionMessage('This request is not allowed to access the filesystem'); |
|||
|
|||
$this->storage->moveFromStorage($sourceStorage, 'foo', 'bar'); |
|||
} |
|||
|
|||
public function testTest() { |
|||
$this->assertTrue($this->storage->test()); |
|||
return true; |
|||
} |
|||
|
|||
public function testGetOwner() { |
|||
$this->assertNull($this->storage->getOwner('foo')); |
|||
} |
|||
|
|||
public function testGetCache() { |
|||
$this->assertInstanceOf(NullCache::class, $this->storage->getCache('foo')); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
<?php |
|||
/** |
|||
* @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl> |
|||
* |
|||
* @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\Lockdown; |
|||
|
|||
use OC\Authentication\Token\DefaultToken; |
|||
use OC\Lockdown\LockdownManager; |
|||
use Test\TestCase; |
|||
|
|||
class LockdownManagerTest extends TestCase { |
|||
public function testCanAccessFilesystemDisabled() { |
|||
$manager = new LockdownManager(); |
|||
$this->assertTrue($manager->canAccessFilesystem()); |
|||
} |
|||
|
|||
public function testCanAccessFilesystemAllowed() { |
|||
$token = new DefaultToken(); |
|||
$token->setScope(['filesystem' => true]); |
|||
$manager = new LockdownManager(); |
|||
$manager->setToken($token); |
|||
$this->assertTrue($manager->canAccessFilesystem()); |
|||
} |
|||
|
|||
public function testCanAccessFilesystemNotAllowed() { |
|||
$token = new DefaultToken(); |
|||
$token->setScope(['filesystem' => false]); |
|||
$manager = new LockdownManager(); |
|||
$manager->setToken($token); |
|||
$this->assertFalse($manager->canAccessFilesystem()); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue