test: add error-path coverage for key format operations#106
Merged
atoomic merged 1 commit intoMar 16, 2026
Merged
Conversation
Cover 6 previously untested error paths: - new_public_key() with unrecognized key format - get_private_key_string() with cipher but no passphrase - get_private_key_string() with unsupported cipher name - new_private_key() with wrong passphrase - new_private_key() with garbage input - new_private_key() with truncated PEM
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.
What
Add 6 tests covering previously untested error paths in key format operations.
Why
The
new_public_key(),new_private_key(), andget_private_key_string()functionshave error paths (unrecognized format, bad passphrase, unsupported cipher, garbage PEM)
that had zero test coverage. These are the kind of paths that silently break during
refactoring.
Testing
All 287 tests pass (281 existing + 6 new). Tested on macOS with OpenSSL 3.x.
New tests
new_public_key("garbage")→ croak "unrecognized key format"get_private_key_string(undef, 'aes-128-cbc')→ croak "Passphrase is required"get_private_key_string('secret', 'no-such-cipher')→ croak "Unsupported cipher"new_private_key($encrypted_key, 'wrong-passphrase')→ croaknew_private_key("garbage")→ croaknew_private_key("-----BEGIN RSA PRIVATE KEY-----\ngarbage\n...")→ croakQuality Report
Changes: 1 file changed, 25 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline