Decryption error handling and encryption service test cases update#2724
Merged
crivetimihai merged 1 commit intomainfrom Feb 15, 2026
Merged
Conversation
Member
|
Great work on the encryption subsystem improvements, @MohanLaksh! The v2 format prefix, double-encryption prevention, and the strict/idempotent API split are all well-designed. The test suite is comprehensive — good coverage of concurrent async, wrong-key scenarios, and real-world token formats. A few items to address:
|
f1ca890 to
d0ca2d2
Compare
Collaborator
Author
|
Can you please review and merge this PR. I have rebased the PR against main and have addressed the following review feedback:
|
74678fa to
05334a3
Compare
- Add AlreadyEncryptedError and NotEncryptedError (extend ValueError) for explicit validation in strict mode - Introduce v2: format prefix for unambiguous encrypted data detection - Add strict vs idempotent API modes (decrypt_secret vs decrypt_secret_or_plaintext) with backward-compatible async wrappers - Replace length heuristic in oauth_manager with explicit is_encrypted() - Add null checks after decryption in dcr_service update/delete - Migrate encryption tests to dedicated test_encryption_service.py - Add comprehensive test coverage for edge cases, concurrent operations, and real-world token formats (JWT, OAuth2, API keys) Closes #2405 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
05334a3 to
80993a7
Compare
crivetimihai
approved these changes
Feb 15, 2026
suciu-daniel
pushed a commit
that referenced
this pull request
Feb 16, 2026
…2724) - Add AlreadyEncryptedError and NotEncryptedError (extend ValueError) for explicit validation in strict mode - Introduce v2: format prefix for unambiguous encrypted data detection - Add strict vs idempotent API modes (decrypt_secret vs decrypt_secret_or_plaintext) with backward-compatible async wrappers - Replace length heuristic in oauth_manager with explicit is_encrypted() - Add null checks after decryption in dcr_service update/delete - Migrate encryption tests to dedicated test_encryption_service.py - Add comprehensive test coverage for edge cases, concurrent operations, and real-world token formats (JWT, OAuth2, API keys) Closes #2405 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
vishu-bh
pushed a commit
that referenced
this pull request
Feb 18, 2026
…2724) - Add AlreadyEncryptedError and NotEncryptedError (extend ValueError) for explicit validation in strict mode - Introduce v2: format prefix for unambiguous encrypted data detection - Add strict vs idempotent API modes (decrypt_secret vs decrypt_secret_or_plaintext) with backward-compatible async wrappers - Replace length heuristic in oauth_manager with explicit is_encrypted() - Add null checks after decryption in dcr_service update/delete - Migrate encryption tests to dedicated test_encryption_service.py - Add comprehensive test coverage for edge cases, concurrent operations, and real-world token formats (JWT, OAuth2, API keys) Closes #2405 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…BM#2724) - Add AlreadyEncryptedError and NotEncryptedError (extend ValueError) for explicit validation in strict mode - Introduce v2: format prefix for unambiguous encrypted data detection - Add strict vs idempotent API modes (decrypt_secret vs decrypt_secret_or_plaintext) with backward-compatible async wrappers - Replace length heuristic in oauth_manager with explicit is_encrypted() - Add null checks after decryption in dcr_service update/delete - Migrate encryption tests to dedicated test_encryption_service.py - Add comprehensive test coverage for edge cases, concurrent operations, and real-world token formats (JWT, OAuth2, API keys) Closes IBM#2405 Signed-off-by: Mohan Lakshmaiah <mohan.economist@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
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.
Decryption Error Handling and Encryption Service Unit Tests
Summary
This PR enhances the encryption service with robust error handling, clear API contracts, and comprehensive test coverage. It addresses three critical issues: double encryption prevention, unclear decryption errors, and test organization.
Changes
1. Double Encryption Prevention
AlreadyEncryptedErrorexception raised when attempting to encrypt already-encrypted dataencrypt_secret()now validates input withis_encrypted()before encryption2. Clear Decryption Error Messages
NotEncryptedErrorexception with explicit message when decrypting plaintextinvalid literal: line 1 column 1 (char 0)) with contextual messages:3. Strict vs Idempotent API Modes
Strict Mode (explicit validation):
encrypt_secret()- RaisesAlreadyEncryptedErrorif input already encrypteddecrypt_secret()- RaisesNotEncryptedErrorif input not encrypteddecrypt_secret_strict_async()- Async strict variantIdempotent Mode (resilient):
decrypt_secret_or_plaintext()- Returns plaintext unchanged if not encrypted, None on errordecrypt_secret_async()- Backward compatible (idempotent)decrypt_secret_or_plaintext_async()- Explicit idempotent async4. Enhanced Format Detection
New v2 Format:
"v2:{...json...}"for unambiguous detectionRobust Detection:
_is_valid_v2_bundle()- Validates v2: prefixed bundles_is_valid_json_bundle()- Legacy JSON format support_is_valid_fernet_format()- Legacy Fernet binary format_looks_like_failed_encryption()- Heuristic for corrupted data5. Comprehensive Documentation
is_encrypted()limitations6. Test Suite Migration and Expansion
test_oauth_manager.pyto newtest_encryption_service.py7. Consumer Updates
dcr_service.py:update_client()anddelete_client()DcrErrorif decryption failsoauth_manager.py:len(client_secret) > 50) with explicitis_encrypted()checkexchange_code_for_token(),refresh_token(),password_grant(),get_token_with_client_credentials()Files Changed
Testing
Migration Strategy
Security Improvements
is_encrypted()returnsFalsefor ambiguous dataBackward Compatibility
Impact
Positive:
Risk Mitigation:
Closes #2405