...

Text file src/go.mongodb.org/mongo-driver/testdata/client-side-encryption/unified/removeKeyAltName.yml

Documentation: go.mongodb.org/mongo-driver/testdata/client-side-encryption/unified

     1description: removeKeyAltName
     2
     3schemaVersion: "1.8"
     4
     5runOnRequirements:
     6  - csfle: true
     7
     8createEntities:
     9  - client:
    10      id: &client0 client0
    11      observeEvents:
    12        - commandStartedEvent
    13  - clientEncryption:
    14      id: &clientEncryption0 clientEncryption0
    15      clientEncryptionOpts:
    16        keyVaultClient: *client0
    17        keyVaultNamespace: keyvault.datakeys
    18        kmsProviders:
    19          local: { key: { $$placeholder: 1 } }
    20  - database:
    21      id: &database0 database0
    22      client: *client0
    23      databaseName: &database0Name keyvault
    24  - collection:
    25      id: &collection0 collection0
    26      database: *database0
    27      collectionName: &collection0Name datakeys
    28
    29initialData:
    30  - databaseName: *database0Name
    31    collectionName: *collection0Name
    32    documents:
    33      - &local_key_doc
    34        _id: &local_key_id { $binary: { base64: bG9jYWxrZXlsb2NhbGtleQ==, subType: "04" } }
    35        keyAltNames: [alternate_name, local_key]
    36        keyMaterial: { $binary: { base64: ABKBldDEoDW323yejOnIRk6YQmlD9d3eQthd16scKL75nz2LjNL9fgPDZWrFFOlqlhMCFaSrNJfGrFUjYk5JFDO7soG5Syb50k1niJoKg4ilsj0L4mpimFUtTpOr2nzZOeQtvAksEXc7gsFgq8gV7t/U3lsaXPY7I0t42DfSE8EGlPdxRjFdHnxh+OR8h7U9b8Qs5K5UuhgyeyxaBZ1Hgw==, subType: "00" } }
    37        creationDate: { $date: { $numberLong: "1641024000000" } }
    38        updateDate: { $date: { $numberLong: "1641024000000" } }
    39        status: 1
    40        masterKey:
    41          provider: local
    42
    43tests:
    44  - description: remove keyAltName from non-existent data key
    45    operations:
    46      - name: removeKeyAltName
    47        object: *clientEncryption0
    48        arguments:
    49          # First 3 letters of local_key_id replaced with 'A' (value: "#alkeylocalkey").
    50          id: &non_existent_id { $binary: { base64: AAAjYWxrZXlsb2NhbGtleQ==, subType: "04" } }
    51          keyAltName: does_not_exist
    52        expectResult: { $$unsetOrMatches: null }
    53    expectEvents:
    54      - client: *client0
    55        events:
    56          - commandStartedEvent:
    57              databaseName: *database0Name
    58              command:
    59                findAndModify: *collection0Name
    60                query: { _id: *non_existent_id }
    61                update: [{ $set: { keyAltNames: { $cond: [{ $eq: [$keyAltNames, [does_not_exist]] }, $$REMOVE, { $filter: { input: $keyAltNames, cond: { $ne: [$$this, does_not_exist] } } }] } } }]
    62                writeConcern: { w: majority }
    63    outcome:
    64      - collectionName: *collection0Name
    65        databaseName: *database0Name
    66        documents:
    67          - *local_key_doc
    68
    69  - description: remove non-existent keyAltName from existing data key
    70    operations:
    71      - name: removeKeyAltName
    72        object: *clientEncryption0
    73        arguments:
    74          id: *local_key_id
    75          keyAltName: does_not_exist
    76        expectResult: *local_key_doc
    77    expectEvents:
    78      - client: *client0
    79        events:
    80          - commandStartedEvent:
    81              databaseName: *database0Name
    82              command:
    83                findAndModify: *collection0Name
    84                query: { _id: *local_key_id }
    85                update: [{ $set: { keyAltNames: { $cond: [{ $eq: [$keyAltNames, [does_not_exist]] }, $$REMOVE, { $filter: { input: $keyAltNames, cond: { $ne: [$$this, does_not_exist] } } }] } } }]
    86                writeConcern: { w: majority }
    87    outcome:
    88      - collectionName: *collection0Name
    89        databaseName: *database0Name
    90        documents:
    91          - *local_key_doc
    92
    93  - description: remove an existing keyAltName from an existing data key
    94    operations:
    95      - name: removeKeyAltName
    96        object: *clientEncryption0
    97        arguments:
    98          id: *local_key_id
    99          keyAltName: alternate_name
   100        expectResult: *local_key_doc
   101      - name: find
   102        object: *collection0
   103        arguments:
   104          filter: {}
   105          projection: { _id: 0, keyAltNames: 1 }
   106        expectResult:
   107          - keyAltNames: [local_key]
   108    expectEvents:
   109      - client: *client0
   110        events:
   111          - commandStartedEvent:
   112              databaseName: *database0Name
   113              command:
   114                findAndModify: *collection0Name
   115                query: { _id: *local_key_id }
   116                update: [{ $set: { keyAltNames: { $cond: [{ $eq: [$keyAltNames, [alternate_name]] }, $$REMOVE, { $filter: { input: $keyAltNames, cond: { $ne: [$$this, alternate_name] } } }] } } }]
   117                writeConcern: { w: majority }
   118          - commandStartedEvent: { commandName: find }
   119
   120  - description: remove the last keyAltName from an existing data key
   121    operations:
   122      - name: removeKeyAltName
   123        object: *clientEncryption0
   124        arguments:
   125          id: *local_key_id
   126          keyAltName: alternate_name
   127        expectResult: *local_key_doc
   128      - name: removeKeyAltName
   129        object: *clientEncryption0
   130        arguments:
   131          id: *local_key_id
   132          keyAltName: local_key
   133        expectResult:
   134          _id: *local_key_id
   135          keyAltNames: [local_key]
   136          keyMaterial: { $$type: binData }
   137          creationDate: { $$type: date }
   138          updateDate: { $$type: date }
   139          status: 1
   140          masterKey:
   141            provider: local
   142    expectEvents:
   143      - client: *client0
   144        events:
   145          - commandStartedEvent:
   146              databaseName: *database0Name
   147              command:
   148                findAndModify: *collection0Name
   149                query: { _id: *local_key_id }
   150                update: [{ $set: { keyAltNames: { $cond: [{ $eq: [$keyAltNames, [alternate_name]] }, $$REMOVE, { $filter: { input: $keyAltNames, cond: { $ne: [$$this, alternate_name] } } }] } } }]
   151                writeConcern: { w: majority }
   152          - commandStartedEvent:
   153              databaseName: *database0Name
   154              command:
   155                findAndModify: *collection0Name
   156                query: { _id: *local_key_id }
   157                update: [{ $set: { keyAltNames: { $cond: [{ $eq: [$keyAltNames, [local_key]] }, $$REMOVE, { $filter: { input: $keyAltNames, cond: { $ne: [$$this, local_key] } } }] } } }]

View as plain text