Review main Merged

94931[TASK] Avoid frontend context leak in extbase controller tests

Benni Mack CR +2 V +2 Normal +59 −1 updated 07/26/26, 15:10

Commit message

BlogPostEditingControllerTest relied on state leaking from frontend
sub-requests into the test scope: executeFrontendSubRequest() boots
the frontend application via Bootstrap::init(), which registers a
fresh DI container globally, and the testing framework does not
restore the previous container afterwards. Extbase repository calls
made after a sub-request therefore ran with the language aspect of
the frontend request instead of the default language context.

On top of that, the Extbase persistence session of the frontend
request was reused when mapping query results in test scope: the
language-aware identity map matched the leaked language aspect, so
assertions were satisfied by the in-memory object graph of the form
submission and never verified persisted database state.

The tests now reset the leaked language aspect (a workaround until
the testing framework restores the container), fetch the updated
translation with an explicitly set language aspect, and assert
against actual database content. This uncovers that MM relation
changes of a translated aggregate root are written against the
default language record, while reading resolves MM relations via the
localized uid. The affected assertions document this inconsistency
and are marked to be adapted once write and read side agree on which
uid owns the MM rows of a translated record.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Garvin Hicking +1
    • Stefan Bürk +1
  • Verified V +2 Done
    • Benni Mack +2
    • Garvin Hicking +1
    • Stefan Bürk +1
    • core-ci +1 CI

Issues 4

Files 1

Review log 1520

  1. Benni Mack uploaded patch set 1 07/24/26, 15:19

  2. core-ci voted on patch set 1 V -1 07/24/26, 15:31 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105339

  3. core-ci commented on patch set 1 07/24/26, 16:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105339

  4. Benni Mack marked it work in progress 07/24/26, 16:34

  5. Rémy DANIEL commented on patch set 1 07/24/26, 16:35

    Hi. I think the issue marked as resolved is not the right one.
  6. Benni Mack updated the commit message in patch set 2 V -1 07/24/26, 16:41

  7. Benni Mack commented on patch set 2 07/24/26, 16:41

    Reply

    yes. thank you
  8. core-ci voted on patch set 2 V -1 07/24/26, 16:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105347

  9. Benni Mack uploaded patch set 3 V -1 07/24/26, 18:59

  10. Benni Mack marked it ready for review 07/24/26, 19:08

  11. core-ci voted on patch set 3 V +1 07/24/26, 19:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105349

  12. Garvin Hicking commented on patch set 3 CR +1 V +1 07/25/26, 11:42

    Wow what a mess 🤪
  13. Oliver Klee voted on patch set 3 V +1 07/25/26, 12:08

  14. Oliver Klee commented on patch set 3 07/25/26, 12:09

    BlogPostEditingControllerTest.php:134

    I think we can use `$this->get(Context::class)` instead in both places.
  15. Stefan Bürk rebased onto patch set 4 CR +1 V +1 07/25/26, 17:33

  16. core-ci voted on patch set 4 V +1 07/25/26, 17:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105396

  17. Stefan Bürk commented on patch set 4 CR +1 V +1 07/25/26, 18:01

    BlogPostEditingControllerTest.php:134 Reply

    Agreed in principle, but it does not hold yet on this patch - it only works once the container is restored, so I adopted it one change up instead, in the WIP change https://review.typo3.org/c/Packages/TYPO3.CMS/+/94945 The two are not equivalent while the leak is still there. After executeFrontendSubRequest(), the globally registered container is still the one Bootstrap::init() built for the frontend request. GeneralUtility::makeInstance() therefore resolves Context through that leaked frontend container - which is exactly the instance Extbase's Typo3QuerySettings reads afterwards. $this->get() resolves through FunctionalTestCase::$container, the container of the test scope, and hands out a different Context instance. Setting the aspect there would leave the object that consumers actually read untouched, and the workaround would silently stop working. Verified locally on sqlite: * this patch as is, testing-framework dev-main: OK (10 tests, 59 assertions) * this patch with $this->get() in both places, dev-main: 1 failure, the category assertion in fullyLocalizedFormSubmissionPersistsDataOfSelectedBlogForRequestedTranslation * this patch with $this->get(), on top of testing-framework branch frontendrequest-context-leak: OK The testing-framework branch restores Context and the DI container in FrameworkState::push()/pop(), after which both resolve to the same service - every SingletonInterface implementation is a public service via SingletonPass - and your suggestion is the better spelling. 94945 requires that branch, drops the workaround introduced here and switches the remaining call to $this->get(Context::class). So I would keep makeInstance() here as long as this change targets dev-main and https://github.com/TYPO3/testing-framework/pull/734 has not been merged and raised for `main` - I'll added the suggested change into the gerrit change testing the testing-framework change and already removing the workaround introduced in this change again. See: 94945: [WIP][TASK] Test testing-framework context leak fix | https://review.typo3.org/c/Packages/TYPO3.CMS/+/94945
  18. Garvin Hicking voted on patch set 4 CR +1 V +1 07/25/26, 20:01

  19. Benni Mack commented on patch set 4 CR +2 V +2 07/26/26, 15:10

    BlogPostEditingControllerTest.php:134 Reply

    yeah, that's the main reason for using makeInstance here (= and documenting this with the commit).
  20. Benni Mack merged patch set 5 07/26/26, 15:10