-
Notifications
You must be signed in to change notification settings - Fork 0
(#14) feat(openpgp): increase test coverage #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds new tests to the `pkg/crypt/openpgp` package to cover error handling and edge cases in the `EncryptPGP` and `DecryptPGP` functions. - Adds a new test file, `encrypt_extra_test.go`, with tests for incorrect passphrases, malformed messages, and signing failures. - Adds a pre-generated, encrypted PGP key to be used in tests, working around a limitation in the `go-crypto` library that prevents programmatic generation of encrypted keys. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
📝 WalkthroughSummary by CodeRabbit
WalkthroughTwo new files have been added to the openpgp package: a test utility file providing helpers for managing encrypted PGP keys, and a test file containing four test cases validating error handling across encryption and decryption workflows. Changes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
pkg/crypt/openpgp/encrypt_extra_test.go(1 hunks)pkg/crypt/openpgp/test_util.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/crypt/openpgp/encrypt_extra_test.go (1)
pkg/crypt/openpgp/encrypt.go (2)
EncryptPGP(113-164)DecryptPGP(167-233)
🪛 Gitleaks (8.28.0)
pkg/crypt/openpgp/test_util.go
[high] 11-76: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.
(private-key)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: coverage
- GitHub Check: coverage
🔇 Additional comments (5)
pkg/crypt/openpgp/test_util.go (2)
9-76: Static analysis alert is a false positive for test data.The static analysis tool has flagged the embedded PGP private key as a security concern. However, this is clearly documented as test-only data with the passphrase ("test-passphrase") explicitly stated in the comment. This is an appropriate pattern for test fixtures.
78-96: LGTM!The helper function correctly uses
t.Helper()for proper test reporting, creates temporary directories securely, writes the key file with appropriate permissions (0600), and provides a cleanup function. The implementation follows testing best practices.pkg/crypt/openpgp/encrypt_extra_test.go (3)
31-44: LGTM!This test correctly verifies that
DecryptPGPhandles malformed input gracefully. The test setup is appropriate and the error assertions validate the expected behaviour.
46-52: LGTM!This test correctly verifies that
EncryptPGPfails appropriately when the recipient's public key file doesn't exist. The error handling validation is accurate.
54-71: LGTM!This test correctly verifies that signing during encryption fails when an incorrect passphrase is provided for the encrypted private key. The test setup properly separates the recipient and signer keys, and the error assertions validate the expected behaviour.
Adds new tests to the
pkg/crypt/openpgppackage to cover error handling and edge cases in theEncryptPGPandDecryptPGPfunctions.encrypt_extra_test.go, with tests for incorrect passphrases, malformed messages, and signing failures.go-cryptolibrary that prevents programmatic generation of encrypted keys.