diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-09-11 16:04:42 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-09-12 15:03:02 -0400 |
commit | ce71ccd92747972654c92fe9438df9c633188f93 (patch) | |
tree | af365a5ef3bfc35c67a402c15ae46f6b57a64031 /jstests/noPassthrough/json_schema_ignore_unknown_keywords.js | |
parent | 54f04e18005939b0357e411e5a34528301f3c7ef (diff) | |
download | mongo-ce71ccd92747972654c92fe9438df9c633188f93.tar.gz |
SERVER-30723: Add a query knob that controls whether JSON Schema ignores or errors on unknown keywords
Diffstat (limited to 'jstests/noPassthrough/json_schema_ignore_unknown_keywords.js')
-rw-r--r-- | jstests/noPassthrough/json_schema_ignore_unknown_keywords.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/jstests/noPassthrough/json_schema_ignore_unknown_keywords.js b/jstests/noPassthrough/json_schema_ignore_unknown_keywords.js new file mode 100644 index 00000000000..f16a757c3f5 --- /dev/null +++ b/jstests/noPassthrough/json_schema_ignore_unknown_keywords.js @@ -0,0 +1,59 @@ +/** + * Test that setting the query knob 'internalQueryIgnoreUnknownJSONSchemaKeywords' correctly + * ignores unknown keywords within $jsonSchema. + */ +(function() { + "use strict"; + + load("jstests/libs/assert_schema_match.js"); + + const options = {setParameter: "internalQueryIgnoreUnknownJSONSchemaKeywords=1"}; + const conn = MongoRunner.runMongod(options); + assert.neq(null, conn, "mongod was unable to start up with options: " + tojson(options)); + + const testDB = conn.getDB("test"); + const coll = testDB.getCollection("jstests_json_schema_ignore_unsupported"); + + assertSchemaMatch(coll, {my_keyword: "ignored", minProperties: 2}, {_id: 0}, false); + assertSchemaMatch(coll, {my_keyword: "ignored", minProperties: 2}, {_id: 0, a: 1}, true); + assertSchemaMatch( + coll, {properties: {a: {my_keyword: "ignored", minProperties: 1}}}, {a: {b: 1}}, true); + + // Test that the same query knob does not change the behavior for unsupported keywords. + { + let res = + coll.runCommand({find: coll.getName(), query: {$jsonSchema: {default: {_id: 0}}}}); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = coll.runCommand({ + find: coll.getName(), + query: {$jsonSchema: {definitions: {numberField: {type: "number"}}}} + }); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = coll.runCommand({find: coll.getName(), query: {$jsonSchema: {format: "email"}}}); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = + coll.runCommand({find: coll.getName(), query: {$jsonSchema: {id: "someschema.json"}}}); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = coll.runCommand({ + find: coll.getName(), + query: {$jsonSchema: {properties: {a: {$ref: "#/definitions/positiveInt"}}}} + }); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = coll.runCommand( + {find: coll.getName(), query: {$jsonSchema: {$schema: "hyper-schema"}}}); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + + res = coll.runCommand({ + find: coll.getName(), + query: {$jsonSchema: {$schema: "http://json-schema.org/draft-04/schema#"}} + }); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); + } + + MongoRunner.stopMongod(conn); +}()); |