-
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
Changes from 7 commits
b60b5f8
f65f4ab
c91126d
19c9d30
e46b06f
35ed4a0
d7c3b5b
e7b3597
87e2fbf
c4bc979
6847456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,221 @@ | ||||||
<?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() | ||||||
->onlyMethods(['get']) | ||||||
->getMockForAbstractClass(); | ||||||
|
||||||
$this->designMock = $this->getMockBuilder(DesignInterface::class) | ||||||
->disableOriginalConstructor() | ||||||
->onlyMethods(['getDesignTheme']) | ||||||
->getMockForAbstractClass(); | ||||||
|
||||||
$this->themeInterFaceMock = $this->getMockBuilder(ThemeInterface::class) | ||||||
->getMockForAbstractClass(); | ||||||
|
||||||
$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() | ||||||
->getMockForAbstractClass(); | ||||||
|
||||||
$this->filesystemMock = $this->createPartialMock(Filesystem::class, ['getDirectoryRead']); | ||||||
|
||||||
$this->readInterfaceMock = $this->getMockBuilder(ReadInterface::class) | ||||||
->disableOriginalConstructor() | ||||||
->getMockForAbstractClass(); | ||||||
|
||||||
$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 $filename | ||||||
|
||||||
* @param array $fileList | ||||||
* | ||||||
* @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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||
* | ||||||
* @param string $filename | ||||||
|
* @param string $filename | |
* @param string $fileName |
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
Outdated
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.
* Data provider for get glocal scope tests. | |
* Data provider for get global scope tests. |
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
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.
getMockForAbstractClass
method has been deprecated, please use alternative.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