From d1d91952cdd16ad2ce2a5a660fd7163032e02aa0 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Mon, 15 Apr 2024 15:30:56 +0200 Subject: [PATCH] Update bootstrap path and add manifest credential use The bootstrap path in phpunit.xml.dist has been updated to 'tests/autoload.php'. A useCredentials option has been added to the PWA manifest allowing the manifest to be fetched with credentials, enhancing website security. Also, an autoload.php file has been added to facilitate testing. --- phpunit.xml.dist | 2 +- src/Dto/Manifest.php | 3 +++ src/Resources/config/definition/manifest.php | 4 ++++ src/Twig/PwaRuntime.php | 6 +++++- tests/autoload.php | 9 +++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/autoload.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index feb46b0..3d7f866 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ info('The public URL of the manifest file.') ->example('/site.manifest') ->end() + ->booleanNode('use_credentials') + ->defaultTrue() + ->info('Indicates whether the manifest should be fetched with credentials.') + ->end() ->scalarNode('background_color') ->info( 'The background color of the application. It should match the background-color CSS property in the sites stylesheet for a smooth transition between launching the web application and loading the site\'s content.' diff --git a/src/Twig/PwaRuntime.php b/src/Twig/PwaRuntime.php index e55388c..e3ca916 100644 --- a/src/Twig/PwaRuntime.php +++ b/src/Twig/PwaRuntime.php @@ -56,8 +56,12 @@ public function load( private function injectManifestFile(string $output): string { $url = $this->assetMapper->getPublicPath($this->manifestPublicUrl) ?? $this->manifestPublicUrl; + $useCredentials = ''; + if ($this->manifest->useCredentials === true) { + $useCredentials = ' crossorigin="use-credentials"'; + } - return $output . sprintf('%s', PHP_EOL, $url); + return $output . sprintf('%s', PHP_EOL, $useCredentials, $url); } private function injectThemeColor(string $output, bool $themeColor): string diff --git a/tests/autoload.php b/tests/autoload.php new file mode 100644 index 0000000..552064b --- /dev/null +++ b/tests/autoload.php @@ -0,0 +1,9 @@ +