Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8957: Fixed deserializing SiteAccess Matchers for ESI #430

Conversation

vidarl
Copy link
Contributor

@vidarl vidarl commented Sep 26, 2024

🎫 Issue IBX-8957

Description:

When unserializing SiteaccessMatcher in ESI, custom matchers was only fetch from registry. Serialized configuration of the matcher was not restored.

In case of sitefactoy's SiteAccessMatcher, it meant that mapKey was never restored, causing incorrect links to be generated.
(Map is an ancestor of SiteAccessMatcher)


Maintainer update: this issue uncovered a few other underlying issues. We were using traits in production code to configure serializers. Instead I've (@alongosz) changed it to configured ibexa.core.mvc.serializer service.

Moreover the same mirrored code was used to serialize and deserialize data and store them into 3 separate request attributes. While the latter case needs to be tackled separately via IBX-9102, I've made the code uniformly use the same serializer for both serialization and deserialization of data. The SerializerTrait is left only for unit test purposes.

I've introduced ...\Fragment\SiteAccessSerializer service to wrap what SiteAccessSerializationTrait was doing for production code.

The end goal is to have serialization/deserialization handled by configured Symfony serializers entirely. The question now is if we should move parts of the scope resolved here to IBX-9102, or should we keep this and only improve in IBX-9102?


For QA:

See ticket for instructions on how to reproduce.

Maintainer update: sanities on SiteAccess matchers, including compound matchers are needed.

Regression run: 🟢 ibexa/commerce#1081
Matchers tests: 🟢 ibexa/experience#500

Documentation:

@vidarl vidarl force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch 3 times, most recently from 7eb0ce3 to e784f1b Compare September 27, 2024 11:59
@vidarl vidarl requested a review from a team September 30, 2024 06:31
Copy link
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should cover this scenario within tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.

@konradoboza konradoboza requested a review from a team October 2, 2024 08:51
@vidarl
Copy link
Contributor Author

vidarl commented Oct 3, 2024

I think we should cover this scenario within tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest.

This needs to be tested with a matcher which is in the siteAccessMatcherRegistry, but I don't think any of the build-in matchers are there.. ( the fix is inside the if ($this->siteAccessMatcherRegistry->hasMatcher($matcherClass)) { condition )

So, then I would need to make a new test inside SiteFactory based on tests/lib/MVC/Symfony/EventListener/SiteAccessMatchListenerTest ?

@konradoboza

@konradoboza
Copy link
Contributor

@vidarl
there should be another test case within SiteAccessMatchListenerTest mocking that separately, e.g.:

$matcherRegistryMock = $this->createMock(SiteAccessMatcherRegistryInterface::class);
$matcherRegistryMock->method('hasMatcher')->willReturn(true);
$matcherRegistryMock->method('getMatcher')->willReturn($matcherObject)

I just wanted to have it covered as it seems the shape of the object changes substantially. If the test boils down to tons of mocking and only checking if deserialize method was called once, there is no need. Otherwise, it brings value.

@konradoboza konradoboza requested a review from alongosz October 9, 2024 10:59
Copy link
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay-ish but I would like to see the test covering this scenario but this is kind hard to deliver after internal sync. Maybe @alongosz has some tips on how to test that so it brings any value (without mocking tons of classes).

@vidarl vidarl force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from b250d10 to a316206 Compare October 10, 2024 07:38
@vidarl
Copy link
Contributor Author

vidarl commented Oct 10, 2024

I have written a test now.
I was not able to mock the CustomMatcher as it:

  • Needs to both extend Ibexa\Core\MVC\Symfony\SiteAccess\Matcher and implement Ibexa\Bundle\Core\SiteAccess\Matcher
  • Have some property that is serialized and which can be validated if it is also deserialized or not

SonarCloud fails due to duplication code in the test. I asssume this is OK ?
@konradoboza , @alongosz

@vidarl vidarl requested a review from konradoboza October 10, 2024 09:41
@vidarl
Copy link
Contributor Author

vidarl commented Oct 10, 2024

SonarCloud is happy too now....

@vidarl vidarl force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from a7386e0 to 472ec69 Compare October 10, 2024 12:54
@alongosz alongosz changed the title IBX-8957: Sitefactory: ESI fragments containing links are losing factory matcher path IBX-8957: Fixed deserializing SiteAccess Matchers for ESI Oct 11, 2024
@alongosz alongosz force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from 85ed742 to 9ce8dea Compare October 15, 2024 14:22
@alongosz alongosz force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from 9ce8dea to 606af76 Compare October 17, 2024 01:11
@alongosz alongosz force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from 606af76 to 4f5bdf8 Compare October 17, 2024 08:27
@alongosz alongosz force-pushed the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch from a25473f to 1270e47 Compare October 17, 2024 13:44
Co-Authored-By: Paweł Niedzielski <Steveb-p@users.noreply.github.com>
@alongosz alongosz requested review from Steveb-p and a team October 17, 2024 14:38
Copy link

@alongosz alongosz requested a review from a team October 18, 2024 08:32
@mikadamczyk mikadamczyk requested a review from a team October 18, 2024 14:14
@micszo micszo self-assigned this Oct 21, 2024
Copy link
Contributor

@micszo micszo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced and retested.

Sanities with matchers OK.

@micszo micszo removed their assignment Oct 25, 2024
@alongosz alongosz merged commit ac4e57c into 4.6 Oct 25, 2024
24 checks passed
@alongosz alongosz deleted the IBX-8957_Sitefactory_ESI_fragments_containing_links_are_losing_factory_matcher_path branch October 25, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants