Add error-path tests for HybridDecrypter.Decrypt in the crypto package
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 364
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 84
Description
What would you like to be added:
I'd like to add unit tests for the error paths in HybridDecrypter.Decrypt(). Right now the only test we have (TestHybridEncryptDecrypt) just tests the happy path — encrypt something valid, decrypt it back, make sure it matches. But the Decrypt function has around 5 different ways it can fail, and none of them are tested.
My plan is to add a table-driven test that covers:
- Passing in garbage that isn't valid base64
- Passing in data that's too short to even read the RSA length header
- Passing in data where the declared RSA length is bigger than what's actually there
- Tampering with the RSA ciphertext portion so RSA OAEP decryption fails
- Tampering with the AES-GCM ciphertext portion so the authentication check fails — this is the one that worries me most because if someone accidentally breaks that GCM auth check, tampered secrets would just pass through silently
I've already looked at how the rest of the crypto package does tests (TestNewAESEncryptDecrypterInvalidKey, TestAESEncryptDecrypt, etc.) and I'll match that same style — testify/require and testify/assert, same-package tests, reading keys from testdata/.
Why is this needed:
I was reading through hybrid.go and noticed the Decrypt function has quite a few places where it can return errors, but none of them have tests. The one that really stood out to me is the AES-GCM authentication check on line 143 (aed.Open). That's the function that verifies the ciphertext hasn't been tampered with. If someone accidentally broke that check in a refactor, we might not catch it because the only test just tests valid data.
Since this crypto code is what powers PipeCD's sealed secrets feature, I think it's worth having these tests in place. Better to catch a regression early than to have tampered secrets slip through.
If this approach aligns with what you had in mind, I can go ahead and put together the implementation. If you'd prefer a different structure or have additional cases you want covered, just let me know.... happy to adjust!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with hybrid.go's Decrypt and the existing TestHybridEncryptDecrypt, then review TestNewAESEncryptDecrypterInvalidKey and TestAESEncryptDecrypt for the package's testify style and testdata key setup. Add coverage for the five listed failure paths and run the crypto package tests; done means invalid base64, malformed lengths, RSA tampering, and AES-GCM tampering all return errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- security
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100