Repository navigation
Description
Summary
Add encryption round-trip and decryption-failure tests for the channel bot token encryption that already shipped without dedicated test coverage.
Background
Trinity stores bot/auth tokens for three external channels in encrypted form via services.credential_encryption.CredentialEncryptionService (AES-256-GCM):
telegram_bindings.bot_token_encrypted—db/telegram_channels.pywhatsapp_bindings.auth_token_encrypted—db/whatsapp_channels.pyslack_workspaces.bot_token(encrypted-blob-in-text-column) —db/slack_channels.pyslack_link_connections.slack_bot_token—db/slack.py(will be encrypted as part of fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453)
The encryption code itself is well-tested via the services.credential_encryption test suite. What's missing: per-channel integration tests that verify the round-trip through each *ChannelOperations class — encrypt-on-write, decrypt-on-read, decryption-failure handling, and the plaintext fallback path (slack_channels.py:47-49).
This was discovered during #453 investigation (see project memory project_453_slack_encryption.md) — Telegram and WhatsApp tables have no encryption-specific test files. Slack-002 (slack_channels.py) also lacks them.
Scope
For each of the three already-shipped encrypted-token storage modules, add a unit test file covering:
tests/unit/test_telegram_token_encryption.py (NEW)
- Round-trip:
create_binding→ raw column read → assert JSON envelope →get_decrypted_bot_tokenreturns plaintext - Decryption failure: tamper with envelope →
_decrypt_tokenreturnsNone, no exception leaks to caller - Re-encryption on update: second
create_bindingfor same agent_name updates the encrypted blob
tests/unit/test_whatsapp_token_encryption.py (NEW)
- Same coverage for
WhatsAppChannelOperations._encrypt_auth_token/_decrypt_auth_token - Twilio-specific:
account_sidstays plaintext (it's not a credential), onlyauth_token_encryptedis encrypted
tests/unit/test_slack_workspaces_encryption.py (NEW)
- Round-trip for
SlackChannelOperations._encrypt_token/_decrypt_token - Plaintext fallback path at
slack_channels.py:47-49— assert that a row with rawxoxb-*bot_token returns the token via_decrypt_token(current behavior — preserves graceful handling for legacy plaintext rows) - Verify the warning is logged
Out of scope
slack_link_connections(db/slack.py) — this module is getting encryption added as part of fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453, and its tests are part of that PR- Any logic changes to the existing encryption code — pure test addition
- Architecture doc updates — already covered in fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453
Acceptance Criteria
-
test_telegram_token_encryption.pycovers round-trip + decryption-failure (≥3 tests) -
test_whatsapp_token_encryption.pycovers round-trip + decryption-failure (≥3 tests) -
test_slack_workspaces_encryption.pycovers round-trip + decryption-failure + plaintext-fallback (≥4 tests) - All tests use the
CREDENTIAL_ENCRYPTION_KEYtest fixture pattern (look at how the newdb/slack.pytests do it in fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453's PR for reference) - Test registry (
tests/registry.json) updated with the three new entries - All tests pass against the live backend
Effort estimate
~2 hours. Mostly mechanical — copy the test pattern from tests/unit/test_slack_token_encryption.py (added in #453) and adapt for each channel's class.
References
- Originating context: fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453 investigation (project memory
project_453_slack_encryption.md) - Encryption primitive:
src/backend/services/credential_encryption.py(AES-256-GCM, JSON envelope) - Test pattern reference: whatever
tests/unit/test_slack_token_encryption.pylooks like after fix(security): Encrypt Slack and Telegram bot tokens at rest (Invariant #13) #453 lands - Architectural Invariant fix: Add ARM64 Alpine compatibility for frontend Docker build #12 (credentials handling):
docs/memory/architecture.md
Activity
fix(security): Encrypt Slack bot tokens at rest (#453)
fix(security): encrypt SLACK-001 bot tokens at rest (#453) (#667)
AndriiPasternak31 commentedon May 17, 2026
/claim
github-actions commentedon May 17, 2026
Claimed by @AndriiPasternak31. Label
status-in-progressadded.Next steps:
feature/664-<short-slug>Fixes #664test(security): backfill encryption tests for Telegram/WhatsApp/Slack…
chore: gitignore empty uv.lock and archive CSO diff audit for #664
test(security): backfill encryption tests for Telegram/WhatsApp/Slack…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
Release: v0.6.1 (#1171)