Repository navigation
Description
Summary
Remove persistent encryption provisioning/conversion from the PHPUnit bootstrap. Initialize a valid test-only encryption key in memory instead, and keep provisioning/conversion coverage in isolated tests.
Requested by @objecttothis as a follow-up outside PR #4694. Leave this issue unassigned.
Rationale
Production releases exclude tests, and Config\Database selects the tests database group under the testing environment. This is primarily a developer-checkout and CI isolation concern, not a claim that normal test runs modify a separate production database.
However, tests/bootstrap.php calls checkEncryption() before test setUp() runs:
- With an absent key, the helper provisions a key and persists it to the checkout's
.env. - With a nonempty key shorter than 64 characters, the helper reads legacy database secrets and can rotate the
.envkey and persist converted secrets. Config\SecurityEnvdefaults to the checkout's.env, even when the test database is separate.- Security-helper tests redirect filesystem paths only in
setUp(). Database reset/seeding also happens after bootstrap. - A short key can therefore require an available, initialized test database before test setup. A missing key or short key can also require writable checkout configuration.
Resetting the test database later does not undo a bootstrap write to .env. If a developer checkout uses that key for another database, changing the shared key can leave that database's ciphertext out of sync.
Required changes
- Replace the bootstrap call to
checkEncryption()with in-memory test-key initialization before tests use the encrypter. - Do not persist the test key or run automatic legacy conversion during general test startup.
- Preserve explicit provisioning and conversion tests using isolated filesystem paths and mocked or dedicated database state.
- Account for cached encrypter/config instances so tests use the intended test key.
- Keep runtime provisioning and CI3-to-CI4 migration behavior unchanged.
Affected areas
tests/bootstrap.phptests/Helpers/security_helperTest.phpapp/Helpers/security_helper.php(behavior exercised, not necessarily requiring changes)app/Config/SecurityEnv.phpandapp/Config/Database.php(isolation boundaries)
Acceptance criteria
- Starting a focused database-free unit test with an absent or short checkout key does not modify the checkout's
.env, backup, or lock files. - General bootstrap does not initiate legacy-secret database reads or conversion.
- Focused database-free tests do not need an initialized database solely for encryption bootstrap.
- Tests that need encryption receive a valid in-memory test key.
- Sandboxed provisioning/conversion tests and database-backed tests continue to pass.
References
- PR: feat(manage-tables): add export-all-rows toggle to bootstrap-table toolbar #4694
- Review discussion: feat(manage-tables): add export-all-rows toggle to bootstrap-table toolbar #4694 (comment)
Analysis is based on source inspection; no repository code was executed.
Activity
objecttothis commentedon Oct 24, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Premise doesn't match current
master— the described file/flow doesn't exist there.tests/bootstrap.phpin the repository.phpunit.xml.distusesbootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"(the framework's own bootstrap), not a custom OSPOS one.checkEncryption()(app/Helpers/security_helper.php) is only invoked from runtime code paths —Config::__construct()/Config::postSaveInfo(),Email_lib, and the20220127000000_convertToCI4migration — not from any general PHPUnit bootstrap/startup hook.tests/Helpers/security_helperTest.phpalready does exactly what this issue's acceptance criteria ask for: it redirectsconfig('SecurityEnv')->envPath/backupPath/lockPathto a unique per-run temp sandbox insetUp()/tearDown(), so itscheckEncryption()/rotateEncryptionKey()/conversion tests never touch the real checkout.env, and DB-backed conversion tests use a fakeAppconfigrather than a real database.So the specific race this issue describes (a shared
tests/bootstrap.phpcallingcheckEncryption()globally beforesetUp(), risking persisted.envwrites for unrelated focused/unit tests) isn't present onmasteras far as I can find — there's no such bootstrap file, and the one test file that does exercisecheckEncryption()is already fully sandboxed. The referenced PR #4694 (still open) doesn't appear to introduce this bootstrap call either. I'd flag this to a maintainer to confirm whether the issue was filed against a different/future state of the code, since I can't locate the problematic code path on currentmaster.