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
Only prevent disabling encrytion via the API
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jul 16, 2019
commit f8592e5e798b9ef07b759c8ece3b1f847239a9ad
13 changes: 9 additions & 4 deletions apps/provisioning_api/lib/Controller/AppConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getValue(string $app, string $key, string $defaultValue = ''): D
public function setValue(string $app, string $key, string $value): DataResponse {
try {
$this->verifyAppId($app);
$this->verifyConfigKey($app, $key);
$this->verifyConfigKey($app, $key, $value);
} catch (\InvalidArgumentException $e) {
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN);
}
Expand All @@ -124,7 +124,7 @@ public function setValue(string $app, string $key, string $value): DataResponse
public function deleteKey(string $app, string $key): DataResponse {
try {
$this->verifyAppId($app);
$this->verifyConfigKey($app, $key);
$this->verifyConfigKey($app, $key, '');
} catch (\InvalidArgumentException $e) {
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN);
}
Expand All @@ -146,14 +146,19 @@ protected function verifyAppId(string $app) {
/**
* @param string $app
* @param string $key
* @param string $value
* @throws \InvalidArgumentException
*/
protected function verifyConfigKey(string $app, string $key) {
protected function verifyConfigKey(string $app, string $key, string $value) {
if (in_array($key, ['installed_version', 'enabled', 'types'])) {
throw new \InvalidArgumentException('The given key can not be set');
}

if ($app === 'core' && ($key === 'encryption_enabled' || strpos($key, 'public_') === 0 || strpos($key, 'remote_') === 0)) {
if ($app === 'core' && $key === 'encryption_enabled' && $value !== 'yes') {
throw new \InvalidArgumentException('The given key can not be set');
}

if ($app === 'core' && (strpos($key, 'public_') === 0 || strpos($key, 'remote_') === 0)) {
throw new \InvalidArgumentException('The given key can not be set');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,32 +342,36 @@ public function testVerifyAppIdThrows($app) {

public function dataVerifyConfigKey() {
return [
['activity', 'abc'],
['dav', 'public_route'],
['files', 'remote_route'],
['activity', 'abc', ''],
['dav', 'public_route', ''],
['files', 'remote_route', ''],
['core', 'encryption_enabled', 'yes'],
];
}

/**
* @dataProvider dataVerifyConfigKey
* @param string $app
* @param string $key
* @param string $value
*/
public function testVerifyConfigKey($app, $key) {
public function testVerifyConfigKey($app, $key, $value) {
$api = $this->getInstance();
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key]);
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key, $value]);
$this->addToAssertionCount(1);
}

public function dataVerifyConfigKeyThrows() {
return [
['activity', 'installed_version'],
['calendar', 'enabled'],
['contacts', 'types'],
['core', 'public_files'],
['core', 'public_dav'],
['core', 'remote_files'],
['core', 'remote_dav'],
['activity', 'installed_version', ''],
['calendar', 'enabled', ''],
['contacts', 'types', ''],
['core', 'encryption_enabled', 'no'],
['core', 'encryption_enabled', ''],
['core', 'public_files', ''],
['core', 'public_dav', ''],
['core', 'remote_files', ''],
['core', 'remote_dav', ''],
];
}

Expand All @@ -376,9 +380,10 @@ public function dataVerifyConfigKeyThrows() {
* @expectedException \InvalidArgumentException
* @param string $app
* @param string $key
* @param string $value
*/
public function testVerifyConfigKeyThrows($app, $key) {
public function testVerifyConfigKeyThrows($app, $key, $value) {
$api = $this->getInstance();
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key]);
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key, $value]);
}
}