Skip to content

netresearch/typo3-testing-skill / skills/typo3-testing

typo3-testing

Flagged

Use when reproducing defects as failing tests, testing template or rendered output changes, confirming changes on a running TYPO3 instance, or setting up TYPO3 extension tests: unit/functional/E2E, PHPUnit 11-13, mutation testing, final-class mocks (v14), CI matrix across TYPO3 12/13/14.3 LTS, typo3-ci-workflows meta-package, CI failures. Also: transaction rollback, worker crashes, competing requests, testing-framework setup, test matrix, integration/e2e testing, coverage, test generation.

FileKindSize
SKILL.mdskill md6.8 KB
assets/.php-cs-fixer.dist.phpscript7.0 KB
assets/AGENTS.mdmarkdown5.0 KB
assets/Build/Scripts/runTests.shexecutablescript27.5 KB
assets/Build/playwright/.nvmrcother6 B
assets/Build/playwright/package.jsonmanifest535 B
assets/Build/playwright/playwright.config.tsscript1.3 KB
assets/Build/playwright/tests/playwright/accessibility/modules.spec.tsscript2.0 KB
assets/Build/playwright/tests/playwright/config.tsscript712 B
assets/Build/playwright/tests/playwright/e2e/backend-module.spec.tsscript1.9 KB
assets/Build/playwright/tests/playwright/fixtures/setup-fixtures.tsscript2.7 KB
assets/Build/playwright/tests/playwright/helper/login.setup.tsscript975 B
assets/FunctionalTests.xmlconfig1.4 KB
assets/FunctionalTestsBootstrap.phpscript1.6 KB
assets/Makefileother2.3 KB
assets/UnitTests.xmlconfig890 B
assets/UnitTestsBootstrap.phpscript2.1 KB
assets/bootstrap.phpscript1.4 KB
assets/codecov.ymlconfig1.6 KB
assets/docker/codeception.ymlconfig979 B
assets/docker/docker-compose.ymlconfig1.4 KB
assets/example-tests/ExampleAcceptanceCest.phpscript2.2 KB
assets/example-tests/ExampleFunctionalTest.phpscript2.4 KB
assets/example-tests/ExampleUnitTest.phpscript1.6 KB
assets/fixtures/README.mdmarkdown2.0 KB
assets/fixtures/be_users.csvother361 B
assets/fixtures/pages.csvother257 B
assets/fixtures/sys_category.csvother228 B
assets/fixtures/tt_content.csvother338 B
assets/github-actions-e2e.ymlconfig8.8 KB
assets/github-actions-tests.ymlconfig6.3 KB
assets/infection.json5other2.8 KB
assets/phpat.neonother330 B
assets/phpat.phpscript8.4 KB
assets/phpstan-baseline.neonother365 B
assets/phpstan.neonother1.4 KB
assets/rector.phpscript2.9 KB
checkpoints.yamlconfig61.7 KB
references/accessibility-testing.mdmarkdown7.6 KB
references/architecture-testing.mdmarkdown4.4 KB
references/asset-templates-guide.mdmarkdown3.4 KB
references/backend-module-render-verification.mdmarkdown9.7 KB
references/backend-user-access-testing.mdmarkdown9.5 KB
references/captainhook-setup.mdmarkdown2.4 KB
references/ci-cd.mdmarkdown39.5 KB
references/ci-debugging.mdmarkdown20.0 KB
references/ci-workflows-meta-package.mdmarkdown11.6 KB
references/crash-and-concurrency-testing.mdmarkdown4.8 KB
references/crypto-testing.mdmarkdown16.6 KB
references/datahandler-silent-rewrites.mdmarkdown7.2 KB
references/ddev-testing.mdmarkdown1.3 KB
references/e2e-testing.mdmarkdown53.0 KB
references/enforcement-rules.mdmarkdown5.7 KB
references/event-dispatch-testing.mdmarkdown2.8 KB
references/framework-compat-gate.mdmarkdown4.9 KB
references/functional-test-patterns.mdmarkdown11.0 KB
references/functional-testing.mdmarkdown46.3 KB
references/fuzz-testing.mdmarkdown8.6 KB
references/integration-testing.mdmarkdown14.1 KB
references/javascript-testing.mdmarkdown29.3 KB
references/live-instance-verification.mdmarkdown8.6 KB
references/mock-validity.mdmarkdown15.7 KB
references/mutation-testing.mdmarkdown36.0 KB
references/performance-testing.mdmarkdown11.2 KB
references/quality-tools.mdmarkdown25.5 KB
references/release-workflow-validation.mdmarkdown3.6 KB
references/sonarcloud.mdmarkdown18.8 KB
references/synthetic-secret-fixtures.mdmarkdown3.8 KB
references/tdd-discipline.mdmarkdown9.1 KB
references/test-environment-guards.mdmarkdown18.5 KB
references/test-runners.mdmarkdown24.6 KB
references/typo3-ci-config-patterns.mdmarkdown9.0 KB
references/typo3-v14-final-classes.mdmarkdown16.5 KB
references/unit-testing.mdmarkdown59.1 KB
scripts/generate-test.shexecutablescript6.0 KB
scripts/setup-testing.shexecutablescript6.3 KB
scripts/validate-setup.shexecutablescript4.0 KB

