jstests/fle2/implicit_schema_validation.js
// If 'hasUserValidator' is true, this assumes it validates the optional field 'name' is a string.
If 'hasUserValidator' is true, this assumes it validates the optional field 'name' is a string.
If ' hasUserValidator ' is true this assumes it validates the optional field ' name ' is a string .
function positiveTests(coll, hasUserValidator, invert = false) {
    function assertExpectedResult(result) {
        if (invert) {
            assert.commandFailedWithCode(result, ErrorCodes.DocumentValidationFailure);
        } else {
            assert.commandWorked(result);
        }
    }
    jsTestLog("test inserting document without any encrypted fields");
    assert.commandWorked(coll.insert({}));
    assert.commandWorked(coll.insert({foo: 1}));
    assert.commandWorked(coll.insert({a: {foo: 1}}));
    assert.commandWorked(coll.insert({a: {b: {foo: 1}, x: {foo: 1}}}));
    jsTestLog("test inserting single encrypted field with valid type");
    assertExpectedResult(coll.insert({firstName: validEncryptedString}));
    jsTestLog("test inserting multiple encrypted fields with valid type");
    assertExpectedResult(coll.insert({
        firstName: validEncryptedString,
        a: {
            b: {
                c: validEncryptedInt,
                d: validEncryptedInt,
            },
            x: {
                y: validEncryptedString,
            }
        }
    }));
    jsTestLog("test inserting non-object along encrypted path");
    assertExpectedResult(coll.insert({
        firstName: validEncryptedString,
        a: "foo",
    }));
    assertExpectedResult(coll.insert({
        firstName: validEncryptedString,
        a: {
            b: {
                c: validEncryptedInt,
                d: validEncryptedInt,
            },
            x: "foo",
        }
    }));
    jsTestLog("test insert satisfies user-provided validator");
    assertExpectedResult(coll.insert({name: "joe", firstName: validEncryptedString}));
}
function positiveTests ( coll , hasUserValidator , invert = false ) { function assertExpectedResult ( result ) { if ( invert ) { assert . commandFailedWithCode ( result , ErrorCodes . DocumentValidationFailure ) ; } else { assert . commandWorked ( result ) ; } } jsTestLog ( "test inserting document without any encrypted fields" ) ; assert . commandWorked ( coll . insert ( { } ) ) ; assert . commandWorked ( coll . insert ( { foo : 1 } ) ) ; assert . commandWorked ( coll . insert ( { a : { foo : 1 } } ) ) ; assert . commandWorked ( coll . insert ( { a : { b : { foo : 1 } , x : { foo : 1 } } } ) ) ; jsTestLog ( "test inserting single encrypted field with valid type" ) ; assertExpectedResult ( coll . insert ( { firstName : validEncryptedString } ) ) ; jsTestLog ( "test inserting multiple encrypted fields with valid type" ) ; assertExpectedResult ( coll . insert ( { firstName : validEncryptedString , a : { b : { c : validEncryptedInt , d : validEncryptedInt , } , x : { y : validEncryptedString , } } } ) ) ; jsTestLog ( "test inserting non-object along encrypted path" ) ; assertExpectedResult ( coll . insert ( { firstName : validEncryptedString , a : "foo" , } ) ) ; assertExpectedResult ( coll . insert ( { firstName : validEncryptedString , a : { b : { c : validEncryptedInt , d : validEncryptedInt , } , x : "foo" , } } ) ) ; jsTestLog ( "test insert satisfies user-provided validator" ) ; assertExpectedResult ( coll . insert ( { name : "joe" , firstName : validEncryptedString } ) ) ; }
If 'hasUserValidator' is true, this assumes it validates the optional field 'name' is a string.
If ' hasUserValidator ' is true this assumes it validates the optional field ' name ' is a string .