Skip to content

Commit 24d48c4

Browse files
committed
Merge remote-tracking branch 'af/B2B-3035' into B2B-2931-2677-3035
2 parents 07e800c + ec3b557 commit 24d48c4

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/Calculator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey;
99

10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1012
use Magento\Framework\ObjectManagerInterface;
1113
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
1214
use Magento\GraphQlResolverCache\Model\Resolver\Result\ValueProcessorInterface;
@@ -16,6 +18,11 @@
1618
*/
1719
class Calculator
1820
{
21+
/**
22+
* @var DeploymentConfig
23+
*/
24+
private $deploymentConfig;
25+
1926
/**
2027
* @var ContextFactoryInterface
2128
*/
@@ -42,17 +49,20 @@ class Calculator
4249
private ValueProcessorInterface $valueProcessor;
4350

4451
/**
52+
* @param DeploymentConfig $deploymentConfig
4553
* @param ContextFactoryInterface $contextFactory
4654
* @param ObjectManagerInterface $objectManager
4755
* @param ValueProcessorInterface $valueProcessor
4856
* @param string[] $factorProviders
4957
*/
5058
public function __construct(
59+
DeploymentConfig $deploymentConfig,
5160
ContextFactoryInterface $contextFactory,
5261
ObjectManagerInterface $objectManager,
5362
ValueProcessorInterface $valueProcessor,
5463
array $factorProviders = []
5564
) {
65+
$this->deploymentConfig = $deploymentConfig;
5666
$this->contextFactory = $contextFactory;
5767
$this->factorProviders = $factorProviders;
5868
$this->objectManager = $objectManager;
@@ -76,7 +86,8 @@ public function calculateCacheKey(?array $parentData = null): ?string
7686
try {
7787
$this->initializeFactorProviderInstances();
7888
$factors = $this->getFactors($parentData);
79-
$keysString = strtoupper(implode('|', array_values($factors)));
89+
$salt = (string)$this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
90+
$keysString = strtoupper(implode('|', array_values($factors))) . "|$salt";
8091
return hash('sha256', $keysString);
8192
} catch (\Throwable $e) {
8293
throw new CalculationException($e->getMessage(), $e->getCode(), $e);

dev/tests/integration/testsuite/Magento/GraphQlResolverCache/Model/Resolver/Result/Cache/KeyCalculator/ProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\CustomerGraphQl\Model\Resolver\CacheKey\FactorProvider\CustomerGroup;
1111
use Magento\CustomerGraphQl\Model\Resolver\Customer;
1212
use Magento\CustomerGraphQl\Model\Resolver\CustomerAddresses;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\Config\ConfigOptionsListConstants;
1315
use Magento\Framework\GraphQl\Query\ResolverInterface;
1416
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator\Provider;
1517
use Magento\StoreGraphQl\CacheIdFactorProviders\CurrencyProvider;
@@ -152,9 +154,11 @@ public function testProviderKeyFactorsConfigured()
152154
$this->objectManager->addSharedInstance($storeFactorMock, StoreProvider::class);
153155
$this->objectManager->addSharedInstance($currencyFactorMock, CurrencyProvider::class);
154156
$this->objectManager->addSharedInstance($customerGroupFactorMock, CustomerGroup::class);
157+
$salt = $this->objectManager->get(DeploymentConfig::class)
158+
->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
155159
$expectedKey = hash(
156160
'sha256',
157-
strtoupper(implode('|', ['currency' => 'USD', 'customer_group' => '1', 'store' => 'default']))
161+
strtoupper(implode('|', ['CURRENCY' => 'USD', 'CUSTOMER_GROUP' => '1', 'STORE' => 'default'])) . "|$salt"
158162
);
159163
$calc = $this->provider->getKeyCalculatorForResolver($resolver);
160164
$key = $calc->calculateCacheKey();

dev/tests/integration/testsuite/Magento/GraphQlResolverCache/Model/Resolver/Result/Cache/KeyCalculatorTest.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
namespace Magento\GraphQlResolverCache\Model\Resolver\Result\Cache;
99

10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1012
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
1113
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\CalculationException;
1214
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\Calculator;
1315
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValueFactorProviderInterface;
1416
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\GenericFactorProviderInterface;
1517
use Magento\GraphQlResolverCache\Model\Resolver\Result\ValueProcessorInterface;
1618
use Magento\TestFramework\Helper\Bootstrap;
17-
use Psr\Log\LoggerInterface;
1819

1920
/**
2021
* Test for graphql resolver-level cache key calculator.
@@ -182,6 +183,8 @@ private function resetMocksForObjectManager(array $factorDataArray)
182183
*/
183184
public function keyFactorDataProvider()
184185
{
186+
$salt = Bootstrap::getObjectManager()->get(DeploymentConfig::class)
187+
->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
185188
return [
186189
'no factors' => [
187190
'factorProviders' => [],
@@ -197,7 +200,7 @@ public function keyFactorDataProvider()
197200
],
198201
],
199202
'parentResolverData' => null,
200-
'expectedCacheKey' => hash('sha256', strtoupper('testValue')),
203+
'expectedCacheKey' => hash('sha256', strtoupper('testValue') . "|$salt"),
201204
],
202205
'unsorted multiple factors' => [
203206
'factorProviders' => [
@@ -218,7 +221,10 @@ public function keyFactorDataProvider()
218221
],
219222
],
220223
'parentResolverData' => null,
221-
'expectedCacheKey' => hash('sha256', strtoupper('a_testValue|b_testValue|c_testValue')),
224+
'expectedCacheKey' => hash(
225+
'sha256',
226+
strtoupper('a_testValue|b_testValue|c_testValue') . "|$salt"
227+
),
222228
],
223229
'unsorted multiple factors with parent data' => [
224230
'factorProviders' => [
@@ -241,7 +247,10 @@ public function keyFactorDataProvider()
241247
'parentResolverData' => [
242248
'object_id' => 123
243249
],
244-
'expectedCacheKey' => hash('sha256', strtoupper('a_testValue|object_123|c_testValue')),
250+
'expectedCacheKey' => hash(
251+
'sha256',
252+
strtoupper('a_testValue|object_123|c_testValue') . "|$salt"
253+
),
245254
],
246255
'unsorted multifactor with no parent data and parent factored interface' => [
247256
'factorProviders' => [
@@ -262,7 +271,10 @@ public function keyFactorDataProvider()
262271
],
263272
],
264273
'parentResolverData' => null,
265-
'expectedCacheKey' => hash('sha256', strtoupper('a_testValue|some value|c_testValue')),
274+
'expectedCacheKey' => hash(
275+
'sha256',
276+
strtoupper('a_testValue|some value|c_testValue') . "|$salt"
277+
),
266278
],
267279
];
268280
}
@@ -301,7 +313,10 @@ public function testValueProcessingIsCalledForParentValueFromCache()
301313
]);
302314

