jstests/fle2/libs/encrypted_client_util.js
/**
     * Get a single document from the collection with the specified query. Ensure it contains the
     specified fields when decrypted and that does fields are encrypted.

     * @param {string} coll
     * @param {object} query
     * @param {object} fields
     */
Get a single document from the collection with the specified query. Ensure it contains the
specified fields when decrypted and that does fields are encrypted.


Get a single document from the collection with the specified query . Ensure it contains the specified fields when decrypted and that does fields are encrypted .
assertOneEncryptedDocumentFields(coll, query, fields) {
        let encryptedDocs = this._db.getCollection(coll).find(query).toArray();
        assert.eq(encryptedDocs.length,
                  1,
                  `Expected query ${tojson(query)} to only return one document. Found ${
                      encryptedDocs.length}`);
        let unEncryptedDocs = this._edb.getCollection(coll).find(query).toArray();
        assert.eq(unEncryptedDocs.length, 1);
        let encryptedDoc = encryptedDocs[0];
        let unEncryptedDoc = unEncryptedDocs[0];
        assert(encryptedDoc[kSafeContentField] !== undefined);
        for (let field in fields) {
            assert(encryptedDoc.hasOwnProperty(field),
                   `Could not find ${field} in encrypted ${tojson(encryptedDoc)}`);
            assert(unEncryptedDoc.hasOwnProperty(field),
                   `Could not find ${field} in unEncrypted ${tojson(unEncryptedDoc)}`);
            let rawField = encryptedDoc[field];
            assertIsIndexedEncryptedField(rawField);
            let unEncryptedField = unEncryptedDoc[field];
            assert.eq(unEncryptedField, fields[field]);
        }
    }
assertOneEncryptedDocumentFields ( coll , query , fields ) { let encryptedDocs = this . _db . getCollection ( coll ) . find ( query ) . toArray ( ) ; assert . eq ( encryptedDocs . length , 1 , ` ${ tojson ( query ) } ${ encryptedDocs . length } ` ) ; let unEncryptedDocs = this . _edb . getCollection ( coll ) . find ( query ) . toArray ( ) ; assert . eq ( unEncryptedDocs . length , 1 ) ; let encryptedDoc = encryptedDocs [ 0 ] ; let unEncryptedDoc = unEncryptedDocs [ 0 ] ; assert ( encryptedDoc [ kSafeContentField ] !== undefined ) ; for ( let field in fields ) { assert ( encryptedDoc . hasOwnProperty ( field ) , ` ${ field } ${ tojson ( encryptedDoc ) } ` ) ; assert ( unEncryptedDoc . hasOwnProperty ( field ) , ` ${ field } ${ tojson ( unEncryptedDoc ) } ` ) ; let rawField = encryptedDoc [ field ] ; assertIsIndexedEncryptedField ( rawField ) ; let unEncryptedField = unEncryptedDoc [ field ] ; assert . eq ( unEncryptedField , fields [ field ] ) ; } }
Get a single document from the collection with the specified query.
Get a single document from the collection with the specified query .