Skip to content

Commit 1f09cf2

Browse files
authored
ENGCOM-7142: Static properties serialization fix. #26175
2 parents 9657870 + ed83a6a commit 1f09cf2

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\TestFramework\Serialize;
10+
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
13+
/**
14+
* Insecure SerializerInterface implementation for test use only.
15+
*/
16+
class Serializer implements SerializerInterface
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function serialize($data)
22+
{
23+
if (is_resource($data)) {
24+
throw new \InvalidArgumentException('Unable to serialize value.');
25+
}
26+
27+
// phpcs:ignore Magento2.Security.InsecureFunction
28+
return serialize($data);
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function unserialize($string)
35+
{
36+
if (false === $string || null === $string || '' === $string) {
37+
throw new \InvalidArgumentException('Unable to unserialize value.');
38+
}
39+
set_error_handler(
40+
function () {
41+
restore_error_handler();
42+
throw new \InvalidArgumentException('Unable to unserialize value, string is corrupted.');
43+
},
44+
E_NOTICE
45+
);
46+
// phpcs:ignore Magento2.Security.InsecureFunction
47+
$result = unserialize($string);
48+
restore_error_handler();
49+
50+
return $result;
51+
}
52+
}

dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/StaticProperties.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function backupStaticVariables()
170170

171171
$objectManager = Bootstrap::getInstance()->getObjectManager();
172172
$cache = $objectManager->get(CacheInterface::class);
173-
$serializer = $objectManager->get(SerializerInterface::class);
173+
$serializer = $objectManager->get(\Magento\TestFramework\Serialize\Serializer::class);
174174
$cachedProperties = $cache->load(self::CACHE_NAME);
175175

176176
if ($cachedProperties) {
@@ -187,9 +187,10 @@ public static function backupStaticVariables()
187187
| Files::INCLUDE_TESTS
188188
),
189189
function ($classFile) {
190-
return StaticProperties::_isClassInCleanableFolders($classFile)
191-
// phpcs:ignore Magento2.Functions.DiscouragedFunction
192-
&& strpos(file_get_contents($classFile), ' static ') > 0;
190+
return strpos($classFile, 'TestFramework') === -1
191+
&& StaticProperties::_isClassInCleanableFolders($classFile)
192+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
193+
&& strpos(file_get_contents($classFile), ' static ') > 0;
193194
}
194195
);
195196
$namespacePattern = '/namespace [a-zA-Z0-9\\\\]+;/';

0 commit comments

Comments
 (0)