- Notifications
You must be signed in to change notification settings - Fork 9.4k
magento/magento2#38933: Putting csp_whitelist.xml in theme does not work and creates intermittent issue #38933 #39672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-devops-reposync-svc merged 11 commits into magento:2.4-develop from NitrogenUA:fix-for-issue-38933 Apr 29, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits Select commit Hold shift + click to select a range
b60b5f8
magento/magento2#38933: Putting csp_whitelist.xml in theme does not w…
NitrogenUA f65f4ab
magento/magento2#38933: Putting csp_whitelist.xml in theme does not w…
NitrogenUA c91126d
Merge branch 'magento:2.4-develop' into fix-for-issue-38933
NitrogenUA 19c9d30
Merge branch '2.4-develop' into fix-for-issue-38933
engcom-Hotel e46b06f
Update app/code/Magento/Csp/Model/Collector/CspWhitelistXml/FileResol…
Den4ik 35ed4a0
Merge branch '2.4-develop' into fix-for-issue-38933
engcom-Dash d7c3b5b
Added Unit Test Cases for CSP FileResolver
engcom-Dash e7b3597
39672: Fixed Review Comments
engcom-Dash 87e2fbf
Merge branch '2.4-develop' into fix-for-issue-38933
engcom-Dash c4bc979
Merge branch '2.4-develop' into fix-for-issue-38933
engcom-Hotel 6847456
Merge branch '2.4-develop' into fix-for-issue-38933
engcom-Dash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions 223 app/code/Magento/Csp/Test/Unit/Model/Collector/CspWhitelistXml/FileResolverTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?php | ||
/** | ||
* Copyright 2025 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
| ||
declare(strict_types=1); | ||
| ||
namespace Magento\Csp\Test\Unit\Model\Collector\CspWhitelistXml; | ||
| ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\View\Design\Theme\CustomizationInterface; | ||
use Magento\Framework\View\Design\ThemeInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\Framework\Config\FileResolverInterface; | ||
use Magento\Csp\Model\Collector\CspWhitelistXml\FileResolver; | ||
use Magento\Framework\View\DesignInterface; | ||
use Magento\Framework\Config\CompositeFileIteratorFactory; | ||
use Magento\Framework\View\Design\Theme\CustomizationInterfaceFactory; | ||
use Magento\Framework\Filesystem\Directory\ReadInterface; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
| ||
class FileResolverTest extends TestCase | ||
{ | ||
/** | ||
* @var FileResolver | ||
*/ | ||
private $model; | ||
| ||
/** | ||
* @var FileResolverInterface | ||
*/ | ||
private $moduleFileResolverMock; | ||
| ||
/** | ||
* @var DesignInterface | ||
*/ | ||
private $designMock; | ||
| ||
/** | ||
* @var CustomizationInterfaceFactory | ||
*/ | ||
private $customizationFactoryMock; | ||
| ||
/** | ||
* @var Filesystem | ||
*/ | ||
private $filesystemMock; | ||
| ||
/** | ||
* @var CompositeFileIteratorFactory | ||
*/ | ||
private $iteratorFactoryMock; | ||
| ||
/** | ||
* @var ReadInterface | ||
*/ | ||
private $readInterfaceMock; | ||
| ||
/** | ||
* @var ThemeInterface | ||
*/ | ||
private $themeInterFaceMock; | ||
| ||
/** | ||
* @var CustomizationInterface | ||
*/ | ||
private $customizationInterfaceMock; | ||
| ||
protected function setUp(): void | ||
{ | ||
$this->moduleFileResolverMock = $this->getMockBuilder(FileResolverInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->designMock = $this->getMockBuilder(DesignInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->themeInterFaceMock = $this->getMockBuilder(ThemeInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->designMock->expects($this->once()) | ||
->method('getDesignTheme') | ||
->willReturn($this->themeInterFaceMock); | ||
| ||
$this->customizationFactoryMock = $this->getMockBuilder(CustomizationInterfaceFactory::class) | ||
->disableOriginalConstructor() | ||
->onlyMethods(['create']) | ||
->getMock(); | ||
| ||
$this->customizationInterfaceMock = $this->getMockBuilder(CustomizationInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->filesystemMock = $this->createPartialMock(Filesystem::class, ['getDirectoryRead']); | ||
| ||
$this->readInterfaceMock = $this->getMockBuilder(ReadInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->filesystemMock->expects($this->once()) | ||
->method('getDirectoryRead') | ||
->with(DirectoryList::ROOT) | ||
->willReturn($this->readInterfaceMock); | ||
| ||
$this->iteratorFactoryMock = $this->getMockBuilder(CompositeFileIteratorFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
| ||
$this->model = new FileResolver( | ||
$this->moduleFileResolverMock, | ||
$this->designMock, | ||
$this->customizationFactoryMock, | ||
$this->filesystemMock, | ||
$this->iteratorFactoryMock | ||
); | ||
} | ||
| ||
/** | ||
* Test for get method with frontend scope. | ||
* | ||
* @param string $scope | ||
* @param string $fileName | ||
* @param array $fileList | ||
* @param string $themeFilesPath | ||
* | ||
* @return void | ||
* @dataProvider providerGetFrontend | ||
*/ | ||
public function testGetFrontend(string $scope, string $fileName, array $fileList, string $themeFilesPath): void | ||
{ | ||
$this->moduleFileResolverMock->expects($this->once()) | ||
->method('get') | ||
->with($fileName, $scope) | ||
->willReturn($fileList); | ||
| ||
$this->customizationFactoryMock->expects($this->any()) | ||
->method('create') | ||
->with(['theme' => $this->themeInterFaceMock]) | ||
->willReturn($this->customizationInterfaceMock); | ||
| ||
$this->customizationInterfaceMock->expects($this->once()) | ||
->method('getThemeFilesPath') | ||
->willReturn($themeFilesPath); | ||
| ||
$this->readInterfaceMock->expects($this->once()) | ||
->method('isExist') | ||
->with($themeFilesPath.'/etc/'.$fileName) | ||
->willReturn(true); | ||
| ||
$this->iteratorFactoryMock->expects($this->once()) | ||
->method('create') | ||
->with( | ||
[ | ||
'paths' => array_reverse([$themeFilesPath.'/etc/'.$fileName]), | ||
'existingIterator' => $fileList | ||
] | ||
) | ||
->willReturn($fileList); | ||
| ||
$this->assertEquals($fileList, $this->model->get($fileName, $scope)); | ||
} | ||
| ||
/** | ||
* Test for get method with global scope. | ||
* | ||
* @param string $scope | ||
* @param string $fileName | ||
* @param array $fileList | ||
* | ||
* @return void | ||
* @dataProvider providerGetGlobal | ||
*/ | ||
public function testGetGlobal(string $scope, string $fileName, array $fileList): void | ||
{ | ||
$this->moduleFileResolverMock->expects($this->once()) | ||
->method('get') | ||
->with($fileName, $scope) | ||
->willReturn($fileList); | ||
$this->assertEquals($fileList, $this->model->get($fileName, $scope)); | ||
} | ||
| ||
/** | ||
* Data provider for get global scope tests. | ||
* | ||
* @return array | ||
*/ | ||
public static function providerGetGlobal(): array | ||
{ | ||
return [ | ||
[ | ||
'global', | ||
'csp_whitelist.xml', | ||
['anyvendor/anymodule/etc/csp_whitelist.xml'] | ||
] | ||
]; | ||
} | ||
| ||
/** | ||
* Data provider for get frontend & adminhtml scope tests. | ||
* | ||
* @return array | ||
*/ | ||
public static function providerGetFrontend(): array | ||
{ | ||
return [ | ||
[ | ||
'frontend', | ||
'csp_whitelist.xml', | ||
['themevendor/theme/etc/csp_whitelist.xml'], | ||
'themevendor/theme' | ||
], | ||
[ | ||
'adminhtml', | ||
'csp_whitelist.xml', | ||
['adminthemevendor/admintheme/etc/csp_whitelist.xml'], | ||
'adminthemevendor/admintheme' | ||
] | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHPDoc comment signature is not complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed