2013-02-28 17:13:23 -08:00
|
|
|
// Tests to see what validity checks are done for 10gen specific object construction
|
|
|
|
|
|
2013-07-09 19:35:30 -04:00
|
|
|
// Takes a list of constructors and returns a new list with an extra entry for each constructor with
|
|
|
|
|
// "new" prepended
|
|
|
|
|
function addConstructorsWithNew (constructorList) {
|
|
|
|
|
function prependNew (constructor) {
|
|
|
|
|
return "new " + constructor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var valid = constructorList.valid;
|
|
|
|
|
var invalid = constructorList.invalid;
|
|
|
|
|
// We use slice(0) here to make a copy of our lists
|
|
|
|
|
var validWithNew = valid.concat(valid.slice(0).map(prependNew));
|
|
|
|
|
var invalidWithNew = invalid.concat(invalid.slice(0).map(prependNew));
|
|
|
|
|
return { "valid" : validWithNew, "invalid" : invalidWithNew };
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 17:13:23 -08:00
|
|
|
function clientEvalConstructorTest (constructorList) {
|
2013-07-09 19:35:30 -04:00
|
|
|
constructorList = addConstructorsWithNew(constructorList);
|
2013-02-28 17:13:23 -08:00
|
|
|
constructorList.valid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
try {
|
|
|
|
|
eval(constructor);
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
throw ("valid constructor: " + constructor + " failed in eval context: " + e);
|
|
|
|
|
}
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
constructorList.invalid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
assert.throws(function () { eval(constructor) },
|
|
|
|
|
[], "invalid constructor did not throw error in eval context: " + constructor);
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dbEvalConstructorTest (constructorList) {
|
2013-07-09 19:35:30 -04:00
|
|
|
constructorList = addConstructorsWithNew(constructorList);
|
2013-02-28 17:13:23 -08:00
|
|
|
constructorList.valid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
try {
|
|
|
|
|
db.eval(constructor);
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
throw ("valid constructor: " + constructor + " failed in db.eval context: " + e);
|
|
|
|
|
}
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
constructorList.invalid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
assert.throws(function () { db.eval(constructor) },
|
|
|
|
|
[], "invalid constructor did not throw error in db.eval context: " + constructor);
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mapReduceConstructorTest (constructorList) {
|
2013-07-09 19:35:30 -04:00
|
|
|
constructorList = addConstructorsWithNew(constructorList);
|
2013-02-28 17:13:23 -08:00
|
|
|
t = db.mr_constructors;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
|
|
|
|
t.save( { "partner" : 1, "visits" : 9 } )
|
|
|
|
|
t.save( { "partner" : 2, "visits" : 9 } )
|
|
|
|
|
t.save( { "partner" : 1, "visits" : 11 } )
|
|
|
|
|
t.save( { "partner" : 1, "visits" : 30 } )
|
|
|
|
|
t.save( { "partner" : 2, "visits" : 41 } )
|
|
|
|
|
t.save( { "partner" : 2, "visits" : 41 } )
|
|
|
|
|
|
|
|
|
|
constructorList.valid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
try {
|
|
|
|
|
m = eval("dummy = function(){ emit( \"test\" , " + constructor + " ) }");
|
2013-02-28 17:13:23 -08:00
|
|
|
|
2013-03-12 16:05:07 -07:00
|
|
|
r = eval("dummy = function( k , v ){ return { test : " + constructor + " } }");
|
2013-02-28 17:13:23 -08:00
|
|
|
|
2013-03-12 16:05:07 -07:00
|
|
|
res = t.mapReduce( m , r , { out : "mr_constructors_out" , scope : { xx : 1 } } );
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
throw ("valid constructor: " + constructor + " failed in mapReduce context: " + e);
|
|
|
|
|
}
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
constructorList.invalid.forEach(function (constructor) {
|
|
|
|
|
m = eval("dummy = function(){ emit( \"test\" , " + constructor + " ) }");
|
|
|
|
|
|
|
|
|
|
r = eval("dummy = function( k , v ){ return { test : " + constructor + " } }");
|
|
|
|
|
|
|
|
|
|
assert.throws(function () { res = t.mapReduce( m , r ,
|
2013-03-12 16:05:07 -07:00
|
|
|
{ out : "mr_constructors_out" , scope : { xx : 1 } } ) },
|
|
|
|
|
[], "invalid constructor did not throw error in mapReduce context: " + constructor);
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
db.mr_constructors_out.drop();
|
|
|
|
|
t.drop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function whereConstructorTest (constructorList) {
|
2013-07-09 19:35:30 -04:00
|
|
|
constructorList = addConstructorsWithNew(constructorList);
|
2013-02-28 17:13:23 -08:00
|
|
|
t = db.where_constructors;
|
|
|
|
|
t.drop();
|
2014-01-14 14:09:42 -05:00
|
|
|
assert.writeOK( t.insert({ x : 1 }));
|
2013-02-28 17:13:23 -08:00
|
|
|
|
|
|
|
|
constructorList.valid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
try {
|
|
|
|
|
t.findOne({ $where : constructor });
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
throw ("valid constructor: " + constructor + " failed in $where query: " + e);
|
|
|
|
|
}
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
constructorList.invalid.forEach(function (constructor) {
|
2013-03-12 16:05:07 -07:00
|
|
|
assert.throws(function () { t.findOne({ $where : constructor }) },
|
|
|
|
|
[], "invalid constructor did not throw error in $where query: " + constructor);
|
2013-02-28 17:13:23 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dbrefConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
"DBRef(\"namespace\", 0)",
|
|
|
|
|
"DBRef(\"namespace\", \"test\")",
|
2014-02-18 10:01:14 -05:00
|
|
|
"DBRef(\"namespace\", \"test\", \"database\")",
|
2013-02-28 17:13:23 -08:00
|
|
|
"DBRef(\"namespace\", ObjectId())",
|
|
|
|
|
"DBRef(\"namespace\", ObjectId(\"000000000000000000000000\"))",
|
2014-02-18 10:01:14 -05:00
|
|
|
"DBRef(\"namespace\", ObjectId(\"000000000000000000000000\"), \"database\")",
|
2013-02-28 17:13:23 -08:00
|
|
|
],
|
|
|
|
|
"invalid" : [
|
2013-06-05 18:23:46 -04:00
|
|
|
"DBRef()",
|
|
|
|
|
"DBRef(true, ObjectId())",
|
2014-02-18 10:01:14 -05:00
|
|
|
"DBRef(true, ObjectId(), true)",
|
2013-02-28 17:13:23 -08:00
|
|
|
"DBRef(\"namespace\")",
|
2013-07-08 18:02:54 -04:00
|
|
|
"DBRef(\"namespace\", ObjectId(), true)",
|
2014-02-18 10:01:14 -05:00
|
|
|
"DBRef(\"namespace\", ObjectId(), 123)",
|
2013-02-28 17:13:23 -08:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dbpointerConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
"DBPointer(\"namespace\", ObjectId())",
|
|
|
|
|
"DBPointer(\"namespace\", ObjectId(\"000000000000000000000000\"))",
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
"DBPointer()",
|
2013-06-05 18:23:46 -04:00
|
|
|
"DBPointer(true, ObjectId())",
|
|
|
|
|
"DBPointer(\"namespace\", 0)",
|
|
|
|
|
"DBPointer(\"namespace\", \"test\")",
|
2013-02-28 17:13:23 -08:00
|
|
|
"DBPointer(\"namespace\")",
|
2013-07-08 18:02:54 -04:00
|
|
|
"DBPointer(\"namespace\", ObjectId(), true)",
|
2013-02-28 17:13:23 -08:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var objectidConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'ObjectId()',
|
|
|
|
|
'ObjectId("FFFFFFFFFFFFFFFFFFFFFFFF")',
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'ObjectId(5)',
|
|
|
|
|
'ObjectId("FFFFFFFFFFFFFFFFFFFFFFFQ")',
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var timestampConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'Timestamp()',
|
|
|
|
|
'Timestamp(0,0)',
|
2013-03-12 16:31:42 -07:00
|
|
|
'Timestamp(1.0,1.0)',
|
2013-02-28 17:13:23 -08:00
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'Timestamp(0)',
|
|
|
|
|
'Timestamp(0,0,0)',
|
2013-03-12 16:31:42 -07:00
|
|
|
'Timestamp("test","test")',
|
|
|
|
|
'Timestamp("test",0)',
|
|
|
|
|
'Timestamp(0,"test")',
|
|
|
|
|
'Timestamp(true,true)',
|
|
|
|
|
'Timestamp(true,0)',
|
|
|
|
|
'Timestamp(0,true)',
|
2013-02-28 17:13:23 -08:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bindataConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'BinData(0,"test")',
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'BinData(0,"test", "test")',
|
2013-07-08 18:02:54 -04:00
|
|
|
'BinData()',
|
|
|
|
|
'BinData(-1, "")',
|
|
|
|
|
'BinData(256, "")',
|
|
|
|
|
'BinData("string","aaaa")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'BinData(0, true)',
|
|
|
|
|
'BinData(0, null)',
|
|
|
|
|
'BinData(0, undefined)',
|
|
|
|
|
'BinData(0, {})',
|
|
|
|
|
'BinData(0, [])',
|
|
|
|
|
'BinData(0, function () {})',
|
2013-07-08 18:02:54 -04:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var uuidConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'UUID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")',
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'UUID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0)',
|
|
|
|
|
'UUID()',
|
|
|
|
|
'UUID("aa")',
|
|
|
|
|
'UUID("invalidhex")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'UUID("invalidhexbutstilltherequiredlen")',
|
2013-07-08 18:02:54 -04:00
|
|
|
'UUID(true)',
|
|
|
|
|
'UUID(null)',
|
|
|
|
|
'UUID(undefined)',
|
|
|
|
|
'UUID({})',
|
|
|
|
|
'UUID([])',
|
|
|
|
|
'UUID(function () {})',
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var md5Constructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'MD5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")',
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'MD5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0)',
|
|
|
|
|
'MD5()',
|
|
|
|
|
'MD5("aa")',
|
|
|
|
|
'MD5("invalidhex")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'MD5("invalidhexbutstilltherequiredlen")',
|
2013-07-08 18:02:54 -04:00
|
|
|
'MD5(true)',
|
|
|
|
|
'MD5(null)',
|
|
|
|
|
'MD5(undefined)',
|
|
|
|
|
'MD5({})',
|
|
|
|
|
'MD5([])',
|
|
|
|
|
'MD5(function () {})',
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hexdataConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'HexData(0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")',
|
|
|
|
|
'HexData(0, "")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'HexData(0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")',
|
2013-07-08 18:02:54 -04:00
|
|
|
'HexData(0, "000000000000000000000005")', // SERVER-9605
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
'HexData(0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0)',
|
|
|
|
|
'HexData()',
|
|
|
|
|
'HexData(0)',
|
2015-07-25 15:05:49 -04:00
|
|
|
'HexData(0, 100)',
|
2013-07-08 18:02:54 -04:00
|
|
|
'HexData(-1, "")',
|
|
|
|
|
'HexData(256, "")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'HexData(0, "aaa")',
|
2013-07-08 18:02:54 -04:00
|
|
|
'HexData("string","aaaa")',
|
2015-07-25 15:05:49 -04:00
|
|
|
'HexData(0, true)',
|
|
|
|
|
'HexData(0, null)',
|
|
|
|
|
'HexData(0, undefined)',
|
|
|
|
|
'HexData(0, {})',
|
|
|
|
|
'HexData(0, [])',
|
|
|
|
|
'HexData(0, function () {})',
|
|
|
|
|
'HexData(0, "invalidhex")',
|
2013-02-28 17:13:23 -08:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dateConstructors = {
|
|
|
|
|
"valid" : [
|
|
|
|
|
'Date()',
|
|
|
|
|
'Date(0)',
|
|
|
|
|
'Date(0,0)',
|
|
|
|
|
'Date(0,0,0)',
|
|
|
|
|
'Date("foo")',
|
|
|
|
|
],
|
|
|
|
|
"invalid" : [
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clientEvalConstructorTest(dbrefConstructors);
|
|
|
|
|
clientEvalConstructorTest(dbpointerConstructors);
|
|
|
|
|
clientEvalConstructorTest(objectidConstructors);
|
|
|
|
|
clientEvalConstructorTest(timestampConstructors);
|
|
|
|
|
clientEvalConstructorTest(bindataConstructors);
|
2013-07-08 18:02:54 -04:00
|
|
|
clientEvalConstructorTest(uuidConstructors);
|
|
|
|
|
clientEvalConstructorTest(md5Constructors);
|
|
|
|
|
clientEvalConstructorTest(hexdataConstructors);
|
2013-02-28 17:13:23 -08:00
|
|
|
clientEvalConstructorTest(dateConstructors);
|
|
|
|
|
|
|
|
|
|
dbEvalConstructorTest(dbrefConstructors);
|
|
|
|
|
dbEvalConstructorTest(dbpointerConstructors);
|
|
|
|
|
dbEvalConstructorTest(objectidConstructors);
|
|
|
|
|
dbEvalConstructorTest(timestampConstructors);
|
|
|
|
|
dbEvalConstructorTest(bindataConstructors);
|
2013-07-08 18:02:54 -04:00
|
|
|
dbEvalConstructorTest(uuidConstructors);
|
|
|
|
|
dbEvalConstructorTest(md5Constructors);
|
|
|
|
|
dbEvalConstructorTest(hexdataConstructors);
|
2013-02-28 17:13:23 -08:00
|
|
|
dbEvalConstructorTest(dateConstructors);
|
|
|
|
|
|
2015-11-13 12:32:15 -05:00
|
|
|
mapReduceConstructorTest(dbrefConstructors);
|
|
|
|
|
mapReduceConstructorTest(dbpointerConstructors);
|
|
|
|
|
mapReduceConstructorTest(objectidConstructors);
|
|
|
|
|
mapReduceConstructorTest(timestampConstructors);
|
|
|
|
|
mapReduceConstructorTest(bindataConstructors);
|
|
|
|
|
mapReduceConstructorTest(uuidConstructors);
|
|
|
|
|
mapReduceConstructorTest(md5Constructors);
|
|
|
|
|
mapReduceConstructorTest(hexdataConstructors);
|
2013-02-28 17:13:23 -08:00
|
|
|
mapReduceConstructorTest(dateConstructors);
|
|
|
|
|
|
2015-11-13 12:32:15 -05:00
|
|
|
whereConstructorTest(dbrefConstructors);
|
|
|
|
|
whereConstructorTest(dbpointerConstructors);
|
|
|
|
|
whereConstructorTest(objectidConstructors);
|
|
|
|
|
whereConstructorTest(timestampConstructors);
|
|
|
|
|
whereConstructorTest(bindataConstructors);
|
|
|
|
|
whereConstructorTest(uuidConstructors);
|
|
|
|
|
whereConstructorTest(md5Constructors);
|
|
|
|
|
whereConstructorTest(hexdataConstructors);
|
2013-02-28 17:13:23 -08:00
|
|
|
whereConstructorTest(dateConstructors);
|