diff options
author | Ian Boros <puppyofkosh@gmail.com> | 2019-02-21 16:23:42 -0500 |
---|---|---|
committer | Ian Boros <puppyofkosh@gmail.com> | 2019-02-26 12:47:35 -0500 |
commit | bedd8a55dcbcc619aee6c9245c3b527c42d486f0 (patch) | |
tree | 07cd44e6e93760321aaa48ced47d413d815c2493 /jstests | |
parent | 2fabf81388ce6175af7cd27145ff8cabba2950df (diff) | |
download | mongo-bedd8a55dcbcc619aee6c9245c3b527c42d486f0.tar.gz |
SERVER-39612 better validation for fields in geoNear
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/aggregation/sources/geonear/geonear_validation.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/geonear/geonear_validation.js b/jstests/aggregation/sources/geonear/geonear_validation.js new file mode 100644 index 00000000000..d567102762e --- /dev/null +++ b/jstests/aggregation/sources/geonear/geonear_validation.js @@ -0,0 +1,60 @@ +// Test for the bug found in SERVER-39612, where the server could behave poorly on invalid input +// from a $geoNear. +(function() { + const coll = db.geonear_validation; + + coll.drop(); + coll.insert({}); + coll.createIndex({"a.b.c": "2dsphere"}); + + function runGeoNearWithKey(key) { + return coll.aggregate([{ + $geoNear: { + key: key, + spherical: true, + distanceField: 'distance', + near: {type: 'Point', coordinates: [0, 0]} + } + }]); + } + + function runGeoNearCmdWithKey(key) { + const geoCmd = { + geoNear: coll.getName(), + near: {type: 'Point', coordinates: [0, 0]}, + spherical: true, + key: key + }; + return db.runCommand(geoCmd); + } + + // Try a valid value for 'key'. + (function() { + const key = "a.b.c"; + const cursor = runGeoNearWithKey(key); + assert.eq(cursor.itcount(), 0); + + const cmdCursor = assert.commandWorked(runGeoNearCmdWithKey(key)); + assert.eq(cursor.itcount(), 0); + })(); + + (function() { + // 'key' cannot start with a "$" since it would be an invalid field name. + const key = "$hello"; + const code = 16410; + let err = assert.throws(() => runGeoNearWithKey(key)); + assert.eq(err.code, code); + + assert.commandFailedWithCode(runGeoNearCmdWithKey(key), code); + })(); + + (function() { + // 'key' cannot include null bytes since it would make it an invalid field name. + const key = "A\0B"; + const code = 16411; + const err = assert.throws(() => runGeoNearWithKey(key)); + assert.eq(err.code, code); + + assert.commandFailedWithCode(runGeoNearCmdWithKey(key), code); + })(); +})(); |