Skip to content

Commit 83d62dc

Browse files
author
Oleksandr Gorkun
committed
MC-19926: Implement CSP
1 parent 55f414f commit 83d62dc

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

app/code/Magento/Csp/Model/Collector/ConfigCollector.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
use Magento\Framework\App\Area;
1313
use Magento\Framework\App\Config\ScopeConfigInterface;
1414
use Magento\Framework\App\State;
15+
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\Store\Model\ScopeInterface;
16-
use Magento\Store\Model\Store;
1717

1818
/**
1919
* Reads Magento config.
@@ -36,26 +36,26 @@ class ConfigCollector implements PolicyCollectorInterface
3636
private $state;
3737

3838
/**
39-
* @var Store
39+
* @var StoreManagerInterface
4040
*/
41-
private $storeModel;
41+
private $storeManager;
4242

4343
/**
4444
* @param ScopeConfigInterface $config
4545
* @param PolicyReaderPool $readersPool
4646
* @param State $state
47-
* @param Store $storeModel
47+
* @param StoreManagerInterface $storeManager
4848
*/
4949
public function __construct(
5050
ScopeConfigInterface $config,
5151
PolicyReaderPool $readersPool,
5252
State $state,
53-
Store $storeModel
53+
StoreManagerInterface $storeManager
5454
) {
5555
$this->config = $config;
5656
$this->readersPool = $readersPool;
5757
$this->state = $state;
58-
$this->storeModel = $storeModel;
58+
$this->storeManager = $storeManager;
5959
}
6060

6161
/**
@@ -77,7 +77,7 @@ public function collect(array $defaultPolicies = []): array
7777
$policiesConfig = $this->config->getValue(
7878
'csp/policies/' . $configArea,
7979
ScopeInterface::SCOPE_STORE,
80-
$this->storeModel->getStore()
80+
$this->storeManager->getStore()
8181
);
8282
if (is_array($policiesConfig) && $policiesConfig) {
8383
foreach ($policiesConfig as $policyConfig) {

app/code/Magento/Csp/etc/csp_whitelist.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
/**
4-
* Structure description for webapi.xml configuration files.
4+
* Structure description for csp_whitelist.xml configuration files.
55
*
66
* Copyright © Magento, Inc. All rights reserved.
77
* See COPYING.txt for license details.

dev/tests/integration/testsuite/Magento/Csp/Model/Collector/ConfigCollectorTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,17 @@ private function getExpectedPolicies(): array
160160
*/
161161
public function testCollecting(): void
162162
{
163-
$policies = $this->collector->collect([]);
163+
$policies = $this->collector->collect([new FlagPolicy('upgrade-insecure-requests')]);
164164
$checked = [];
165165
$expectedPolicies = $this->getExpectedPolicies();
166166

167+
//Policies were collected
167168
$this->assertNotEmpty($policies);
169+
//Default policies are being kept
170+
/** @var PolicyInterface $defaultPolicy */
171+
$defaultPolicy = array_shift($policies);
172+
$this->assertEquals('upgrade-insecure-requests', $defaultPolicy->getId());
173+
//Comparing collected with configured
168174
/** @var PolicyInterface $policy */
169175
foreach ($policies as $policy) {
170176
$id = $policy->getId();

0 commit comments

Comments
 (0)