references/backend-user-access-testing.md

View on GitHub
<!-- SPDX-License-Identifier: CC-BY-SA-4.0 -->
<!-- SPDX-FileCopyrightText: Netresearch DTT GmbH -->

# Backend-User Access in Functional Tests (non-admin, page & file mounts)

> **Source**: netresearch/t3x-nr-llm — testing per-user access enforcement on tools that egress data to an external LLM (2026-07). Verified on TYPO3 v13.4 / v14.3.

Testing that a **non-admin** backend user is correctly *confined* (to pages, languages, file mounts) is a common security requirement — and the framework setup is unobvious. These recipes let a functional test drive a real non-admin who genuinely passes or fails the core access checks, instead of a check that passes for the wrong reason.

## Contents

- `groupData` overrides apply live after `setUpBackendUser()`
- A non-admin reading a page: `readPageAccess` needs a web mount over the rootline
- `doesUserHaveAccess()` already enforces the web mount
- A non-admin confined to a file mount (real FAL enforcement)
- FAL permission API: `getFile()` does NOT assert — the mock-validity trap

## `groupData` overrides apply live after `setUpBackendUser()`

`setUpBackendUser($uid)` authenticates the user (so `fetchGroupData()` has run). You can then override the resolved permission data directly on `$GLOBALS['BE_USER']->groupData` and the core access methods honour it immediately — no re-auth needed:

```php
$this->setUpBackendUser(2); // a non-admin from BeUsers.csv
$beUser = $GLOBALS['BE_USER'];
self::assertInstanceOf(BackendUserAuthentication::class, $beUser); // narrows mixed for PHPStan
$beUser->groupData['webmounts']         = '5';           // getWebmounts() reads this
$beUser->groupData['tables_select']     = 'tt_content';  // check('tables_select', …) reads this
$beUser->groupData['allowed_languages'] = '0';           // checkLanguageAccess() reads this
```

## A non-admin reading a page: `readPageAccess` needs a web mount over the rootline

`BackendUtility::readPageAccess($uid, $permsClause)` returns `false` unless **both**:

1. the page matches the perms clause (`getPagePermsClause(Permission::PAGE_SHOW)`), **and**
2. `isInWebMount($uid, …)` is true — the page's **rootline** intersects `getWebmounts()`.

The web-mount step is the one that bites: giving a page `perms_everybody` is *not enough*. The web mount must cover the page's rootline. The simplest isolation is a **root page** (`pid = 0`, so its rootline is just itself) with the web mount pointing at it:

```php
$conn = $this->get(ConnectionPool::class)->getConnectionForTable('pages');
$conn->insert('pages', [
    'uid' => 5, 'pid' => 0, 'title' => 'Public', 'doktype' => 1,
    'sorting' => 5, 'perms_everybody' => Permission::PAGE_SHOW,
]);
$this->setUpBackendUser(2);
$GLOBALS['BE_USER']->groupData['webmounts'] = '5'; // rootline of page 5 is [5]
```

**Why it matters for a security test:** if the non-admin cannot reach *any* page, a "denied" assertion passes trivially (denied by page access, not by the thing you meant to test — e.g. a language gate). Make the user genuinely able to read the page, so the gate under test is the only variable.

## `doesUserHaveAccess()` already enforces the web mount

`BackendUserAuthentication::doesUserHaveAccess($row, $perms)` returns `(calcPerms($row) & $perms) == $perms`: every bit in `$perms` must be granted, and a zero mask returns `true` whatever `calcPerms()` says. `calcPerms()` returns `Permission::NOTHING` for a non-admin when `isInWebMount($row)` fails — before `perms_user`/`perms_group`/`perms_everybody` are read and before the `calcPerms` hook runs (cms-core 14.3.7: `doesUserHaveAccess()` lines 333-337, `calcPerms()` lines 544-553).

This holds for the core class, not for every object in `$GLOBALS['BE_USER']`. A subclass can override `calcPerms()` or `doesUserHaveAccess()`: EXT:workspaces' `PreviewUserAuthentication` (the `ADMCMD_prev` preview-link user) returns `Permission::PAGE_SHOW` for every row without consulting the web mount (cms-workspaces 14.3.7, lines 106-109). An edit check (`PAGE_EDIT`, `CONTENT_EDIT`) is still refused for it, but a `PAGE_SHOW` check passes outside any mount. Before relying on the guarantee, check which class the active user is and read its override.

So code that authorises a page with `doesUserHaveAccess()` and a non-zero `$perms` on a plain `BackendUserAuthentication` needs no extra `isInWebMount()` call. A review finding "the web-mount check is missing" is wrong unless the code authorises through something else — `getPagePermsClause()` alone, a raw `perms_*` comparison, or no page check at all. Settle it with a test, not a code change:

- the editor is a member of **at least one group** — `calcPerms()` ORs the `perms_*` bits only when `userGroupsUID` is non-empty (line 557), so a groupless editor is refused *inside* the mount too and the test proves nothing;
- the target page grants the permission through `perms_everybody` (e.g. `Permission::ALL`);
- `groupData['webmounts']` (overridden live, see above) points at a **different** root page → the call is refused;
- control: the same editor with `groupData['webmounts']` covering the target page → the call succeeds.

