Add compactStructuredEncryptionData administration command tests#625
Conversation
…tion - Add NOT_ENCRYPTED_COLLECTION_ERROR constant to error_codes.py - Use bson_type_validator for exhaustive compactionTokens type rejection - Use CommandTestCase with pytest_params for parametrized core/error/edge tests - Fix smoke test to use assertFailureCode (no message content checks) - Remove redundant response structure standalone test Signed-off-by: Ian Forster <forstaia@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, test-framework); effort from diff stats (405+5 LOC, 10 files); LLM: Adds 36 new compatibility test cases for the compactStructuredEncryptionData command across multiple new test files, touching one component with no schema changes. If a label is wrong, remove it manually and ping |
eerxuan
left a comment
There was a problem hiding this comment.
§16 happy-path coverage — verified reachable on mongo-replset
Nice, clean DRY structure throughout (good reuse of bson_type_validator, logical file split, and the smoke-test fix to assertFailureCode). One gap worth addressing before merge.
Every test here asserts a rejection path. Per TEST_COVERAGE.md §16, a collection command also needs its success path — "primary operation succeeds and returns expected response fields." I checked whether that
path is actually reachable, since on standalone it isn't (creating a QE collection fails with 6346402 "Encrypted collections are not supported on standalone", so the all-rejection strategy is correct for that
target).
It is reachable on the mongo-replset target the harness already supports. Tested against mongo:8.2.4:
// QE collection created server-side via create + encryptedFields (UUID keyId)
db.runCommand({
compactStructuredEncryptionData: "enc",
compactionTokens: { ssn: }
})
// →
{ stats: { ecoc: { read: 0, deleted: 0 },
esc: { read: 0, inserted: 0, updated: 0, deleted: 0 } },
ok: 1.0 }
Two things this surfaces:
- Success path is testable and returns a documented stats.{esc,ecoc} shape — assertable with assertProperties.
- The current compactionTokens "content edge case" tests (null_token_value, empty_string_key, dot_notation_key, nested_document_value) all short-circuit on 6346807 (not-encrypted) on standalone, so they don't
actually exercise token parsing. On a QE collection, empty tokens against a queryable field instead returns 7294900 "Compact tokens object is missing Compact token for the encrypted path 'ssn'" — that's the
genuinely-encrypted analog and the path with real signal.
Suggested additions, gated with @pytest.mark.requires(queryable_encryption=True) (the capability already exists in preconditions.py) so they run on mongo-replset and deselect on standalone:
- Success: QE collection + valid bindata token → assert ok: 1.0 and the stats.esc/stats.ecoc structure.
- Missing-token (7294900): QE collection with a queryable field + empty compactionTokens.
Notes for whoever picks this up:
- Server-side create with encryptedFields (keyId as UUID Binary subtype 4) is enough — full client-side auto-encryption (pymongo[encryption]) is not needed for the command path.
- These must be replica-set gated; QE collection creation itself fails on standalone (6346402).
- I don't see a QE TargetCollection fixture yet — that small enabling piece is the prerequisite. If adding it is out of scope here, a tracked follow-up referencing this comment is fine so the gap is intentional
rather than invisible.
Everything else looks good to me.
#416
Test cases: 36
Docs: https://www.mongodb.com/docs/v8.2/reference/command/compactStructuredEncryptionData/
Summary
Adds comprehensive tests for
compactStructuredEncryptionDataadministration command using proper DRY parametrization patterns.Changes
NOT_ENCRYPTED_COLLECTION_ERROR = 6346807constantbson_type_validatorfor exhaustive compactionTokens type rejection (16 BSON types), plus §19 namespace validation and missing field testsCommandTestCasetests for non-encrypted collection rejectionassertFailureCodeinstead of checking error message contentWhat was tested
All 36 tests pass against MongoDB: