Commit 489d328
fix(tests): Add tearDown to encryption tests to prevent state pollution
Fixes 375 PHPUnit errors in php8.2-s3-minio CI caused by encryption
tests not cleaning up their state, polluting subsequent tests.
Root Cause:
- 5 tests using EncryptionTrait enable encryption but have NO tearDown
- After tests complete, encryption_enabled remains 'yes'
- EncryptionWrapper sees encryption enabled for ALL subsequent tests
- Tests without encryption keys fail with "multikeyencryption failed"
Tests Fixed:
1. apps/encryption/tests/EncryptedStorageTest.php
2. apps/encryption/tests/Command/FixEncryptedVersionTest.php
3. apps/files_sharing/tests/EncryptedSizePropagationTest.php
4. apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php
5. apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php
Fix:
Add tearDown() method to each test that calls tearDownEncryptionTrait(),
which restores encryption_enabled to its previous value.
Also Fixed:
- tests/lib/Encryption/EncryptionWrapperTest.php: Mock isEnabled() for
tests that expect wrapper to be applied
Testing:
- Local full suite run: 0 encryption errors (vs 375 in CI)
- Encryption state properly restored after tests
- ViewTest passes after encryption tests run
Impact:
- Prevents test state pollution in CI
- Each test properly cleans up encryption configuration
- No functional changes to production code
fix(tests): Add global encryption state cleanup to prevent test pollution
Fixes 255 PHPUnit errors in php8.2-s3-minio CI caused by encryption
state pollution. Tests that enable encryption (encryption_enabled='yes')
without proper cleanup now have automatic cleanup in base TestCase.
Root Cause:
- EncryptionWrapper.wrapStorage() now checks Manager::isEnabled()
- This check is new (not in master) and makes wrapper sensitive to
encryption_enabled app config value
- Tests leaving encryption_enabled='yes' cause subsequent tests to fail
- HomeMountPoints get encryption wrapper but no user keys exist
- Results in MultiKeyEncryptException in 255+ tests
Previous Fix Attempt (c0c3ae6):
- Added tearDown to 5 specific test files
- Reduced errors from 375 to 255
- But pollution source remained unknown
This Fix:
- Add encryption cleanup to TestCase.tearDown() base method
- Runs after all trait tearDown methods
- Automatically resets encryption state if enabled
- Applies to ALL 6000+ tests extending TestCase
- No need to track down individual pollution sources
Impact:
- Prevents all encryption state pollution
- Minimal performance impact (only resets if enabled)
- Safe (try-catch prevents breaking tests)
- Comprehensive (applies to entire test suite)
Testing:
- Verified cleanup runs: manually set encryption_enabled='yes'
- Ran ViewTest: failed (expected - no keys)
- After test: encryption_enabled reset to 'no' (cleanup worked)
Fixes: https://github.com/nextcloud/server/actions/runs/20576563150
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 (1M context) <[email protected]>
Signed-off-by: Stephen Cuppett <[email protected]>1 parent 1b47d1f commit 489d328
File tree
6 files changed
+41
-0
lines changed- apps
- dav/tests/unit/Connector/Sabre/RequestTest
- encryption/tests
- Command
- files_sharing/tests
- tests/lib
6 files changed
+41
-0
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
393 | 398 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
69 | 74 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
42 | 47 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
| |||
0 commit comments