7
7
8
8
namespace Magento \GraphQlResolverCache \Model \Resolver \Result \Cache ;
9
9
10
+ use Magento \Framework \App \DeploymentConfig ;
11
+ use Magento \Framework \Config \ConfigOptionsListConstants ;
10
12
use Magento \GraphQl \Model \Query \ContextFactoryInterface ;
11
13
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \CalculationException ;
12
14
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator ;
13
15
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \ParentValueFactorProviderInterface ;
14
16
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \GenericFactorProviderInterface ;
15
17
use Magento \GraphQlResolverCache \Model \Resolver \Result \ValueProcessorInterface ;
16
18
use Magento \TestFramework \Helper \Bootstrap ;
17
- use Psr \Log \LoggerInterface ;
18
19
19
20
/**
20
21
* Test for graphql resolver-level cache key calculator.
@@ -182,6 +183,8 @@ private function resetMocksForObjectManager(array $factorDataArray)
182
183
*/
183
184
public function keyFactorDataProvider ()
184
185
{
186
+ $ salt = Bootstrap::getObjectManager ()->get (DeploymentConfig::class)
187
+ ->get (ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY );
185
188
return [
186
189
'no factors ' => [
187
190
'factorProviders ' => [],
@@ -197,7 +200,7 @@ public function keyFactorDataProvider()
197
200
],
198
201
],
199
202
'parentResolverData ' => null ,
200
- 'expectedCacheKey ' => hash ('sha256 ' , strtoupper ('testValue ' )),
203
+ 'expectedCacheKey ' => hash ('sha256 ' , strtoupper ('testValue ' ) . " | $ salt " ),
201
204
],
202
205
'unsorted multiple factors ' => [
203
206
'factorProviders ' => [
@@ -218,7 +221,10 @@ public function keyFactorDataProvider()
218
221
],
219
222
],
220
223
'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
+ ),
222
228
],
223
229
'unsorted multiple factors with parent data ' => [
224
230
'factorProviders ' => [
@@ -241,7 +247,10 @@ public function keyFactorDataProvider()
241
247
'parentResolverData ' => [
242
248
'object_id ' => 123
243
249
],
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
+ ),
245
254
],
246
255
'unsorted multifactor with no parent data and parent factored interface ' => [
247
256
'factorProviders ' => [
@@ -262,7 +271,10 @@ public function keyFactorDataProvider()
262
271
],
263
272
],
264
273
'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
+ ),
266
278
],
267
279
];
268
280
}
@@ -301,7 +313,10 @@ public function testValueProcessingIsCalledForParentValueFromCache()
301
313
]);
302
314
303
315
$ 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 );
305
320
306
321
$ this ->objectManager ->removeSharedInstance ('TestValueFactorMock ' );
307
322
$ this ->objectManager ->removeSharedInstance ('TestContextFactorMock ' );
@@ -365,7 +380,10 @@ public function testValueProcessingIsNotCalledForParentValueFromResolver()
365
380
]);
366
381
367
382
$ 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 );
369
387
370
388
$ this ->objectManager ->removeSharedInstance ('TestValueFactorMock ' );
371
389
$ this ->objectManager ->removeSharedInstance ('TestContextFactorMock ' );
@@ -403,7 +421,10 @@ public function testValueProcessingIsSkippedForContextOnlyFactors()
403
421
]);
404
422
405
423
$ 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 );
407
428
408
429
$ this ->objectManager ->removeSharedInstance ('TestContextFactorMock ' );
409
430
}
0 commit comments