...
1description: addKeyAltName
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 keyMaterial: { $binary: { base64: ABKBldDEoDW323yejOnIRk6YQmlD9d3eQthd16scKL75nz2LjNL9fgPDZWrFFOlqlhMCFaSrNJfGrFUjYk5JFDO7soG5Syb50k1niJoKg4ilsj0L4mpimFUtTpOr2nzZOeQtvAksEXc7gsFgq8gV7t/U3lsaXPY7I0t42DfSE8EGlPdxRjFdHnxh+OR8h7U9b8Qs5K5UuhgyeyxaBZ1Hgw==, subType: "00" } }
36 creationDate: { $date: { $numberLong: "1641024000000" } }
37 updateDate: { $date: { $numberLong: "1641024000000" } }
38 status: 1
39 masterKey:
40 provider: local
41
42tests:
43 - description: add keyAltName to non-existent data key
44 operations:
45 - name: addKeyAltName
46 object: *clientEncryption0
47 arguments:
48 # First 3 letters of local_key_id replaced with 'A' (value: "#alkeylocalkey").
49 id: &non_existent_id { $binary: { base64: AAAjYWxrZXlsb2NhbGtleQ==, subType: "04" } }
50 keyAltName: new_key_alt_name
51 expectResult: { $$unsetOrMatches: null }
52 expectEvents:
53 - client: *client0
54 events:
55 - commandStartedEvent:
56 databaseName: *database0Name
57 command:
58 findAndModify: *collection0Name
59 query: { _id: *non_existent_id }
60 update: { $addToSet: { keyAltNames: new_key_alt_name } }
61 writeConcern: { w: majority }
62 outcome:
63 - collectionName: *collection0Name
64 databaseName: *database0Name
65 documents:
66 - *local_key_doc
67
68 - description: add new keyAltName to data key with no keyAltNames
69 operations:
70 - name: addKeyAltName
71 object: *clientEncryption0
72 arguments:
73 id: *local_key_id
74 keyAltName: local_key
75 expectResult: *local_key_doc
76 - name: find
77 object: *collection0
78 arguments:
79 filter: {}
80 projection: { _id: 0, keyAltNames: 1 }
81 expectResult:
82 - keyAltNames: [local_key]
83 expectEvents:
84 - client: *client0
85 events:
86 - commandStartedEvent:
87 databaseName: *database0Name
88 command:
89 findAndModify: *collection0Name
90 query: { _id: *local_key_id }
91 update: { $addToSet: { keyAltNames: local_key } }
92 writeConcern: { w: majority }
93 - commandStartedEvent: { commandName: find }
94
95 - description: add existing keyAltName to existing data key
96 operations:
97 - name: addKeyAltName
98 object: *clientEncryption0
99 arguments:
100 id: *local_key_id
101 keyAltName: local_key
102 expectResult: *local_key_doc
103 - name: addKeyAltName
104 # Attempting to add a duplicate keyAltName to the data key should not be an error.
105 object: *clientEncryption0
106 arguments:
107 id: *local_key_id
108 keyAltName: local_key
109 expectResult:
110 _id: *local_key_id
111 keyAltNames: [local_key]
112 keyMaterial: { $$type: binData }
113 creationDate: { $$type: date }
114 updateDate: { $$type: date }
115 status: 1
116 masterKey:
117 provider: local
118 - name: find
119 object: *collection0
120 arguments:
121 filter: {}
122 projection: { _id: 0, keyAltNames: 1 }
123 expectResult:
124 - keyAltNames: [local_key]
125 expectEvents:
126 - client: *client0
127 events:
128 - commandStartedEvent:
129 databaseName: *database0Name
130 command:
131 findAndModify: *collection0Name
132 query: { _id: *local_key_id }
133 update: { $addToSet: { keyAltNames: local_key } }
134 writeConcern: { w: majority }
135 - commandStartedEvent:
136 databaseName: *database0Name
137 command:
138 findAndModify: *collection0Name
139 query: { _id: *local_key_id }
140 update: { $addToSet: { keyAltNames: local_key } }
141 writeConcern: { w: majority }
142 - commandStartedEvent: { commandName: find }
143
144 - description: add new keyAltName to data key with keyAltNames
145 operations:
146 - name: addKeyAltName
147 object: *clientEncryption0
148 arguments:
149 id: *local_key_id
150 keyAltName: local_key
151 expectResult: *local_key_doc
152 - name: addKeyAltName
153 object: *clientEncryption0
154 arguments:
155 id: *local_key_id
156 keyAltName: another_name
157 expectResult:
158 _id: *local_key_id
159 keyAltNames: [local_key]
160 keyMaterial: { $$type: binData }
161 creationDate: { $$type: date }
162 updateDate: { $$type: date }
163 status: 1
164 masterKey:
165 provider: local
166 - name: aggregate
167 object: *collection0
168 arguments:
169 pipeline:
170 # Ensure keyAltNames are in deterministically sorted order.
171 - $project: { _id: 0, keyAltNames: $keyAltNames }
172 - $unwind: $keyAltNames
173 - $sort: { keyAltNames: 1 }
174 expectResult:
175 - keyAltNames: another_name
176 - keyAltNames: local_key
177 expectEvents:
178 - client: *client0
179 events:
180 - commandStartedEvent:
181 databaseName: *database0Name
182 command:
183 findAndModify: *collection0Name
184 query: { _id: *local_key_id }
185 update: { $addToSet: { keyAltNames: local_key } }
186 writeConcern: { w: majority }
187 - commandStartedEvent:
188 databaseName: *database0Name
189 command:
190 findAndModify: *collection0Name
191 query: { _id: *local_key_id }
192 update: { $addToSet: { keyAltNames: another_name } }
193 writeConcern: { w: majority }
194 - commandStartedEvent: { commandName: aggregate }
View as plain text