@@ -6,6 +6,7 @@ import type { Compass } from '../helpers/compass';
66import { MONGODB_VERSION } from '../helpers/compass' ;
77import * as Selectors from '../helpers/selectors' ;
88import { createDummyCollections } from '../helpers/insert-data' ;
9+ import { getFirstListDocument } from '../helpers/read-first-document-content' ;
910
1011describe ( 'FLE2' , function ( ) {
1112 let initialEnvVars : NodeJS . ProcessEnv ;
@@ -96,15 +97,17 @@ describe('FLE2', function () {
9697 } ) ;
9798
9899 describe ( 'when fleEncryptedFieldsMap is specified while connecting' , function ( ) {
99- const databaseName = 'test' ;
100+ const databaseName = 'fle- test' ;
100101 const collectionName = 'my-another-collection' ;
101102 let compass : Compass ;
102103 let browser : CompassBrowser ;
103104
104105 before ( async function ( ) {
105106 compass = await beforeTests ( ) ;
106107 browser = compass . browser ;
108+ } ) ;
107109
110+ beforeEach ( async function ( ) {
108111 await browser . connectWithConnectionForm ( {
109112 hosts : [ 'localhost:27091' ] ,
110113 fleKeyVaultNamespace : `${ databaseName } .keyvault` ,
@@ -114,13 +117,26 @@ describe('FLE2', function () {
114117 fields: [
115118 {
116119 path: 'phoneNumber',
117- keyId: UUID("fd6275d7-9260-4e6c-a86b-68ec5240814a"),
118- bsonType: 'string'
120+ keyId: UUID("28bbc608-524e-4717-9246-33633361788e"),
121+ bsonType: 'string',
122+ queries: { queryType: 'equality' }
119123 }
120124 ]
121125 }
122126 }` ,
123127 } ) ;
128+ await browser . shellEval ( `use ${ databaseName } ` ) ;
129+ await browser . shellEval (
130+ 'db.keyvault.insertOne({' +
131+ '"_id": UUID("28bbc608-524e-4717-9246-33633361788e"),' +
132+ '"keyMaterial": BinData(0, "/yeYyj8IxowIIZGOs5iUcJaUm7KHhoBDAAzNxBz8c5mr2hwBIsBWtDiMU4nhx3fCBrrN3cqXG6jwPgR22gZDIiMZB5+xhplcE9EgNoEEBtRufBE2VjtacpXoqrMgW0+m4Dw76qWUCsF/k1KxYBJabM35KkEoD6+BI1QxU0rwRsR1rE/OLuBPKOEq6pmT5x74i+ursFlTld+5WiOySRDcZg=="),' +
133+ '"creationDate": ISODate("2022-05-27T18:28:33.925Z"),' +
134+ '"updateDate": ISODate("2022-05-27T18:28:33.925Z"),' +
135+ '"status": 0,' +
136+ '"masterKey": { "provider" : "local" }' +
137+ '})'
138+ ) ;
139+ await browser . clickVisible ( Selectors . SidebarInstanceRefreshButton ) ;
124140 } ) ;
125141
126142 after ( async function ( ) {
@@ -129,13 +145,27 @@ describe('FLE2', function () {
129145 }
130146 } ) ;
131147
148+ afterEach ( async function ( ) {
149+ await browser . shellEval (
150+ `db.getMongo().getDB('${ databaseName } ').dropDatabase()`
151+ ) ;
152+ } ) ;
153+
132154 it ( 'can create a fle2 collection without encryptedFields' , async function ( ) {
133155 await browser . navigateToDatabaseTab ( databaseName , 'Collections' ) ;
134-
135- // open the create collection modal from the button at the top
136156 await browser . clickVisible ( Selectors . DatabaseCreateCollectionButton ) ;
137157 await browser . addCollection ( collectionName ) ;
138158
159+ const selector = Selectors . collectionCard ( databaseName , collectionName ) ;
160+ await browser . scrollToVirtualItem (
161+ Selectors . CollectionsGrid ,
162+ selector ,
163+ 'grid'
164+ ) ;
165+
166+ const collectionCard = await browser . $ ( selector ) ;
167+ await collectionCard . waitForDisplayed ( ) ;
168+
139169 const collectionListFLE2BadgeElement = await browser . $ (
140170 Selectors . CollectionListFLE2Badge
141171 ) ;
@@ -160,5 +190,131 @@ describe('FLE2', function () {
160190 'QUERYABLE ENCRYPTION'
161191 ) ;
162192 } ) ;
193+
194+ it ( 'can insert a document with an encrypted field and a non-encrypted field' , async function ( ) {
195+ await browser . shellEval ( `db.createCollection('${ collectionName } ')` ) ;
196+
197+ await browser . clickVisible ( Selectors . SidebarInstanceRefreshButton ) ;
198+
199+ await browser . navigateToCollectionTab (
200+ databaseName ,
201+ collectionName ,
202+ 'Documents'
203+ ) ;
204+
205+ // browse to the "Insert to Collection" modal
206+ await browser . clickVisible ( Selectors . AddDataButton ) ;
207+ const insertDocumentOption = await browser . $ (
208+ Selectors . InsertDocumentOption
209+ ) ;
210+ await insertDocumentOption . waitForDisplayed ( ) ;
211+ await browser . clickVisible ( Selectors . InsertDocumentOption ) ;
212+
213+ // wait for the modal to appear
214+ const insertDialog = await browser . $ ( Selectors . InsertDialog ) ;
215+ await insertDialog . waitForDisplayed ( ) ;
216+
217+ // set the text in the editor
218+ await browser . setAceValue (
219+ Selectors . InsertJSONEditor ,
220+ '{ "phoneNumber": "30303030", "name": "Person X" }'
221+ ) ;
222+
223+ const insertCSFLEHasKnownSchemaMsg = await browser . $ (
224+ Selectors . insertCSFLEHasKnownSchemaMsg
225+ ) ;
226+ const insertCSFLEHasKnownSchemaMsgText =
227+ await insertCSFLEHasKnownSchemaMsg . getText ( ) ;
228+ expect ( insertCSFLEHasKnownSchemaMsgText ) . to . include ( 'phoneNumber' ) ;
229+
230+ // confirm
231+ const insertConfirm = await browser . $ ( Selectors . InsertConfirm ) ;
232+ await insertConfirm . waitForEnabled ( ) ;
233+ await browser . clickVisible ( Selectors . InsertConfirm ) ;
234+
235+ // wait for the modal to go away
236+ await insertDialog . waitForDisplayed ( { reverse : true } ) ;
237+ await browser . clickVisible ( Selectors . SidebarInstanceRefreshButton ) ;
238+
239+ const result = await getFirstListDocument ( browser ) ;
240+
241+ expect ( result . _id ) . to . exist ;
242+ expect ( result . __safeContent__ ) . to . exist ;
243+ delete result . _id ;
244+ delete result . __safeContent__ ;
245+
246+ expect ( result ) . to . deep . equal ( {
247+ phoneNumber : '"30303030"' ,
248+ name : '"Person X"' ,
249+ } ) ;
250+ } ) ;
251+
252+ it ( 'shows decrypted field icon' , async function ( ) {
253+ await browser . shellEval ( `db.createCollection('${ collectionName } ')` ) ;
254+ await browser . shellEval (
255+ `db['${ collectionName } '].insertOne({ "phoneNumber": "30303030", "name": "Person X" })`
256+ ) ;
257+
258+ await browser . navigateToCollectionTab (
259+ databaseName ,
260+ collectionName ,
261+ 'Documents'
262+ ) ;
263+
264+ const decryptedIconElements = await browser . $$ (
265+ Selectors . documentListDecryptedIcon ( 1 )
266+ ) ;
267+ const decryptedIcons = await Promise . all (
268+ decryptedIconElements . map ( ( el ) => el . getAttribute ( 'title' ) )
269+ ) ;
270+
271+ expect ( decryptedIcons ) . to . have . lengthOf ( 1 ) ;
272+ expect ( decryptedIcons [ 0 ] ) . to . be . equal ( 'Encrypted Field' ) ;
273+ } ) ;
274+
275+ it ( 'can edit and query the encrypted field' , async function ( ) {
276+ await browser . shellEval ( `db.createCollection('${ collectionName } ')` ) ;
277+ await browser . shellEval (
278+ `db['${ collectionName } '].insertOne({ "phoneNumber": "30303030", "name": "Person X" })`
279+ ) ;
280+
281+ await browser . navigateToCollectionTab (
282+ databaseName ,
283+ collectionName ,
284+ 'Documents'
285+ ) ;
286+
287+ const result = await getFirstListDocument ( browser ) ;
288+ expect ( result . phoneNumber ) . to . be . equal ( '"30303030"' ) ;
289+
290+ const document = await browser . $ ( Selectors . DocumentListEntry ) ;
291+ const value = await document . $ (
292+ `${ Selectors . HadronDocumentElement } :nth-child(2) ${ Selectors . HadronDocumentClickableValue } `
293+ ) ;
294+ await value . doubleClick ( ) ;
295+
296+ const input = await document . $ (
297+ `${ Selectors . HadronDocumentElement } :nth-child(2) ${ Selectors . HadronDocumentValueEditor } `
298+ ) ;
299+ await input . setValue ( '10101010' ) ;
300+
301+ const footer = await document . $ ( Selectors . DocumentFooterMessage ) ;
302+ expect ( await footer . getText ( ) ) . to . equal ( 'Document Modified.' ) ;
303+
304+ const button = await document . $ (
305+ '[data-test-id="update-document-button"]'
306+ ) ;
307+ await button . click ( ) ;
308+ await footer . waitForDisplayed ( { reverse : true } ) ;
309+
310+ await browser . runFindOperation (
311+ 'Documents' ,
312+ "{ phoneNumber: '10101010' }"
313+ ) ;
314+
315+ const modifiedResult = await getFirstListDocument ( browser ) ;
316+ expect ( modifiedResult . phoneNumber ) . to . be . equal ( '"10101010"' ) ;
317+ expect ( modifiedResult . _id ) . to . be . equal ( result . _id ) ;
318+ } ) ;
163319 } ) ;
164320} ) ;
0 commit comments