Skip to content

Conversation

@Snider
Copy link
Owner

@Snider Snider commented Oct 30, 2025

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.

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>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Added test coverage for encryption and decryption error handling scenarios, including validation of error messages when using incorrect passphrases, malformed messages, non-existent recipients, and signing failures.

Walkthrough

Two 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

Cohort / File(s) Summary
OpenPGP test utilities
pkg/crypt/openpgp/test_util.go
New utility file introducing embedded encrypted PGP private key constant and helper function to write the key to temporary files with proper cleanup for test execution
OpenPGP error-handling tests
pkg/crypt/openpgp/encrypt_extra_test.go
New test file with four test cases: TestDecryptWithWrongPassphrase, TestDecryptMalformedMessage, TestEncryptWithNonexistentRecipient, and TestEncryptAndSignWithWrongPassphrase validating error paths in encryption and decryption operations

Poem

🐰 Four test cases hop with care,
To catch the errors hiding there,
Wrong passphrases, malformed files too,
A helper's hand to see them through,
The cryptic vault is tested true!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "(#14) feat(openpgp): increase test coverage" directly aligns with the main changeset, which introduces a new test file (encrypt_extra_test.go) containing four new test cases for error handling and edge cases in the openpgp package. The title is concise, clear, and specific enough that a teammate reviewing the commit history would immediately understand that new tests are being added to improve test coverage for the openpgp package. The phrasing is appropriate and avoids vague terminology.
Description Check ✅ Passed The pull request description is directly related to the changeset and provides meaningful information about the changes. It accurately describes the addition of new tests to the pkg/crypt/openpgp package for error handling and edge cases, mentions the new test file by name, and explains the addition of a pre-generated encrypted PGP key with a clear rationale for working around a go-crypto library limitation. The description is specific and substantive rather than vague or generic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between a410e53 and 111e5e1.

📒 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 DecryptPGP handles malformed input gracefully. The test setup is appropriate and the error assertions validate the expected behaviour.


46-52: LGTM!

This test correctly verifies that EncryptPGP fails 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.

@Snider Snider merged commit 30efd31 into main Oct 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants