Fix GraphQL Content-Currency validation against the store named by the Store header (#41242) - #41247
Open
lbajsarowicz wants to merge 2 commits into
Conversation
…er (magento#41242) CurrencyValidator validated Content-Currency against the default store because it ran before StoreProcessor applied the Store header. It now resolves the store named by the Store header itself, matching the store StoreProcessor sets afterwards, and treats an inactive store the same as a missing one instead of depending on validator registration order.
|
Hi @lbajsarowicz. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
Author
|
@magento run all tests |
Contributor
Author
|
@magento run all tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (*)
A GraphQL request that sends
Store: <store code>together withContent-Currency: <code>is rejected withPlease correct the target currencywhenever that currency is allowed only on the requested website and not on the default one.Root cause:
Magento\GraphQlCache\Controller\Plugin\GraphQl::beforeDispatch()runsvalidateRequest()beforeprocessHeaders().Magento\DirectoryGraphQl\Controller\HttpRequestValidator\CurrencyValidatortherefore checks the header againststoreManager->getStore(), which is still the default store, because theStoreheader is only applied byStoreProcessorinsideprocessHeaders(). The validator throws,processHeaders()is skipped, and the second validation pass inGraphQl::dispatch()fails the same way. This ordering was introduced by AC-821 for #31336 (store validation must run before the store is switched) and tightened by AC-11729, so the plugin order is not changed here.The fix makes
CurrencyValidatorresolve the store it validates against from theStoreheader itself, falling back to the current store when the header is absent. An unknown or inactive store code keeps producingRequested store is not found, matchingStoreValidator, so the validator no longer depends on the order in which the two validators are registered.Tests:
Magento\DirectoryGraphQl\Test\Unit\Controller\HttpRequestValidator\CurrencyValidatorTestcovering the header/no-header paths, rejected currencies, unknown and inactive store codes, empty header and normalisation.Magento\GraphQl\Directory\CurrencyHeaderValidationTestwith a second website whose only allowed, base and default currency isNOK(absent from the default scope):Store+Content-Currency: NOKsucceeds,Content-Currency: NOKwithoutStoreis rejected,Store+Content-Currency: USDis rejected.Related Pull Requests
None.
Fixed Issues (if relevant)
Manual testing scenarios (*)
nok_sv).catalog/price/scopeto Website. For the new website setcurrency/options/allow,currency/options/baseandcurrency/options/defaulttoNOK. Leave the default scope onUSD.POST /graphqlwith headersStore: nok_sv,Content-Currency: NOKand query{ storeConfig { store_code base_currency_code } }.Please correct the target currency. After the fix:store_codeisnok_sv,base_currency_codeisNOK.Storeheader: still rejected, becauseNOKis not allowed on the default store.Questions or comments
Local gates: unit, integration (no integration tests changed), PHPCS, PHPStan and the Static Tests reproduction were run on the changed files; the API-functional test relies on the upstream WebAPI build.
Contribution checklist (*)