Repository navigation
feat: ship a shared FakeEncryptor in marko/testing - #523
Merged
Merged
Conversation
Packages that needed an encryptor in tests each wrote their own anonymous EncryptorInterface fake, so the $aad signature change in #502 broke every one of them. Marko\Testing\Fake\FakeEncryptor replaces them: a reversible encoding that records encrypt()/decrypt() calls, differs per call like a real cipher, and binds the ciphertext to its associated data so decrypt() with a different $aad throws a DecryptionException naming both values. assertEncrypted()/assertDecrypted() (value and AAD both optional) and assertNothingEncrypted()/assertNothingDecrypted() follow the other fakes. The security CSRF tests and the database encrypted-column tests now use it. marko/testing requires marko/encryption (contracts only). Fixes #515 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KyjR4cJTfro54iFZ9CWkv1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Marko\Testing\Fake\FakeEncryptor, which implementsEncryptorInterface. It uses a reversible encoding (fake-encrypted:{n}:{base64 aad}:{base64 value}), so ciphertext differs per call like a real cipher and any instance can decrypt another's output.decrypt()with a different$aadthrows aDecryptionExceptionnaming both values (for exampledecrypt() was given associated data 'users.email', but the value was encrypted with 'users.ssn'). Input the fake did not produce throwsDecryptionException::invalidPayload(). Code under test that catchesDecryptionExceptiontherefore behaves as it does in production.encrypt()calls and successfuldecrypt()calls ($encrypted,$decrypted). AddsassertEncrypted(?value, ?aad),assertDecrypted(?value, ?aad),assertNothingEncrypted(),assertNothingDecrypted()andclear(). Nothing is auto-bound.security(CsrfTokenManagerTest,CsrfRotationOnAuthTest) anddatabase(EncryptedColumnTest, which drops its static$aadsrecorder forassertEncrypted(aad: ...)) onto the new fake.marko/testingnow requiresmarko/encryption(contracts only). Documents the fake on the testing docs page (usage and API reference) and in the README fakes list and usage.Not migrated:
packages/webhook/tests/Fixtures/FakeEncryptor.phpis out of scope for this PR because another change touches that package. It can move to the shared fake in a follow-up. The roadrunner fixture app binds the realOpenSslEncryptorfor its end-to-end flow and has no fake to replace.Test plan
packages/testing/tests/Unit/Fake/FakeEncryptorTest.php(19 tests) covers: round trip (including binary values), unique ciphertext per call, decrypting across instances, the AAD-mismatch exception, the invalid-payload exception, call recording, and every assertion helpercomposer test,phpcs,phpstangreen locallyFixes #515
🤖 Generated with Claude Code
https://claude.ai/code/session_01KyjR4cJTfro54iFZ9CWkv1