Revert "SERVER-65078 Report schema violations as errors when the validation level is 'error' in testing"

This reverts commit d63bf9dfa2.
This commit is contained in:
Yuhong Zhang 2022-11-17 19:06:30 +00:00 committed by Evergreen Agent
parent 3757b70869
commit bae80e3873
11 changed files with 25 additions and 49 deletions

View File

@ -34,7 +34,6 @@ load("jstests/libs/doc_validation_utils.js");
const dbName = 'bypass_document_validation';
const collName = 'bypass_document_validation';
const outputCollName = 'bypass_output_coll';
const myDb = db.getSiblingDB(dbName);
const coll = myDb[collName];
@ -65,6 +64,7 @@ function runBypassDocumentValidationTest(validator) {
}
// Test the aggregation command with a $out stage.
const outputCollName = 'bypass_output_coll';
const outputColl = myDb[outputCollName];
outputColl.drop();
assert.commandWorked(myDb.createCollection(outputCollName, {validator: validator}));
@ -199,8 +199,4 @@ runBypassDocumentValidationTest({a: {$exists: true}});
// Run the test again with an equivalent JSON Schema validator.
runBypassDocumentValidationTest({$jsonSchema: {required: ['a']}});
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(myDb.runCommand({collMod: collName, validationAction: "warn"}));
assert.commandWorked(myDb.runCommand({collMod: outputCollName, validationAction: "warn"}));
})();

View File

@ -15,48 +15,41 @@ const encryptedBinDataElement = BinData(6, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA");
const nonEncryptedBinDataElement = BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA");
// Only elements of type BinData with subtype '6' should match.
assertSchemaMatch(coll, {properties: {bin: {encrypt: {}}}}, {bin: encryptedBinDataElement}, true);
assertSchemaMatch(coll, {properties: {bin: {encrypt: {}}}}, {bin: {}}, false);
assertSchemaMatch(
coll, {properties: {bin: {encrypt: {}}}}, {bin: encryptedBinDataElement}, true, true);
assertSchemaMatch(coll, {properties: {bin: {encrypt: {}}}}, {bin: {}}, false, true);
assertSchemaMatch(
coll, {properties: {bin: {encrypt: {}}}}, {bin: nonEncryptedBinDataElement}, false, true);
coll, {properties: {bin: {encrypt: {}}}}, {bin: nonEncryptedBinDataElement}, false);
// Nested in object.
assertSchemaMatch(coll,
{properties: {obj: {type: 'object', properties: {a: {encrypt: {}}}}}},
{obj: {a: encryptedBinDataElement}},
true,
true);
assertSchemaMatch(coll,
{properties: {obj: {type: 'object', properties: {a: {encrypt: {}}}}}},
{obj: {a: {}}},
false,
true);
false);
assertSchemaMatch(coll,
{properties: {obj: {type: 'object', properties: {a: {encrypt: {}}}}}},
{obj: {a: nonEncryptedBinDataElement}},
false,
true);
false);
// Nested in array.
assertSchemaMatch(coll,
{properties: {arr: {type: 'array', items: {encrypt: {}}}}},
{arr: [encryptedBinDataElement, encryptedBinDataElement]},
true,
true);
assertSchemaMatch(
coll, {properties: {arr: {type: 'array', items: {encrypt: {}}}}}, {arr: [{}, {}]}, false, true);
coll, {properties: {arr: {type: 'array', items: {encrypt: {}}}}}, {arr: [{}, {}]}, false);
assertSchemaMatch(coll,
{properties: {arr: {type: 'array', items: {encrypt: {}}}}},
{arr: [encryptedBinDataElement, nonEncryptedBinDataElement]},
false,
true);
false);
// If array is not specified, should not traverse array of encrypted BinData's.
assertSchemaMatch(coll,
{properties: {bin: {encrypt: {}}}},
{bin: [encryptedBinDataElement, encryptedBinDataElement]},
false,
true);
false);
// Encrypt alongside type/bsontype should fail to parse.
assert.commandFailedWithCode(

View File

@ -151,10 +151,6 @@ assert.commandWorked(viewsDB.runCommand({
assert.commandWorked(
viewsDB.runCommand({aggregate: "largeView", pipeline: [{$sort: {x: -1}}], cursor: {}}),
"Expected aggregate to succeed since 'allowDiskUse' is true by default");
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(
viewsDB.runCommand({collMod: validatedCollName, validationAction: "warn"}));
})();
// Test explain modes on a view.

View File

@ -10,7 +10,7 @@
* Asserts that 'doc' matches 'schema' if and only if 'valid' is true. Drops 'coll' in the process,
* so do not pass a collection whose contents you wish to preserve.
*/
function assertSchemaMatch(coll, schema, doc, valid, removeValidator = false) {
function assertSchemaMatch(coll, schema, doc, valid) {
const errmsg = "Document " + tojson(doc) +
(valid ? " should have matched the schema " : " unexpectedly matched the schema ") +
tojson(schema);
@ -60,12 +60,4 @@ function assertSchemaMatch(coll, schema, doc, valid, removeValidator = false) {
ErrorCodes.DocumentValidationFailure,
errmsg + " during update document validation in strict mode");
}
if (removeValidator) {
// Remove the validator to avoid failing collection validation.
assert.commandWorked(coll.runCommand("collMod", {validator: {}}));
} else {
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(coll.runCommand("collMod", {validationAction: "warn"}));
}
}

View File

@ -29,7 +29,7 @@ const collName = "collectionWithMalformedValidator";
assert.commandWorked(
testDB.runCommand({collMod: collName, validator: {email: {$regex: invalidRegex}}}));
MongoRunner.stopMongod(conn, null, {skipValidation: true});
MongoRunner.stopMongod(conn);
})();
(function startUpWithMalformedValidator() {
@ -48,6 +48,6 @@ const collName = "collectionWithMalformedValidator";
assert.commandWorked(testDB.someOtherCollection.insert({a: 1}));
assert.eq(testDB.someOtherCollection.find().itcount(), 1);
MongoRunner.stopMongod(conn, null, {skipValidation: true});
MongoRunner.stopMongod(conn);
})();
})();

