Skip to content

Commit

Permalink
Merge pull request #27621 from owncloud/cannot_create_external_storage
Browse files Browse the repository at this point in the history
Checking for local external storage flag iff the method is local.
  • Loading branch information
Vincent Petry authored Apr 12, 2017
2 parents 04e3aac + afce27c commit b526666
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 72 deletions.
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) {
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

0 comments on commit b526666

Please sign in to comment.