```php
// setUp: page 1 closed (perms_everybody = 0), page 2 open (perms_everybody = Permission::ALL),
// editor uid 2 in be_groups uid 7 (usergroup = '7')
$this->setUpBackendUser(2);
$GLOBALS['BE_USER']->groupData['webmounts'] = '1'; // page 2 is outside the mount
self::assertFalse($GLOBALS['BE_USER']->doesUserHaveAccess($openPageRow, Permission::CONTENT_EDIT));
// control, same editor: groupData['webmounts'] = '2' → assertTrue
```

> Source: netresearch/t3x-nr-llm [PR 958](https://github.com/netresearch/t3x-nr-llm/pull/958) — `anEditorOutsideTheirWebMountsIsRefusedWithTheNeutralWords` passed without a code change, and the issue claiming the writers skipped the web mount ([#960](https://github.com/netresearch/t3x-nr-llm/issues/960)) was closed as not planned.

## A non-admin confined to a file mount (real FAL enforcement)

To test that a tool only surfaces files inside the user's file mount, the `ResourceStorage` object must be built **while the non-admin is logged in inside a backend request** — only then does the core `StoragePermissionsAspect` (on `AfterResourceStorageInitializationEvent`) attach that user's file mounts and permissions to the storage. So insert the storage as a **DB row**, never instantiate it in `setUp`, and set a BE request in the test:

```php
private const STORAGE_CONFIGURATION = '<?xml version="1.0" ...>
<T3FlexForms><data><sheet index="sDEF"><language index="lDEF">
<field index="basePath"><value index="vDEF">fileadmin/</value></field>
<field index="pathType"><value index="vDEF">relative</value></field>
</language></sheet></data></T3FlexForms>';

// setUp: real files on disk + rows only (no ResourceStorage object yet)
GeneralUtility::mkdir_deep($this->instancePath . '/fileadmin/docs');
file_put_contents($this->instancePath . '/fileadmin/docs/manual.txt', 'in');
file_put_contents($this->instancePath . '/fileadmin/top-secret.txt', 'out');
$conn->insert('sys_file_storage', ['uid' => 1, 'pid' => 0, 'name' => 'Main', 'driver' => 'Local',
    'configuration' => self::STORAGE_CONFIGURATION, 'is_online' => 1, 'is_browsable' => 1, 'is_public' => 1]);
$conn->insert('sys_filemounts', ['uid' => 1, 'pid' => 0, 'title' => 'Docs', 'identifier' => '1:/docs/']);
$conn->insert('be_groups', ['uid' => 9, 'pid' => 0, 'title' => 'Docs', 'file_mountpoints' => '1',
    'file_permissions' => 'readFolder,readFile']);
$conn->update('be_users', ['usergroup' => '9', 'options' => 3], ['uid' => 2]); // options=3: inherit db+file mounts

// sys_file index rows — the *_hash columns must be the real sha1 identifier hash
// that core computes, or getFile() will not resolve the row:
$conn->insert('sys_file', ['uid' => 10, 'pid' => 0, 'storage' => 1, 'identifier' => '/docs/manual.txt',
    'identifier_hash' => sha1('/docs/manual.txt'), 'folder_hash' => sha1('/docs'),
    'name' => 'manual.txt', 'extension' => 'txt', 'mime_type' => 'text/plain', 'size' => 2, 'missing' => 0]);

// in the test: fake the backend request so StoragePermissionsAspect fires on first storage build
$this->setUpBackendUser(2);
$GLOBALS['TYPO3_REQUEST'] = (new ServerRequest('https://typo3-testing.local/typo3/'))
    ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
// tearDown(): unset($GLOBALS['TYPO3_REQUEST']);
```

A single indexed file's `sys_file` row needs no file on disk for `getFile()` to *resolve* it (the driver stats disk only for content reads), but the `identifier_hash` **must** be `sha1($identifier)`.

## FAL permission API: `getFile()` does NOT assert — the mock-validity trap

The most dangerous mistake here is testing enforcement against a **fabricated** mock. `ResourceStorage::getFile($identifier)` only *resolves* the index row; it never calls `assureFileReadPermission()` / `isWithinFileMountBoundaries()` and so **`setEvaluatePermissions(true)` has no effect on it**. Stubbing `getFile()->willThrowException()` for "out of mount" invents a behaviour core never exhibits — the test goes green while the production gate enforces nothing (security-theater).

The methods that *do* assert (honour `evaluatePermissions` + the attached file mounts):

- `checkFileActionPermission('read', $file)` — returns `bool` (no throw), the cleanest per-file gate;
- `isWithinFileMountBoundaries($file)` — returns `bool`;
- `getFolder($id)` / `getFilesInFolder()` — **throw** outside the mount (this is why `getFolder`-based browsing enforces while `getFile` does not).

So: verify FAL mount enforcement with the **real storage + file-mount functional recipe above**, not a `getFile` stub. See also `mock-validity.md`.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall