Skip to content

CDRIVER-4657 Prohibit extra fields when matching command subdocuments #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2023

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Jun 6, 2023

Summary

  • Prohibit extra fields when matching command subdocuments in the legacy specification test runner
  • Add missing call to visitor_fn when matching arrays
  • Copy fle2v2-CreateCollection from mongodb/specifications@e59a0ac

Background & Motivation

Prohibit extra fields when matching command subdocuments

Described in mongodb/specifications#1429. The expected behavior for matching command-started events in the legacy Client-Side Encryption test format is to only allow extra fields at the top level of the command document.

Example expectation:

{
    "command_started_event": {
        "command": {
            "create": "encryptedCollection",
            "encryptedFields": {
                "fields": [
                    {
                        "path": "firstName",
                        "bsonType": "string",
                        "keyId": {
                            "$binary": {
                                "subType": "04",
                                "base64": "AAAAAAAAAAAAAAAAAAAAAA=="
                            }
                        }
                    }
                ]
            }
        },
        "command_name": "create",
        "database_name": "default"
    }
}

Example matching actual event:

{
    "command_started_event": {
        "command": {
            "create": "encryptedCollection",
            "encryptedFields": {
                "fields": [
                    {
                        "path": "firstName",
                        "bsonType": "string",
                        "keyId": {
                            "$binary": {
                                "base64": "AAAAAAAAAAAAAAAAAAAAAA==",
                                "subType": "04"
                            }
                        }
                    }
                ]
            },
            "lsid": {
                "id": {
                    "$binary": {
                        "base64": "RA6ru6SwSfm8XRl6wxPEgQ==",
                        "subType": "04"
                    }
                }
            },
            "$clusterTime": {
                "clusterTime": {
                    "$timestamp": {
                        "t": 1686066552,
                        "i": 4
                    }
                },
                "signature": {
                    "hash": {
                        "$binary": {
                            "base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
                            "subType": "00"
                        }
                    },
                    "keyId": {
                        "$numberLong": "0"
                    }
                }
            },
            "$db": "default"
        },
        "command_name": "create",
        "database_name": "default",
        "operation_id": {
            "$numberLong": "136170890"
        }
    }
}

Extra fields in the actual event (e.g. lsid) are permitted at the top level of the command document. But extra fields are not permitted in nested documents (e.g. an extra field inside encryptedFields would be considered a mismatch)

The C driver permitted allowing extra fields at any level of the command document. This PR adds additional checks to apm_match_visitor to prohibit extra fields in command subdocuments.

@kevinAlbs kevinAlbs marked this pull request as ready for review June 8, 2023 16:44
@kevinAlbs kevinAlbs requested a review from eramongodb June 8, 2023 19:48
@kevinAlbs kevinAlbs merged commit 984022e into mongodb:master Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants