Skip to content

Commit

Permalink
MAGETWO-59809: Scrub sensitive data during app:dump
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftedreality committed Nov 2, 2016
1 parent 0f97776 commit f33dd60
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 14 deletions.
3 changes: 1 addition & 2 deletions app/code/Magento/Config/Model/Config/Export/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Magento\Config\App\Config\Source\DumpConfigSourceInterface;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Config\Model\Placeholder\Environment;
use Magento\Framework\App\Config\CommentInterface;

/**
Expand All @@ -35,7 +34,7 @@ public function __construct(
PlaceholderFactory $placeholderFactory,
DumpConfigSourceInterface $source
) {
$this->placeholder = $placeholderFactory->create(Environment::class);
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
$this->source = $source;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
namespace Magento\Config\Model\Config\Processor;

use Magento\Config\Model\Placeholder\Environment;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Framework\App\Config\Spi\PreProcessorInterface;
Expand Down Expand Up @@ -38,7 +37,7 @@ public function __construct(
) {
$this->placeholderFactory = $placeholderFactory;
$this->arrayManager = $arrayManager;
$this->placeholder = $placeholderFactory->create(Environment::class);
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\Framework\App\DeploymentConfig;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Config\Model\Placeholder\Environment;
use Magento\Framework\App\Config\ScopeCodeResolver;

/**
Expand Down Expand Up @@ -50,7 +49,7 @@ public function __construct(
) {
$this->config = $config;
$this->scopeCodeResolver = $scopeCodeResolver;
$this->placeholder = $placeholderFactory->create(Environment::class);
$this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
}

/**
Expand Down
24 changes: 21 additions & 3 deletions app/code/Magento/Config/Model/Placeholder/PlaceholderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,53 @@
*/
namespace Magento\Config\Model\Placeholder;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManagerInterface;

class PlaceholderFactory
{
/**
* @const string Environment type
*/
const TYPE_ENVIRONMENT = 'environment';

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var array
*/
private $types;

/**
* @param ObjectManagerInterface $objectManager
* @param array $types
*/
public function __construct(ObjectManagerInterface $objectManager)
public function __construct(ObjectManagerInterface $objectManager, array $types = [])
{
$this->objectManager = $objectManager;
$this->types = $types;
}

/**
* Create placeholder
*
* @param string $type
* @return PlaceholderInterface
* @throws LocalizedException
*/
public function create($type)
{
$object = $this->objectManager->create($type);
if (!isset($this->types[$type])) {
throw new LocalizedException(__('There is no defined type ' . $type));
}

$object = $this->objectManager->create($this->types[$type]);

if (!$object instanceof PlaceholderInterface) {
throw new \LogicException('Object is not instance of ' . PlaceholderInterface::class);
throw new LocalizedException(__('Object is not instance of ' . PlaceholderInterface::class));
}

return $object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function setUp()
->getMock();
$placeholderFactoryMock->expects($this->once())
->method('create')
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
->willReturn($this->placeholderMock);

$this->configSourceMock = $this->getMockBuilder(DumpConfigSourceInterface::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Magento\Config\Test\Unit\Model\Config\Processor;

use Magento\Config\Model\Config\Processor\EnvironmentPlaceholder;
use Magento\Config\Model\Placeholder\Environment;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Framework\Stdlib\ArrayManager;
Expand Down Expand Up @@ -53,6 +52,7 @@ protected function setUp()

$this->placeholderFactoryMock->expects($this->any())
->method('create')
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
->willReturn($this->placeholderMock);

$this->model = new EnvironmentPlaceholder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Framework\App\DeploymentConfig;
use Magento\Config\Model\Placeholder\PlaceholderInterface;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Config\Model\Placeholder\Environment;

/**
* Test class for checking settings that defined in config file
Expand Down Expand Up @@ -60,7 +59,7 @@ public function setUp()

$placeholderFactoryMock->expects($this->once())
->method('create')
->with(Environment::class)
->with(PlaceholderFactory::TYPE_ENVIRONMENT)
->willReturn($this->placeholderMock);

$this->checker = new SettingChecker($this->configMock, $placeholderFactoryMock, $this->scopeCodeResolverMock);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Test\Unit\Model\Placeholder;

use Magento\Config\Model\Placeholder\Environment;
use Magento\Config\Model\Placeholder\PlaceholderFactory;
use Magento\Framework\ObjectManagerInterface;

class PlaceholderFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PlaceholderFactory
*/
private $model;

/**
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $objectManagerMock;

/**
* @var Environment|\PHPUnit_Framework_MockObject_MockObject
*/
private $environmentMock;

protected function setUp()
{
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
->getMockForAbstractClass();
$this->environmentMock = $this->getMockBuilder(Environment::class)
->disableOriginalConstructor()
->getMock();

$this->model = new PlaceholderFactory(
$this->objectManagerMock,
[
PlaceholderFactory::TYPE_ENVIRONMENT => Environment::class,
'wrongClass' => \stdClass::class,
]
);
}

public function testCreate()
{
$this->objectManagerMock->expects($this->once())
->method('create')
->with(Environment::class)
->willReturn($this->environmentMock);

$this->assertInstanceOf(
Environment::class,
$this->model->create(PlaceholderFactory::TYPE_ENVIRONMENT)
);
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage There is no defined type dummyClass
*/
public function testCreateNonExisted()
{
$this->model->create('dummyClass');
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Object is not instance of Magento\Config\Model\Placeholder\PlaceholderInterface
*/
public function testCreateWrongImplementation()
{
$this->model->create('wrongClass');
}
}
6 changes: 4 additions & 2 deletions app/code/Magento/Config/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@
<argument name="source" xsi:type="object">appDumpSystemSource</argument>
</arguments>
</type>
<type name="Magento\Config\Model\Config\Structure">
<type name="Magento\Config\Model\Placeholder\PlaceholderFactory">
<arguments>
<argument name="tabIterator" xsi:type="object">Magento\Config\Model\Config\Structure\Element\Iterator\Tab\Proxy</argument>
<argument name="types" xsi:type="array">
<item name="environment" xsi:type="string">Magento\Config\Model\Placeholder\Environment</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit f33dd60

Please sign in to comment.