Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
PI-1200 Blacklisted some keys
Browse files Browse the repository at this point in the history
  • Loading branch information
manatarms committed Jul 14, 2017
1 parent 17895bd commit e85752e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
21 changes: 1 addition & 20 deletions config.json.sample
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
{
"debug": false,
"featureManagerIsFullZoneProvisioningEnabled": true,
"homePageCards": [
"AlwaysOnlineCard",
"IPV6Card",
"CacheLevelCard",
"RailgunCard",
"PurgeCacheCard"
],
"locale": "en",
"moreSettingsCards": {
"container.moresettings.security": [
"SecurityLevelCard",
"ChallengePassageCard",
"BrowserIntegrityCheckCard"
],
"container.moresettings.speed": [
"MinifyCard",
"DevelopmentModeCard",
"BrowserCacheTTLCard"
]
}
"locale": "en"
}
36 changes: 23 additions & 13 deletions src/Cpanel/PluginActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,39 @@ class PluginActions extends AbstractPluginActions
protected $userConfig;
protected $composer;

public static $CONFIG = array(
const CONFIG = [
'debug' => false,
'featureManagerIsFullZoneProvisioningEnabled' => true,
'isDNSPageEnabled' => true,
'useHostAPILogin' => true,
'homePageCards' => array(
'homePageCards' => [
'AlwaysOnlineCard',
'IPV6Card',
'CacheLevelCard',
'RailgunCard',
'PurgeCacheCard',
),
'moreSettingsCards' => array(
'container.moresettings.security' => array(
],
'moreSettingsCards' => [
'container.moresettings.security' => [
'SecurityLevelCard',
'ChallengePassageCard',
'BrowserIntegrityCheckCard',
),
'container.moresettings.speed' => array(
],
'container.moresettings.speed' => [
'MinifyCard',
'DevelopmentModeCard',
'BrowserCacheTTLCard',
),
),
],
],
'locale' => 'en',
'integrationName' => 'cpanel',
);
];

const BANNED_KEYS = [
'isDNSPageEnabled',
'useHostAPILogin',
'integrationName',
];

/*
* PATCH /plugin/:id/settings/default_settings
Expand All @@ -58,11 +64,15 @@ public function getConfig()
$this->getComposerJson();

//Clone the config to manipulate
$config = array_merge(array(), self::$CONFIG);
$config = array_merge(array(), self::CONFIG);

//Add version from composer.json to the config
$config['version'] = $this->composer['version'];

// Merge and intersect arrays and return responses
//This removes all the banned keys from the userConfig so we don't over write them
$this->userConfig = array_diff_key($this->userConfig, array_flip(self::BANNED_KEYS));

//Merge and intersect userConfig with default config and return response
$response = array_intersect_key($this->userConfig + $config, $config);

return $this->api->createAPISuccessResponse($response);
Expand All @@ -74,7 +84,7 @@ public function getUserConfig()
//Need to suppress the File not found error with @
$userConfigContent = @file_get_contents('./config.json');

//Need to set an empty array for merge into config
//Need to set an empty array for merge into config so it doesnt throw a type error
$this->userConfig = [];
//If we did find a config decode it
if ($userConfigContent) {
Expand Down
21 changes: 20 additions & 1 deletion src/Test/Cpanel/PluginActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testGetConfigReturnsDefaultConfig()
$this->pluginActions->setComposerJson($composer);
$config = array(
'success' => true,
'result' => pluginActions::$CONFIG,
'result' => pluginActions::CONFIG,
'messages' => array(),
'errors' => array(),
);
Expand Down Expand Up @@ -93,4 +93,23 @@ public function testGetConfigIgnoresInvalidKeys()
$response = $this->pluginActions->getConfig();
$this->assertArrayNotHasKey('something', $response);
}

public function testGetConfigIgnoresBannedKeys()
{

$userConfig = [
'isDNSPageEnabled' => false,
'useHostAPILogin' => false,
'integrationName' => 'myName',
];
$this->pluginActions->setUserConfig($userConfig);
$this->mockPluginAPI->method('createAPISuccessResponse')->will($this->returnCallback(function ($config) {
return $config;
}));

$response = $this->pluginActions->getConfig();
$this->assertTrue($response['isDNSPageEnabled']);
$this->assertTrue($response['useHostAPILogin']);
$this->assertEquals($response['integrationName'], 'cpanel');
}
}

0 comments on commit e85752e

Please sign in to comment.