Skip to content

Commit 675dd95

Browse files
Merge pull request #8493 from magento-cia/cia-2.4.7-beta2-develop-bugfix-08242023
Bugfixes
2 parents 75e9933 + 845520c commit 675dd95

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/internal/Magento/Framework/App/Http/Context.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
namespace Magento\Framework\App\Http;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Config\ConfigOptionsListConstants;
1113
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1214
use Magento\Framework\Serialize\Serializer\Json;
1315

@@ -40,6 +42,11 @@ class Context implements ResetAfterRequestInterface
4042
*/
4143
private $serializer;
4244

45+
/**
46+
* @var DeploymentConfig|null
47+
*/
48+
private ?DeploymentConfig $deploymentConfig = null;
49+
4350
/**
4451
* @param array $data
4552
* @param array $default
@@ -117,8 +124,11 @@ public function getVaryString()
117124
{
118125
$data = $this->getData();
119126
if (!empty($data)) {
127+
$salt = (string)$this->getDeploymentConfig()->get(
128+
ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY
129+
);
120130
ksort($data);
121-
return sha1($this->serializer->serialize($data));
131+
return hash('sha256', $this->serializer->serialize($data) . '|' . $salt);
122132
}
123133
return null;
124134
}
@@ -144,4 +154,18 @@ public function _resetState(): void
144154
$this->data = [];
145155
$this->default = [];
146156
}
157+
158+
/**
159+
* Get DeploymentConfig
160+
*
161+
* @return DeploymentConfig
162+
*/
163+
private function getDeploymentConfig() : DeploymentConfig
164+
{
165+
if ($this->deploymentConfig === null) {
166+
$this->deploymentConfig = ObjectManager::getInstance()
167+
->get(DeploymentConfig::class);
168+
}
169+
return $this->deploymentConfig;
170+
}
147171
}

lib/internal/Magento/Framework/App/Test/Unit/Http/ContextTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\Framework\App\Test\Unit\Http;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\Http\Context;
12+
use Magento\Framework\Config\ConfigOptionsListConstants;
13+
use Magento\Framework\ObjectManagerInterface;
1114
use Magento\Framework\Serialize\Serializer\Json;
1215
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1316
use PHPUnit\Framework\MockObject\MockObject;
@@ -25,13 +28,29 @@ class ContextTest extends TestCase
2528
*/
2629
protected $object;
2730

31+
/**
32+
* @var DeploymentConfig|MockObject
33+
*/
34+
private $deploymentConfig;
35+
36+
/**
37+
* @var ObjectManagerInterface|MockObject
38+
*/
39+
private $objectManagerMock;
40+
2841
/**
2942
* @var Json|MockObject
3043
*/
3144
private $serializerMock;
3245

3346
protected function setUp(): void
3447
{
48+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
49+
->disableOriginalConstructor()
50+
->onlyMethods(['create'])
51+
->getMockForAbstractClass();
52+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerMock);
53+
3554
$this->objectManager = new ObjectManager($this);
3655
$this->serializerMock = $this->getMockBuilder(Json::class)
3756
->setMethods(['serialize'])
@@ -50,6 +69,10 @@ function ($value) {
5069
'serializer' => $this->serializerMock
5170
]
5271
);
72+
$this->deploymentConfig = $this->createPartialMock(
73+
DeploymentConfig::class,
74+
['get']
75+
);
5376
}
5477

5578
public function testGetValue()
@@ -81,14 +104,28 @@ public function testGetData()
81104

82105
public function testGetVaryString()
83106
{
107+
$this->objectManagerMock->expects($this->any())
108+
->method('get')
109+
->with(DeploymentConfig::class)
110+
->willReturn($this->deploymentConfig);
111+
112+
$this->deploymentConfig->expects($this->any())
113+
->method('get')
114+
->with(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
115+
->willReturn('448198e08af35844a42d3c93c1ef4e03');
116+
84117
$this->object->setValue('key2', 'value2', 'default2');
85118
$this->object->setValue('key1', 'value1', 'default1');
86119
$data = [
87120
'key2' => 'value2',
88121
'key1' => 'value1'
89122
];
90123
ksort($data);
91-
$this->assertEquals(sha1(json_encode($data)), $this->object->getVaryString());
124+
125+
$salt = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
126+
$cacheKey = hash('sha256', $this->serializerMock->serialize($data) . '|' . $salt);
127+
128+
$this->assertEquals($cacheKey, $this->object->getVaryString());
92129
}
93130

94131
public function testToArray()

0 commit comments

Comments
 (0)