test(security): backfill encryption tests for Telegram/WhatsApp/Slack-002 (#664)#876
Conversation
vybe
left a comment
There was a problem hiding this comment.
Substance is approved — 31 well-organized tests, follows the #453 pattern, fixtures are unambiguously fake (xoxb-FAKE-TEST-FIXTURE-… / alphabet-walk fillers), the WhatsApp suite correctly pins the account_sid plaintext invariant, CSO --diff CLEAR, pytest matrix green across all 6 seeds.
Two blockers before merge:
-
Rebase on current
devto fix the lint failure. Same root cause I flagged on #875: PR #881 landed ondevwith thetest_slot_per_slot_ttl.pybaseline bump (0 → 6) needed after #871. This branch's merge-base is98574f37, older than #881 (587599d4), so the lint job sees those 6 violations as new on this PR. Rebasing should drop the failure. -
Untangle the 4 feature-flow doc edits from commit
744ab05d. That commit ("sync flows with recent merges") editsagent-monitoring.md,parallel-headless-execution.md,platform-settings.md, andpublic-agent-links.md— none related to #664. Against currentdevthey still diverge meaningfully (68/32/130/299 lines), so they're not just merge-noise. Please either: (a) confirm post-rebase they collapse to no-op, or (b) split that commit into a separatedocs(feature-flows): sync …PR so this PR only carries the encryption-test backfill it advertises.
Re-approve immediately once CI is green and the scope is just the tests + .gitignore + CSO archive.
…-002 (#664) Adds 31 unit tests covering the AES-256-GCM encryption that already shipped on three channel bot-token columns: - `telegram_bindings.bot_token_encrypted` (db/telegram_channels.py) - `whatsapp_bindings.auth_token_encrypted` (db/whatsapp_channels.py) - `slack_workspaces.bot_token` (db/slack_channels.py, SLACK-002) Each suite covers: round-trip via the public ops API, raw DB envelope inspection (AES-256-GCM JSON with nonce + ciphertext), corrupt-envelope and wrong-key decryption failure, fresh-nonce on update, missing-key behavior. Slack-002 additionally pins the plaintext-fallback path at slack_channels.py:47-49 (legacy xoxb-* rows + operator WARNING log). WhatsApp pins the `account_sid` plaintext invariant so future refactors don't accidentally encrypt the public Twilio identifier. Mirrors the test pattern established in #453 (tests/unit/test_slack_token_encryption.py) for SLACK-001 / db/slack.py. Pure test backfill — no production code changes, no new dependencies. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Adds `uv.lock` to .gitignore. The repo uses `pyproject.toml` only for pytest configuration (no `[project]` or `[tool.uv]` section). Running `uv` against this tree generates a 3-line empty lockfile with no `[[package]]` entries — checking it in adds churn with zero supply-chain signal. Flagged as L-1 in the #664 CSO diff audit. - Adds the CSO diff audit report alongside the historical reports in docs/security-reports/. Verdict: CLEAR (test-only backfill, no new surface, fixtures unambiguously fake). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
744ab05 to
1ca38f2
Compare
|
Both blockers addressed: 1. Rebased on current 2. Dropped the feature-flow doc commit (744ab05). You were right — those edits diverge meaningfully from current Final scope (6 files):
Verification:
Ready for re-review. |
Summary
Backfills the unit-test coverage that was missing for the AES-256-GCM
encryption already shipped on three channel bot-token columns:
telegram_bindings.bot_token_encrypteddb/telegram_channels.pywhatsapp_bindings.auth_token_encrypteddb/whatsapp_channels.pyslack_workspaces.bot_tokendb/slack_channels.py(SLACK-002)These columns store an AES-256-GCM JSON envelope but had no dedicated
tests for the encryption invariant. This PR adds 31 unit tests following
the proven pattern from
tests/unit/test_slack_token_encryption.py(#453).Closes #664.
What each suite covers
{"algorithm": "AES-256-GCM", "nonce": …, "ciphertext": …}, never the original token.None+ ERROR log.None(AES-256-GCM auth-tag rejection, protects against key-substitution attacks).encryptraises;decryptreturnsNonecleanly.SLACK-002-specific
slack_channels.py:47-49— legacyxoxb-*rows still readable; operator-facing WARNING log fires (caplog-asserted).get_all_workspacesdecrypts every row, not just the first.WhatsApp-specific
account_sidplaintext invariant — pinned so future refactors don't accidentally encrypt the public Twilio identifier (which would silently break Twilio API calls).Scope
Pure test backfill. No production code changes. No new dependencies.
Repo hygiene picked up along the way (CSO L-1 finding on this branch):
.gitignore: ignore the emptyuv.lockthatuvgenerates against this repo's pytest-onlypyproject.toml.docs/security-reports/cso-diff-2026-05-17.md: archived CSO--diffaudit for this PR (verdict: CLEAR).Pre-Landing Review
?placeholders — clean.xoxb-FAKE-TEST-FIXTURE-…,123456:FAKE-…, alphabet-walk filler).secrets.token_hex(32)CREDENTIAL_ENCRYPTION_KEYrotated per test viamonkeypatchautouse fixture.tmp_pathSQLite +monkeypatch.setattr(module, "get_db_connection", …)— no shared state.sys.moduleslint: passes (229 violations / 232 baseline, no new entries).ruff check: passes.CSO
--diffverdict: CLEAR (no real secrets, no new auth surface, no new supply-chain surface).Test plan
uv run pytest tests/unit/test_slack_workspaces_encryption.py tests/unit/test_telegram_token_encryption.py tests/unit/test_whatsapp_token_encryption.py→ 31 passedorigin/dev(which brought in bug: Cleanup watchdog falsely kills long-running executions as stale before timeout expires #869/fix(cleanup): per-slot TTL prevents false-kill of long-running executions (#869) #871 — unrelated slot-service work, no conflicts) → 31 passeduv run python tests/lint_sys_modules.py→ 0 new violationsuv run ruff checkon the new files → clean🤖 Generated with Claude Code