303315
$key = $keyCalculator->calculateCacheKey($value);
304-
$this->assertEquals('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', $key);
316+
$salt = Bootstrap::getObjectManager()->get(DeploymentConfig::class)
317+
->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
318+
$expectedResult = hash('sha256', "|$salt");
319+
$this->assertEquals($expectedResult, $key);
305320

306321
$this->objectManager->removeSharedInstance('TestValueFactorMock');
307322
$this->objectManager->removeSharedInstance('TestContextFactorMock');
@@ -365,7 +380,10 @@ public function testValueProcessingIsNotCalledForParentValueFromResolver()
365380
]);
366381

367382
$key = $keyCalculator->calculateCacheKey($value);
368-
$this->assertEquals('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', $key);
383+
$salt = Bootstrap::getObjectManager()->get(DeploymentConfig::class)
384+
->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
385+
$expectedResult = hash('sha256', "|$salt");
386+
$this->assertEquals($expectedResult, $key);
369387

370388
$this->objectManager->removeSharedInstance('TestValueFactorMock');
371389
$this->objectManager->removeSharedInstance('TestContextFactorMock');
@@ -403,7 +421,10 @@ public function testValueProcessingIsSkippedForContextOnlyFactors()
403421
]);
404422

405423
$key = $keyCalculator->calculateCacheKey($value);
406-
$this->assertEquals('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', $key);
424+
$salt = Bootstrap::getObjectManager()->get(DeploymentConfig::class)
425+
->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
426+
$expectedResult = hash('sha256', "|$salt");
427+
$this->assertEquals($expectedResult, $key);
407428

408429
$this->objectManager->removeSharedInstance('TestContextFactorMock');
409430
}

0 commit comments

Comments
 (0)