Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions apps/files_external/lib/Controller/GlobalStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public function create(
) {
$canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', false);

if ($canCreateNewLocalStorage === true) {
if ($backend === 'local' && $canCreateNewLocalStorage === false) {
return new DataResponse(
null,
Http::STATUS_FORBIDDEN
);
}

$newStorage = $this->createStorage(
$mountPoint,
$backend,
Expand Down Expand Up @@ -119,14 +125,6 @@ public function create(
);
}

else {
return new DataResponse(
null,
Http::STATUS_FORBIDDEN
);
}
}

/**
* Update an external storage entry.
*
Expand Down
16 changes: 7 additions & 9 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ public function create(
) {
$canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', false);

if ($canCreateNewLocalStorage === true) {
if ($backend === 'local' && $canCreateNewLocalStorage === false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove this completely, users are never allowed to setup local storages for security reasons

return new DataResponse(
null,
Http::STATUS_FORBIDDEN
);
}

$newStorage = $this->createStorage(
$mountPoint,
$backend,
Expand All @@ -154,14 +160,6 @@ public function create(
);
}

else {
return new DataResponse(
null,
Http::STATUS_FORBIDDEN
);
}
}

/**
* Update an external storage entry.
*
Expand Down
36 changes: 21 additions & 15 deletions apps/files_external/tests/Controller/StoragesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB'
return $backend;
}

/**
* @return \OCP\Files\External\Backend\Backend
*/
protected function getBackendMockLocal($class = '\OCA\Files_External\Lib\Backend\Local', $storageClass = '\OC\Files\Storage\Local') {
$backend = $this->getMockBuilder('\OCP\Files\External\Backend\Backend')
->disableOriginalConstructor()
->getMock();
$backend->method('getStorageClass')
->willReturn($storageClass);
$backend->method('getIdentifier')
->willReturn('identifier:'.$class);
return $backend;
}

/**
* @return \OCP\Files\External\Auth\AuthMechanism
*/
Expand Down Expand Up @@ -125,34 +139,26 @@ public function testAddStorage() {
public function testAddStorageWithoutConfig() {
\OC::$server->getSystemConfig()->setValue('files_external_allow_create_new_local', false);

$authMech = $this->getAuthMechMock();
$authMech->method('validateStorage')
->willReturn(true);
$authMech->method('isVisibleFor')
->willReturn(true);
$backend = $this->getBackendMock();
$backend = $this->getBackendMockLocal();
$backend->method('validateStorage')
->willReturn(true);
$backend->method('isVisibleFor')
->willReturn(true);

$storageConfig = new StorageConfig(1);
$storageConfig->setMountPoint('mount');
$storageConfig->setMountPoint('Local');
$storageConfig->setBackend($backend);
$storageConfig->setAuthMechanism($authMech);
$storageConfig->setBackendOptions([]);

$this->service->expects($this->never())
$this->service
->method('createStorage')
->will($this->returnValue($storageConfig));
$this->service->expects($this->never())
$this->service
->method('addStorage')
->will($this->returnValue($storageConfig));

$response = $this->controller->create(
'mount',
'\OCA\Files_External\Lib\Storage\SMB',
'\OCA\Files_External\Lib\Auth\NullMechanism',
'Local',
'local',
null,
[],
[],
[],
Expand Down