Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for local external storage flag iff the method is local. #27621

Merged
merged 4 commits into from
Apr 12, 2017
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
58 changes: 28 additions & 30 deletions apps/files_external/lib/Controller/GlobalStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,40 @@ public function create(
) {
$canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', false);

if ($canCreateNewLocalStorage === true) {
$newStorage = $this->createStorage(
$mountPoint,
$backend,
$authMechanism,
$backendOptions,
$mountOptions,
$applicableUsers,
$applicableGroups,
$priority
if ($backend === 'local' && $canCreateNewLocalStorage === false) {
return new DataResponse(
null,
Http::STATUS_FORBIDDEN
);
if ($newStorage instanceof DataResponse) {
return $newStorage;
}
}

$response = $this->validate($newStorage);
if (!empty($response)) {
return $response;
}
$newStorage = $this->createStorage(
$mountPoint,
$backend,
$authMechanism,
$backendOptions,
$mountOptions,
$applicableUsers,
$applicableGroups,
$priority
);
if ($newStorage instanceof DataResponse) {
return $newStorage;
}

$newStorage = $this->service->addStorage($newStorage);
$response = $this->validate($newStorage);
if (!empty($response)) {
return $response;
}

$this->updateStorageStatus($newStorage);
$newStorage = $this->service->addStorage($newStorage);

return new DataResponse(
$newStorage,
Http::STATUS_CREATED
);
}
$this->updateStorageStatus($newStorage);

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

/**
Expand Down
52 changes: 25 additions & 27 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,36 @@ public function create(
) {
$canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', false);

if ($canCreateNewLocalStorage === true) {
$newStorage = $this->createStorage(
$mountPoint,
$backend,
$authMechanism,
$backendOptions,
$mountOptions
);
if ($newStorage instanceOf DataResponse) {
return $newStorage;
}

$response = $this->validate($newStorage);
if (!empty($response)) {
return $response;
}

$newStorage = $this->service->addStorage($newStorage);
$this->updateStorageStatus($newStorage);

return new DataResponse(
$newStorage,
Http::STATUS_CREATED
);
}

else {
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,
$authMechanism,
$backendOptions,
$mountOptions
);
if ($newStorage instanceOf DataResponse) {
return $newStorage;
}

$response = $this->validate($newStorage);
if (!empty($response)) {
return $response;
}

$newStorage = $this->service->addStorage($newStorage);
$this->updateStorageStatus($newStorage);

return new DataResponse(
$newStorage,
Http::STATUS_CREATED
);
}

/**
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