View File

@ -253,8 +253,5 @@ bulkOp.find({$expr: {$eq: ["$x", 2]}}).update({$set: {x: 10}});
bulkOp.find({$expr: {$lt: ["$x", 1]}}).remove();
checkCounters(() => assert.commandWorked(bulkOp.execute()), {"$eq": 1, "$lt": 1});
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(testColl.runCommand("collMod", {validationAction: "warn"}));
MongoRunner.stopMongod(mongod);
})();

View File

@ -4,6 +4,11 @@
(function() {
"use strict";
// TODO SERVER-65078: remove this block.
// Disable the testing proctor. When the testing proctor is enabled, 'validate' will only warn about
// non-compliant documents, even when the validation action is 'error'.
TestData.testingDiagnosticsEnabled = false;
const conn = MongoRunner.runMongod();
const dbName = "test";

View File

@ -18,15 +18,12 @@ var coll = primary.getDB('test').getCollection(name);
assert.commandWorked(coll.insert({_id: 0, x: 1}));
assert.commandWorked(coll.runCommand("collMod", {"validator": {a: {$exists: true}}}));
secondary = replSet.restart(secondary, {startClean: true, skipValidation: true});
secondary = replSet.restart(secondary, {startClean: true});
replSet.awaitReplication();
replSet.awaitSecondaryNodes();
assert.eq(1, secondary.getDB("test")[name].count());
assert.docEq({_id: 0, x: 1}, secondary.getDB("test")[name].findOne());
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(coll.runCommand("collMod", {validationAction: "warn"}));
replSet.stopSet();
})();

View File

@ -32,9 +32,9 @@ function printCollectionOptions(rollbackTest, time) {
let CommonOps = (node) => {
let testDb = node.getDB(dbName);
assert.commandWorked(testDb[coll1Name].insert({a: 1, b: 1}));
assert.commandWorked(testDb[coll2Name].insert({a: 1, b: 1}));
assert.commandWorked(testDb[coll3Name].insert({a: 1, b: 1}));
assert.commandWorked(testDb[coll4Name].insert({a: 1, b: 1}));
assert.commandWorked(testDb[coll2Name].insert({a: 2, b: 2}));
assert.commandWorked(testDb[coll3Name].insert({a: 3, b: 3}));
assert.commandWorked(testDb[coll4Name].insert({a: 4, b: 4}));
// Start with no validation action.
assert.commandWorked(testDb.runCommand({

View File

@ -63,8 +63,5 @@ assert.eq(125,
"Number of documents on the recipient shard after moveChunk is incorrect.");
assert.eq(175, testColl.find().itcount(), "Number of total documents is incorrect");
// Set the validationAction to "warn" to avoid failing collection validation.
assert.commandWorked(testColl.runCommand("collMod", {validationAction: "warn"}));
st.stop();
})();

View File

@ -133,7 +133,10 @@ void schemaValidationFailed(CollectionValidation::ValidateState* state,
state->setCollectionSchemaViolated();
if (Collection::SchemaValidationResult::kWarn == result) {
// TODO SERVER-65078: remove the testing proctor check.
// When testing is enabled, only warn about non-compliant documents to prevent test failures.
if (TestingProctor::instance().isEnabled() ||
Collection::SchemaValidationResult::kWarn == result) {
results->warnings.push_back(kSchemaValidationFailedReason);
} else if (Collection::SchemaValidationResult::kError == result) {
results->errors.push_back(kSchemaValidationFailedReason);